-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
51 lines (45 loc) · 1.55 KB
/
test_main.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
#!/usr/bin/python
# -*- coding: latin-1 -*-
import datetime, os, unittest, sys
import main
from mock import Mock, call, patch
from freezegun import freeze_time
if sys.version_info < (3,0):
import ConfigParser
else:
import configparser
class TestMainMethods(unittest.TestCase):
# def test_execute_command(self):
# bot = self.build_bot()
# bot.handle = Mock()
# main.execute_bot_command(bot, 'test')
# bot.handle.assert_called_with({'text': 'test', 'chat': {'id': 1}})
#
# @freeze_time("2017-01-01")
# def test_execute_command_monthly_first(self):
# bot = self.build_bot()
# bot.handle = Mock()
# main.execute_bot_command_monthly(bot, 'test')
# bot.handle.assert_called_with({'text': 'test', 'chat': {'id': 1}})
#
# @freeze_time("2017-01-02")
# def test_execute_command_monthly_not_first(self):
# bot = self.build_bot()
# bot.handle = Mock()
# main.execute_bot_command_monthly(bot, 'test')
# bot.handle.assert_not_called()
def build_bot(self):
if sys.version_info < (3, 0):
ConfigParser.ConfigParser = Mock()
else:
configparser.ConfigParser = Mock()
bot = Mock(return_value=456)
bot.chat = Mock()
bot.admin = 1
bot.chat.respond = Mock(return_value='chat response')
bot.do_command = Mock(return_value='command response')
bot.config = Mock()
bot.config.get = Mock(return_value='1,2')
return bot
if __name__ == '__main__':
unittest.main()