-
Notifications
You must be signed in to change notification settings - Fork 12
/
test.py
118 lines (94 loc) · 3.72 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: UTF-8 -*-
from __future__ import absolute_import
import unittest
import os
from six.moves import reload_module
import sys
reload_module(sys)
if sys.version_info.major ==2:
sys.setdefaultencoding('utf-8')
from bot.osmbot import OsmBot
from bot.error import OSMError
from bot.utils import getData
from bot.user import User
class OsmBotMock(OsmBot):
def __init__(self, *args, **kwargs):
super(OsmBotMock, self).__init__(*args, **kwargs)
class BotTest(unittest.TestCase):
# instantiate OsmBotMock class
b = OsmBotMock({}, auto_init=False)
def test_config_file(self):
"""
Test for configuraciont file
:return:None
"""
from configobj import ConfigObj
config = ConfigObj('test/bot.conf')
self.assertEqual(config['database' ], 'bot')
self.assertEqual(config['user' ], 'postgres')
self.assertEqual(config['host' ], '127.0.0.1')
self.assertEqual(config['password' ], 'password')
self.assertEqual(config['hooks' ], 'true')
self.assertEqual(config['webhook' ], 'https://example.com:443/hook/')
self.assertEqual(config['sentry_dsn'], 'sync+http://aadfsaa5@example.com:9000/1')
self.assertEqual(config['token' ], '32111224414:AAF0BqwSgFKTzkgTkJLcLBKVb2ebrSXbWX4')
self.assertEqual(config['update_interval'], '10')
def test_init_config_error(self):
"""
Test for empty config file
:return: None
"""
from configobj import ConfigObj
config = ConfigObj()
# no config and empty config
self.assertRaises(OSMError, self.b.init_config, 0)
self.assertRaises(OSMError, self.b.init_config, True)
self.assertRaises(OSMError, self.b.init_config, 'random_string')
self.assertRaises(OSMError, self.b.init_config, config)
def test_init_config(self):
from configobj import ConfigObj
config = ConfigObj('test/bot.conf')
# TODO(edgar/xevi): let's see if we can test the
# real api with a fake config
# self.b.init_config(config)
def test_languages(self):
"""
Test to ensure that languages on the locales dir are on the code
:return: None
"""
lang_dirs = os.listdir('bot/locales')
msg = '{} not found in directory in avaible languages but found in bo/locales'
for lang_dir in lang_dirs:
is_dir = os.path.isdir(os.path.join('bot/locales', lang_dir))
if is_dir and lang_dir not in self.b.get_languages().values():
print(msg.format(lang_dir))
self.assertTrue(lang_dir in self.b.get_languages().values())
def test_templates(self):
"""
Just to check templates syntax
:return: None
"""
from jinja2 import Environment, exceptions
jinja_env = Environment(extensions=['jinja2.ext.i18n'])
templates = os.listdir('bot/templates')
for template in templates:
print('Testing template:{}'.format(template))
with open(os.path.join('bot/templates', template)) as f:
if sys.version_info.major == 2:
template_text = unicode(f.read())
else:
template_text = f.read()
try:
jinja_env.from_string(template_text).render()
except exceptions.TemplateAssertionError:
pass
except exceptions.UndefinedError:
pass
def test_getData(self):
getData(343535, 'rel')
getData(423454728, 'way')
getData(2482096156, 'nod')
def test_user(self):
u = User('localhost', 'bot', 'postgres', 'empty')
if __name__ == '__main__':
unittest.main()