2016-01-23 12:24:49 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""This module contains a object that represents Tests for Botan analytics integration"""
|
|
|
|
|
|
|
|
import sys
|
2016-04-24 04:11:25 +02:00
|
|
|
import unittest
|
|
|
|
import os
|
2016-04-27 00:28:21 +02:00
|
|
|
|
2016-02-27 22:39:03 +01:00
|
|
|
from flaky import flaky
|
|
|
|
|
2016-01-23 12:24:49 +01:00
|
|
|
sys.path.append('.')
|
|
|
|
|
|
|
|
from telegram.utils.botan import Botan
|
|
|
|
from tests.base import BaseTest
|
|
|
|
|
2016-01-24 16:32:12 +01:00
|
|
|
|
2016-01-23 12:24:49 +01:00
|
|
|
class MessageMock(object):
|
|
|
|
chat_id = None
|
|
|
|
|
|
|
|
def __init__(self, chat_id):
|
|
|
|
self.chat_id = chat_id
|
|
|
|
|
2016-02-07 14:46:36 +01:00
|
|
|
def to_json(self):
|
|
|
|
return "{}"
|
|
|
|
|
2016-01-24 16:32:12 +01:00
|
|
|
|
2016-02-27 22:39:03 +01:00
|
|
|
@flaky(3, 1)
|
2016-01-23 12:24:49 +01:00
|
|
|
class BotanTest(BaseTest, unittest.TestCase):
|
|
|
|
"""This object represents Tests for Botan analytics integration."""
|
2016-01-23 14:58:44 +01:00
|
|
|
|
2016-01-23 17:09:56 +01:00
|
|
|
token = os.environ.get('BOTAN_TOKEN')
|
2016-01-23 12:24:49 +01:00
|
|
|
|
|
|
|
def test_track(self):
|
|
|
|
botan = Botan(self.token)
|
|
|
|
message = MessageMock(self._chat_id)
|
|
|
|
result = botan.track(message, 'named event')
|
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_track_fail(self):
|
|
|
|
botan = Botan(self.token)
|
|
|
|
botan.url_template = 'https://api.botan.io/traccc?token={token}&uid={uid}&name={name}'
|
|
|
|
message = MessageMock(self._chat_id)
|
|
|
|
result = botan.track(message, 'named event')
|
|
|
|
self.assertFalse(result)
|
|
|
|
|
2016-01-24 16:32:12 +01:00
|
|
|
def test_wrong_message(self):
|
|
|
|
botan = Botan(self.token)
|
|
|
|
message = MessageMock(self._chat_id)
|
|
|
|
message = delattr(message, 'chat_id')
|
|
|
|
result = botan.track(message, 'named event')
|
|
|
|
self.assertFalse(result)
|
|
|
|
|
|
|
|
def test_wrong_endpoint(self):
|
|
|
|
botan = Botan(self.token)
|
|
|
|
botan.url_template = 'https://api.botaaaaan.io/traccc?token={token}&uid={uid}&name={name}'
|
|
|
|
message = MessageMock(self._chat_id)
|
|
|
|
result = botan.track(message, 'named event')
|
|
|
|
self.assertFalse(result)
|
|
|
|
|
2016-04-24 04:11:25 +02:00
|
|
|
|
2016-01-23 12:24:49 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|