def test_05_pretend_processing_simple(): """Tests a simple pretend output w/ well known package. tests: R-PROCESSOR-PRETEND-003 tests: R-PROCESSOR-PRETEND-005 tests: R-PROCESSOR-PRETEND-006""" m = MagicMock() m.format_duration_estimation.return_value = "mocked duration estimation" duration = 3677820 pretend = Pretend(output=m, pretend_stream=StringIO("[ebuild N ] cat/package-4.0.3")) pretend.pre_process() merge_properties = dict(timestamp=3679157, atom="cat/package-3.2.1", atom_base="cat/package", atom_version="3.2.1", count_n="11", count_m="23") pretend.process(merge_properties, duration) pretend.post_process() max_package_name_len = len(merge_properties["atom_base"]) assert m.method_calls == [call.message("These are the pretended packages: (this may take a while; wait...)\n"), call.message("\n"), call.package_duration_header(max_package_name_len), call.package_duration(max_package_name_len, merge_properties["atom_base"], 4 * [duration]), call.message(''), call.format_duration_estimation([duration, duration, duration, duration]), call.message("Estimated update time: mocked duration estimation.")]
def test_06_package_mode(): """Tests that in package mode merge time items are collected and printed afterwards. tests: R-PROCESSOR-TIME-005 tests: R-PROCESSOR-TIME-007""" m = MagicMock() time = Time(output=m) merge_properties = [ dict(timestamp=1, atom="cat/package-3.2.1", atom_base="cat/package", atom_version="3.2.1", count_n="11", count_m="23"), dict(timestamp=2, atom="abc/package-0.47.11", atom_base="abc/package", atom_version="0.47.11", count_n="7", count_m="9"), dict(timestamp=3, atom="cat/package-3.1.1", atom_base="cat/package", atom_version="3.1.1", count_n="1", count_m="1")] for merge_property in merge_properties: time.process_package(merge_property, 50) time.post_process() assert m.method_calls == [call.message(" * {}:\n".format(merge_properties[1]["atom_base"])), call.merge_time_item(merge_properties[1]["timestamp"], merge_properties[1]["atom_base"], merge_properties[1]["atom_version"], 50), call.message(" * {}:\n".format(merge_properties[0]["atom_base"])), call.merge_time_item(merge_properties[0]["timestamp"], merge_properties[0]["atom_base"], merge_properties[0]["atom_version"], 50), call.merge_time_item(merge_properties[2]["timestamp"], merge_properties[2]["atom_base"], merge_properties[2]["atom_version"], 50), ]
def test_04_post_processing(): """Tests that pretend processor calls message with the expected post-processing text. tests: R-PROCESSOR-PRETEND-002 tests: R-PROCESSOR-PRETEND-006""" m = MagicMock() pretend = Pretend(output=m) pretend.post_process() assert m.method_calls == [call.message("\n"), call.message("!!! Error: estimated time unknown.")]
def test_09_pretend_processing_all_unknown(): """Tests a simple pretend output w/o a known package tests: R-PROCESSOR-PRETEND-003 tests: R-PROCESSOR-PRETEND-005 tests: R-PROCESSOR-PRETEND-006""" m = MagicMock() pretend = Pretend(output=m, pretend_stream=StringIO("[ebuild N ] cat/package-4.0.3")) pretend.pre_process() pretend.post_process() assert m.method_calls == [call.message("These are the pretended packages: (this may take a while; wait...)\n"), call.message("\n"), call.message("!!! Error: couldn't get previous merge of cat/package; skipping..."), call.message("\n"), call.message("!!! Error: estimated time unknown.")]
def test_04_post_processing(): """Tests that unmerge processor calls message with the expected post-processing text. test: R-PROCESSOR-UNMERGE-002""" m = MagicMock() unmerge = Unmerge(output=m) unmerge.post_process() assert m.method_calls == [call.message("")]
def test_Forward_PM_Answer(self): r = MagicMock() msg = MagicMock() msg.subreddit = None msg.author.name = credentials.admin_username msg.id = 'msgid2' msg.distinguished = None msg.subject = 're: #msgid1 /u/user: "******"' msg.body = 'body' pmUserCache = { } helper = MagicMock() helper.parseText = MagicMock(return_value=([], 'text')) oldMsg = MagicMock() r.inbox.message = MagicMock(return_value=oldMsg) # test hsbot.answerPM(r, msg, pmUserCache, helper) self.assertTrue(msg.author.name not in pmUserCache, "don't admin") expected = [call.inbox.message('msgid1')] self.assertEqual(r.method_calls, expected, 'reddit call') expected = [call.message('msgid1')] self.assertEqual(r.inbox.method_calls, expected, 'get old msg') expected = [call.reply('body')] self.assertEqual(oldMsg.method_calls, expected, 'reply old') expected = [call.reply('answer forwarded')] self.assertEqual(msg.method_calls, expected, 'reply new') self.assertEqual(helper.method_calls, [], 'no helper calls')
def test_Forward_PM(self): r = MagicMock() msg = MagicMock() msg.subreddit = None msg.author.name = 'user' msg.id = 'msgidpm' msg.distinguished = None msg.subject = 'sub' msg.body = 'body' pmUserCache = { } helper = MagicMock() helper.parseText = MagicMock(return_value=([], '')) redMsg = MagicMock() r.redditor = MagicMock(return_value=redMsg) # test hsbot.answerPM(r, msg, pmUserCache, helper) self.assertTrue('user' in pmUserCache, 'user added to cache') expected = [call.redditor(credentials.admin_username)] self.assertEqual(r.method_calls, expected, 'get redditor') expected = [call.message('#msgidpm /u/user: "******"', msg.body)] self.assertEqual(redMsg.method_calls, expected, 'set message') expected = [call.parseText('sub body')] self.assertEqual(helper.method_calls, expected, 'parseText') self.assertEqual(msg.method_calls, [], 'no reply')
def test_Forward_PM_Answer(self): r = MagicMock() msg = MagicMock() msg.subreddit = None msg.author.name = credentials.admin_username msg.id = 'msgid2' msg.distinguished = None msg.subject = 're: #msgid1 /u/user: "******"' msg.body = 'body' pmUserCache = {} helper = MagicMock() helper.parseText = MagicMock(return_value=([], 'text')) oldMsg = MagicMock() r.inbox.message = MagicMock(return_value=oldMsg) # test hsbot.answerPM(r, msg, pmUserCache, helper) self.assertTrue(msg.author.name not in pmUserCache, "don't admin") expected = [call.inbox.message('msgid1')] self.assertEqual(r.method_calls, expected, 'reddit call') expected = [call.message('msgid1')] self.assertEqual(r.inbox.method_calls, expected, 'get old msg') expected = [call.reply('body')] self.assertEqual(oldMsg.method_calls, expected, 'reply old') expected = [call.reply('answer forwarded')] self.assertEqual(msg.method_calls, expected, 'reply new') self.assertEqual(helper.method_calls, [], 'no helper calls')
def test_Forward_PM(self): r = MagicMock() msg = MagicMock() msg.subreddit = None msg.author.name = 'user' msg.id = 'msgidpm' msg.distinguished = None msg.subject = 'sub' msg.body = 'body' pmUserCache = {} helper = MagicMock() helper.parseText = MagicMock(return_value=([], '')) redMsg = MagicMock() r.redditor = MagicMock(return_value=redMsg) # test hsbot.answerPM(r, msg, pmUserCache, helper) self.assertTrue('user' in pmUserCache, 'user added to cache') expected = [call.redditor(credentials.admin_username)] self.assertEqual(r.method_calls, expected, 'get redditor') expected = [call.message('#msgidpm /u/user: "******"', msg.body)] self.assertEqual(redMsg.method_calls, expected, 'set message') expected = [call.parseText('sub body')] self.assertEqual(helper.method_calls, expected, 'parseText') self.assertEqual(msg.method_calls, [], 'no reply')
def test_02_pre_processing(): """Tests that merge processor calls message with the expected pre-processing text. test: R-PROCESSOR-MERGE-002""" m = MagicMock() merge = Merge(output=m) merge.pre_process() assert m.method_calls == [call.message(" * packages merged:\n")]
def test_04_post_processing(): """Tests that sync processor calls message with the expected post-processing text. test: R-PROCESSOR-SYNC-002""" m = MagicMock() sync = Sync(output=m) sync.post_process() assert m.method_calls == [call.message("")]
def test_02_pre_processing(): """Tests that pretend processor calls message with the expected pre-processing text. tests: R-PROCESSOR-PRETEND-002 tests: R-PROCESSOR-PRETEND-003""" m = MagicMock() pretend = Pretend(output=m, pretend_stream=StringIO()) pretend.pre_process() assert m.method_calls == [call.message("These are the pretended packages: (this may take a while; wait...)\n")]
def test_03_pre_processing(): """Tests that merge processor calls message with the expected pre-processing text. tests: R-PROCESSOR-TIME-003""" m = MagicMock() time = Time(output=m, active_filter={"search_reg_exps", }) time.pre_process() assert m.method_calls == [call.message(" * matches found:\n")] m.reset_mock() time = Time(output=m) time.pre_process() assert not m.method_calls