def setUp(self): super(TrackersManagerDbPartTest, self).setUp() with DBSession() as db: topic = Tracker1Topic(display_name=self.DISPLAY_NAME1, url=self.URL1, type=TRACKER1_PLUGIN_NAME, some_addition_field=1) db.add(topic) db.commit() self.tracker1_id1 = topic.id self.tracker1 = Tracker1() self.tracker2 = Tracker2() tracker_settings = TrackerSettings(10, None) settings_manager = Mock() settings_manager.tracker_settings = tracker_settings # noinspection PyTypeChecker self.trackers_manager = TrackersManager( settings_manager, { TRACKER1_PLUGIN_NAME: self.tracker1, TRACKER2_PLUGIN_NAME: self.tracker2, })
def setUp(self): super(TrackersManagerTest, self).setUp() self.tracker1 = Tracker1() self.tracker2 = Tracker2() self.trackers_manager = TrackersManager( TrackerSettings(10), OrderedDict(((TRACKER1_PLUGIN_NAME, self.tracker1), (TRACKER2_PLUGIN_NAME, self.tracker2))))
def setUp(self): super(TrackersManagerTest, self).setUp() self.tracker1 = Tracker1() self.tracker2 = Tracker2() tracker_settings = TrackerSettings(10, None) settings_manager = Mock() settings_manager.tracker_settings = tracker_settings # noinspection PyTypeChecker self.trackers_manager = TrackersManager( settings_manager, OrderedDict(((TRACKER1_PLUGIN_NAME, self.tracker1), (TRACKER2_PLUGIN_NAME, self.tracker2))))
def create_trackers_manager(self): execute_mock = Mock() self.trackers_manager = TrackersManager(TrackerSettings(10, None), {}) mock_tracker = Mock() mock_tracker.get_topics = Mock(return_value=[Topic()]) mock_tracker.execute = execute_mock self.trackers_manager.trackers = {'mock.tracker': mock_tracker}
def trackers_manager_set_up(self): tracker_settings = TrackerSettings(10, None) settings_manager = Mock() settings_manager.tracker_settings = tracker_settings # noinspection PyTypeChecker self.tracker_manager = TrackersManager(settings_manager, None)
def setUp(self): super(TrackersManagerTest, self).setUp() self.tracker1 = Tracker1() self.tracker2 = Tracker2() self.trackers_manager = TrackersManager(TrackerSettings(10), OrderedDict(( (TRACKER1_PLUGIN_NAME, self.tracker1), (TRACKER2_PLUGIN_NAME, self.tracker2)) ))
def setUp(self): super(TrackersManagerTest, self).setUp() self.tracker1 = Tracker1() self.tracker2 = Tracker2() tracker_settings = TrackerSettings(10, None) settings_manager = Mock() settings_manager.tracker_settings = tracker_settings # noinspection PyTypeChecker self.trackers_manager = TrackersManager(settings_manager, OrderedDict(( (TRACKER1_PLUGIN_NAME, self.tracker1), (TRACKER2_PLUGIN_NAME, self.tracker2)) ))
def setUp(self): super(TrackersManagerDbPartTest, self).setUp() with DBSession() as db: topic = Tracker1Topic(display_name=self.DISPLAY_NAME1, url=self.URL1, type=TRACKER1_PLUGIN_NAME, some_addition_field=1) db.add(topic) db.commit() self.tracker1_id1 = topic.id self.tracker1 = Tracker1() self.tracker2 = Tracker2() self.trackers_manager = TrackersManager(TrackerSettings(10), { TRACKER1_PLUGIN_NAME: self.tracker1, TRACKER2_PLUGIN_NAME: self.tracker2, })
def setUp(self): super(EngineTest, self).setUp() self.log_mock = Logger() self.log_info_mock = MagicMock() self.log_downloaded_mock = MagicMock() self.log_failed_mock = MagicMock() self.log_mock.info = self.log_info_mock self.log_mock.downloaded = self.log_downloaded_mock self.log_mock.failed = self.log_failed_mock self.clients_manager = ClientsManager() self.settings_manager = Mock() self.trackers_manager = TrackersManager(self.settings_manager, {}) self.notifier_manager = NotifierManager({}) self.engine = Engine(self.log_mock, self.settings_manager, self.trackers_manager, self.clients_manager, self.notifier_manager)
def trackers_manager_set_up(self): self.tracker_manager = TrackersManager( TrackerSettings(10), {'test': TrackerCollectionTest.TestTracker()})
class TrackersManagerDbPartTest(DbTestCase): DISPLAY_NAME1 = "Some Name / Translated Name" URL1 = "http://tracker.com/1/" def setUp(self): super(TrackersManagerDbPartTest, self).setUp() with DBSession() as db: topic = Tracker1Topic(display_name=self.DISPLAY_NAME1, url=self.URL1, type=TRACKER1_PLUGIN_NAME, some_addition_field=1) db.add(topic) db.commit() self.tracker1_id1 = topic.id self.tracker1 = Tracker1() self.tracker2 = Tracker2() tracker_settings = TrackerSettings(10, None) settings_manager = Mock() settings_manager.tracker_settings = tracker_settings # noinspection PyTypeChecker self.trackers_manager = TrackersManager( settings_manager, { TRACKER1_PLUGIN_NAME: self.tracker1, TRACKER2_PLUGIN_NAME: self.tracker2, }) def create_removed_topic(self): remove_type = TRACKER1_PLUGIN_NAME + ".uk" with DBSession() as db: topic = Topic(display_name=self.DISPLAY_NAME1 + " / Test", url="http://tracker.com/2/", type=remove_type) result = db.execute( topic.__table__.insert(), row2dict(topic, fields=['display_name', 'url', 'type'])) tracker1_id2 = result.inserted_primary_key[0] return tracker1_id2 def test_remove_topic_1(self): self.assertTrue(self.trackers_manager.remove_topic(self.tracker1_id1)) with DBSession() as db: topic = db.query(Topic).filter( Topic.id == self.tracker1_id1).first() self.assertIsNone(topic) def test_remove_topic_2(self): with self.assertRaises(KeyError): self.trackers_manager.remove_topic(self.tracker1_id1 + 1) with DBSession() as db: topic = db.query(Topic).filter( Topic.id == self.tracker1_id1).first() self.assertIsNotNone(topic) def test_get_topic_1(self): topic_settings = {'display_name': self.DISPLAY_NAME1} get_topic_mock = MagicMock(return_value=topic_settings) self.tracker1.get_topic = get_topic_mock result = self.trackers_manager.get_topic(self.tracker1_id1) self.assertEqual( { 'form': self.tracker1.topic_form, 'settings': topic_settings }, result) get_topic_mock.assert_called_with(self.tracker1_id1) def test_get_topic_2(self): with self.assertRaises(KeyError): self.trackers_manager.get_topic(self.tracker1_id1 + 1) def test_get_topic_3(self): tracker1_id2 = self.create_removed_topic() with self.assertRaises(KeyError): self.trackers_manager.get_topic(tracker1_id2) @data(True, False) def test_update_topic_1(self, value): topic_settings = {'display_name': self.DISPLAY_NAME1} update_topic_mock = MagicMock(return_value=value) self.tracker1.update_topic = update_topic_mock self.assertEqual( value, self.trackers_manager.update_topic(self.tracker1_id1, topic_settings)) update_topic_mock.assert_called_with(self.tracker1_id1, topic_settings) def test_update_topic_2(self): tracker1_id2 = self.create_removed_topic() with self.assertRaises(KeyError): self.trackers_manager.get_topic(tracker1_id2) def test_reset_topic_status_1(self): with DBSession() as db: topic = db.query(Topic).filter( Topic.id == self.tracker1_id1).first() topic.status = Status.NotFound topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['status'], str(Status.NotFound)) self.trackers_manager.reset_topic_status(self.tracker1_id1) topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['status'], str(Status.Ok)) def test_reset_topic_status_2(self): tracker1_id2 = self.tracker1_id1 * 100 with self.assertRaises(KeyError): self.trackers_manager.reset_topic_status(tracker1_id2) def test_set_topic_paused_success(self): with DBSession() as db: topic = db.query(Topic).filter( Topic.id == self.tracker1_id1).first() topic.paused = True topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['paused'], True) self.trackers_manager.set_topic_paused(self.tracker1_id1, False) topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['paused'], False) self.trackers_manager.set_topic_paused(self.tracker1_id1, True) topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['paused'], True) def test_reset_topic_status_failed(self): tracker1_id2 = self.tracker1_id1 * 100 with self.assertRaises(KeyError): self.trackers_manager.set_topic_paused(tracker1_id2, True) def test_get_watching_topics_1(self): topics = self.trackers_manager.get_watching_topics() self.assertIsNotNone(topics) self.assertEqual(1, len(topics)) self.assertEqual([{ 'id': self.tracker1_id1, 'display_name': self.DISPLAY_NAME1, 'url': self.URL1, 'last_update': None, 'info': None, 'tracker': TRACKER1_PLUGIN_NAME, 'status': Status.Ok.__str__(), 'paused': False }], topics) def test_get_watching_topics_2(self): with DBSession() as db: topic2 = Tracker2Topic(display_name='Some Name 2 / Other Name 2', url='https://tracker2.tracker/2', type=TRACKER2_PLUGIN_NAME, some_addition_field=2, status=Status.Ok) db.add(topic2) db.commit() topic2_id = topic2.id topics = self.trackers_manager.get_watching_topics() self.assertIsNotNone(topics) self.assertEqual(2, len(topics)) self.assertEqual([{ 'id': self.tracker1_id1, 'display_name': self.DISPLAY_NAME1, 'url': self.URL1, 'last_update': None, 'info': None, 'tracker': TRACKER1_PLUGIN_NAME, 'status': Status.Ok.__str__(), 'paused': False }, { 'id': topic2_id, 'display_name': 'Some Name 2 / Other Name 2', 'url': 'https://tracker2.tracker/2', 'last_update': None, 'info': None, 'tracker': TRACKER2_PLUGIN_NAME, 'thumbnail_url': 'https://tracker2.tracker/2/poster.jpg', 'status': Status.Ok.__str__(), 'paused': False }], topics) def test_get_watching_topics_3(self): self.create_removed_topic() topics = self.trackers_manager.get_watching_topics() self.assertIsNotNone(topics) self.assertEqual(1, len(topics)) self.assertEqual([{ 'id': self.tracker1_id1, 'display_name': self.DISPLAY_NAME1, 'url': self.URL1, 'last_update': None, 'info': None, 'tracker': TRACKER1_PLUGIN_NAME, 'status': Status.Ok.__str__(), 'paused': False }], topics) def test_get_tracker_topics(self): topics = self.trackers_manager.get_tracker_topics(TRACKER1_PLUGIN_NAME) self.assertIsNotNone(topics) self.assertEqual(len(topics), 1) self.assertEqual(topics[0].id, self.tracker1_id1) topics = self.trackers_manager.get_tracker_topics(TRACKER2_PLUGIN_NAME) self.assertEqual(topics, []) def test_get_tracker_topics_key_error(self): topics = self.trackers_manager.get_tracker_topics(TRACKER1_PLUGIN_NAME) self.assertIsNotNone(topics) self.assertEqual(len(topics), 1) self.assertEqual(topics[0].id, self.tracker1_id1) with self.assertRaises(KeyError): self.trackers_manager.get_tracker_topics('UnknowTracker') def test_get_status_topics(self): with DBSession() as db: topic1 = Tracker1Topic(display_name=self.DISPLAY_NAME1 + '/1', url=self.URL1 + '/1', type=TRACKER1_PLUGIN_NAME, some_addition_field=1, status=Status.Error) db.add(topic1) topic2 = Tracker1Topic(display_name=self.DISPLAY_NAME1 + '/2', url=self.URL1 + '/2', type=TRACKER1_PLUGIN_NAME, some_addition_field=1, status=Status.NotFound) db.add(topic2) topic3 = Tracker2Topic(display_name=self.DISPLAY_NAME1 + '/3', url=self.URL1 + '/3', type=TRACKER2_PLUGIN_NAME, some_addition_field=1, status=Status.Unknown) db.add(topic3) db.commit() topic1_id = topic1.id topic2_id = topic2.id topic3_id = topic3.id topics = self.trackers_manager.get_status_topics_ids([Status.Ok]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], self.tracker1_id1) topics = self.trackers_manager.get_status_topics_ids([Status.Error]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], topic1_id) topics = self.trackers_manager.get_status_topics_ids([Status.NotFound]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], topic2_id) topics = self.trackers_manager.get_status_topics_ids([Status.Unknown]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], topic3_id) topics = self.trackers_manager.get_status_topics_ids( [Status.Error, Status.NotFound]) self.assertEqual(len(topics), 2) self.assertListEqual(sorted(topics), sorted([topic1_id, topic2_id]))
def trackers_manager_set_up(self): self.tracker_manager = TrackersManager(TrackerSettings(10))
def setUp(self): super(DBExecuteEngineTest, self).setUp() self.trackers_manager = TrackersManager(TrackerSettings(10), {})
def setUp(self): super(EngineRunnerTest, self).setUp() self.trackers_manager = TrackersManager(TrackerSettings(10), {})
class TrackersManagerDbPartTest(DbTestCase): DISPLAY_NAME1 = "Some Name / Translated Name" URL1 = "http://tracker.com/1/" def setUp(self): super(TrackersManagerDbPartTest, self).setUp() with DBSession() as db: topic = Tracker1Topic(display_name=self.DISPLAY_NAME1, url=self.URL1, type=TRACKER1_PLUGIN_NAME, some_addition_field=1) db.add(topic) db.commit() self.tracker1_id1 = topic.id self.tracker1 = Tracker1() self.tracker2 = Tracker2() self.trackers_manager = TrackersManager( TrackerSettings(10), { TRACKER1_PLUGIN_NAME: self.tracker1, TRACKER2_PLUGIN_NAME: self.tracker2, }) def create_removed_topic(self): remove_type = TRACKER1_PLUGIN_NAME + ".uk" with DBSession() as db: topic = Topic(display_name=self.DISPLAY_NAME1 + " / Test", url="http://tracker.com/2/", type=remove_type) result = db.execute( topic.__table__.insert(), row2dict(topic, fields=['display_name', 'url', 'type'])) tracker1_id2 = result.inserted_primary_key[0] return tracker1_id2 def test_remove_topic_1(self): self.assertTrue(self.trackers_manager.remove_topic(self.tracker1_id1)) with DBSession() as db: topic = db.query(Topic).filter( Topic.id == self.tracker1_id1).first() self.assertIsNone(topic) def test_remove_topic_2(self): with self.assertRaises(KeyError): self.trackers_manager.remove_topic(self.tracker1_id1 + 1) with DBSession() as db: topic = db.query(Topic).filter( Topic.id == self.tracker1_id1).first() self.assertIsNotNone(topic) def test_get_topic_1(self): topic_settings = {'display_name': self.DISPLAY_NAME1} get_topic_mock = MagicMock(return_value=topic_settings) self.tracker1.get_topic = get_topic_mock result = self.trackers_manager.get_topic(self.tracker1_id1) self.assertEqual( { 'form': self.tracker1.topic_form, 'settings': topic_settings }, result) get_topic_mock.assert_called_with(self.tracker1_id1) def test_get_topic_2(self): with self.assertRaises(KeyError): self.trackers_manager.get_topic(self.tracker1_id1 + 1) def test_get_topic_3(self): tracker1_id2 = self.create_removed_topic() with self.assertRaises(KeyError): self.trackers_manager.get_topic(tracker1_id2) @data(True, False) def test_update_topic_1(self, value): topic_settings = {'display_name': self.DISPLAY_NAME1} update_topic_mock = MagicMock(return_value=value) self.tracker1.update_topic = update_topic_mock self.assertEqual( value, self.trackers_manager.update_topic(self.tracker1_id1, topic_settings)) update_topic_mock.assert_called_with(self.tracker1_id1, topic_settings) def test_update_topic_2(self): tracker1_id2 = self.create_removed_topic() with self.assertRaises(KeyError): self.trackers_manager.get_topic(tracker1_id2) def test_reset_topic_status_1(self): with DBSession() as db: topic = db.query(Topic).filter( Topic.id == self.tracker1_id1).first() topic.status = Status.NotFound topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['status'], str(Status.NotFound)) self.trackers_manager.reset_topic_status(self.tracker1_id1) topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['status'], str(Status.Ok)) def test_reset_topic_status_2(self): tracker1_id2 = self.tracker1_id1 * 100 with self.assertRaises(KeyError): self.trackers_manager.reset_topic_status(tracker1_id2) def test_get_watching_topics_1(self): topics = self.trackers_manager.get_watching_topics() self.assertIsNotNone(topics) self.assertEqual(1, len(topics)) self.assertEqual([{ 'id': self.tracker1_id1, 'display_name': self.DISPLAY_NAME1, 'url': self.URL1, 'last_update': None, 'info': None, 'tracker': TRACKER1_PLUGIN_NAME, 'status': Status.Ok.__str__() }], topics) def test_get_watching_topics_2(self): self.create_removed_topic() topics = self.trackers_manager.get_watching_topics() self.assertIsNotNone(topics) self.assertEqual(1, len(topics)) self.assertEqual([{ 'id': self.tracker1_id1, 'display_name': self.DISPLAY_NAME1, 'url': self.URL1, 'last_update': None, 'info': None, 'tracker': TRACKER1_PLUGIN_NAME, 'status': Status.Ok.__str__() }], topics) def test_get_tracker_topics(self): topics = self.trackers_manager.get_tracker_topics(TRACKER1_PLUGIN_NAME) self.assertIsNotNone(topics) self.assertEqual(len(topics), 1) self.assertEqual(topics[0].id, self.tracker1_id1) topics = self.trackers_manager.get_tracker_topics(TRACKER2_PLUGIN_NAME) self.assertEqual(topics, []) def test_get_tracker_topics_key_error(self): topics = self.trackers_manager.get_tracker_topics(TRACKER1_PLUGIN_NAME) self.assertIsNotNone(topics) self.assertEqual(len(topics), 1) self.assertEqual(topics[0].id, self.tracker1_id1) with self.assertRaises(KeyError): self.trackers_manager.get_tracker_topics('UnknowTracker') def test_get_status_topics(self): with DBSession() as db: topic1 = Tracker1Topic(display_name=self.DISPLAY_NAME1 + '/1', url=self.URL1 + '/1', type=TRACKER1_PLUGIN_NAME, some_addition_field=1, status=Status.Error) db.add(topic1) topic2 = Tracker1Topic(display_name=self.DISPLAY_NAME1 + '/2', url=self.URL1 + '/2', type=TRACKER1_PLUGIN_NAME, some_addition_field=1, status=Status.NotFound) db.add(topic2) topic3 = Tracker2Topic(display_name=self.DISPLAY_NAME1 + '/3', url=self.URL1 + '/3', type=TRACKER2_PLUGIN_NAME, some_addition_field=1, status=Status.Unknown) db.add(topic3) db.commit() topic1_id = topic1.id topic2_id = topic2.id topic3_id = topic3.id topics = self.trackers_manager.get_status_topics_ids([Status.Ok]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], self.tracker1_id1) topics = self.trackers_manager.get_status_topics_ids([Status.Error]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], topic1_id) topics = self.trackers_manager.get_status_topics_ids([Status.NotFound]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], topic2_id) topics = self.trackers_manager.get_status_topics_ids([Status.Unknown]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], topic3_id) topics = self.trackers_manager.get_status_topics_ids( [Status.Error, Status.NotFound]) self.assertEqual(len(topics), 2) self.assertListEqual(sorted(topics), sorted([topic1_id, topic2_id])) def test_execute_success(self): engine = Mock() engine.log = Mock() engine.log.info = MagicMock() engine.log.failed = MagicMock() execute_mock = MagicMock() topics = [Mock()] get_topics_mock = Mock(return_value=topics) self.tracker1.execute = execute_mock self.tracker1.get_topics = get_topics_mock self.tracker2.execute = execute_mock self.tracker2.get_topics = get_topics_mock self.trackers_manager.execute(engine, None) self.assertTrue(engine.log.info.called) self.assertFalse(engine.log.failed.called) get_topics_mock.assert_called_with(None) execute_mock.assert_called_with(topics, engine) def test_execute_fails(self): engine = Mock() engine.log = Mock() engine.log.info = MagicMock() engine.log.failed = MagicMock() topics = [Mock()] get_topics_mock = Mock(return_value=topics) execute_mock1 = MagicMock(side_effect=Exception) execute_mock2 = MagicMock(side_effect=Exception) self.tracker1.execute = execute_mock1 self.tracker1.get_topics = get_topics_mock self.tracker2.execute = execute_mock2 self.tracker2.get_topics = get_topics_mock self.trackers_manager.execute(engine, None) self.assertTrue(engine.log.info.called) self.assertTrue(engine.log.failed.called) get_topics_mock.assert_called_with(None) execute_mock1.assert_called_with(topics, engine) execute_mock2.assert_called_with(topics, engine) def test_execute_skip_one_plugin(self): engine = Mock() engine.log = Mock() engine.log.info = MagicMock() engine.log.failed = MagicMock() topics1 = [Mock()] get_topics_mock1 = Mock(return_value=topics1) topics2 = [] get_topics_mock2 = Mock(return_value=topics2) execute_mock1 = Mock() # Exception shouldn't be thrown because there are no tocpis for plugin execute_mock2 = Mock(return_value=Exception) self.tracker1.execute = execute_mock1 self.tracker1.get_topics = get_topics_mock1 self.tracker2.execute = execute_mock2 self.tracker2.get_topics = get_topics_mock2 self.trackers_manager.execute(engine, None) self.assertTrue(engine.log.info.called) self.assertFalse(engine.log.failed.called ) # Check that exception from tracker2 wasn't raised get_topics_mock1.assert_called_with(None) execute_mock1.assert_called_with(topics1, engine) get_topics_mock2.assert_called_with(None) execute_mock2.assert_not_called() def test_execute_with_ids(self): engine = Mock() engine.log = Mock() engine.log.info = MagicMock() engine.log.failed = MagicMock() topics1 = [Mock()] get_topics_mock1 = Mock(return_value=topics1) topics2 = [] get_topics_mock2 = Mock(return_value=topics2) execute_mock1 = Mock() # Exception shouldn't be thrown because there are no tocpis for plugin execute_mock2 = Mock(return_value=Exception) self.tracker1.execute = execute_mock1 self.tracker1.get_topics = get_topics_mock1 self.tracker2.execute = execute_mock2 self.tracker2.get_topics = get_topics_mock2 ids = [1, 2] self.trackers_manager.execute(engine, ids) self.assertTrue(engine.log.info.called) self.assertFalse(engine.log.failed.called ) # Check that exception from tracker2 wasn't raised get_topics_mock1.assert_called_with(ids) execute_mock1.assert_called_with(topics1, engine) get_topics_mock2.assert_called_with(ids) execute_mock2.assert_not_called()
class TrackersManagerTest(TestCase): def setUp(self): super(TrackersManagerTest, self).setUp() self.tracker1 = Tracker1() self.tracker2 = Tracker2() self.trackers_manager = TrackersManager( TrackerSettings(10), OrderedDict(((TRACKER1_PLUGIN_NAME, self.tracker1), (TRACKER2_PLUGIN_NAME, self.tracker2)))) def test_get_settings(self): self.assertIsNone( self.trackers_manager.get_settings(TRACKER1_PLUGIN_NAME)) credentials2 = {'login': '******'} get_credentials_mock = MagicMock(return_value=credentials2) self.tracker2.get_credentials = get_credentials_mock self.assertEqual( self.trackers_manager.get_settings(TRACKER2_PLUGIN_NAME), credentials2) get_credentials_mock.assert_called_with() def test_set_settings(self): credentials1 = {'login': '******'} self.assertFalse( self.trackers_manager.set_settings(TRACKER1_PLUGIN_NAME, credentials1)) credentials2 = {'login': '******', 'password': '******'} update_credentials_mock2 = MagicMock() self.tracker2.update_credentials = update_credentials_mock2 self.assertTrue( self.trackers_manager.set_settings(TRACKER2_PLUGIN_NAME, credentials2)) update_credentials_mock2.assert_called_with(credentials2) def test_check_connection(self): self.assertFalse( self.trackers_manager.check_connection(TRACKER1_PLUGIN_NAME)) verify_mock = MagicMock(return_value=True) self.tracker2.verify = verify_mock self.assertTrue( self.trackers_manager.check_connection(TRACKER2_PLUGIN_NAME)) verify_mock.assert_called_with() def test_prepare_add_topic_1(self): parsed_url = {'display_name': "Some Name / Translated Name"} prepare_add_topic_mock1 = MagicMock(return_value=parsed_url) self.tracker1.prepare_add_topic = prepare_add_topic_mock1 result = self.trackers_manager.prepare_add_topic( 'http://tracker.com/1/') self.assertIsNotNone(result) prepare_add_topic_mock1.assert_called_with('http://tracker.com/1/') self.assertEqual(result, { 'form': TrackerPluginBase.topic_form, 'settings': parsed_url }) def test_prepare_add_topic_2(self): prepare_add_topic_mock1 = MagicMock(return_value=None) self.tracker1.prepare_add_topic = prepare_add_topic_mock1 parsed_url = {'display_name': "Some Name / Translated Name"} prepare_add_topic_mock2 = MagicMock(return_value=parsed_url) self.tracker2.prepare_add_topic = prepare_add_topic_mock2 result = self.trackers_manager.prepare_add_topic( 'http://tracker.com/1/') self.assertIsNotNone(result) prepare_add_topic_mock1.assert_called_with('http://tracker.com/1/') prepare_add_topic_mock2.assert_called_with('http://tracker.com/1/') self.assertEqual(result, { 'form': TrackerPluginBase.topic_form, 'settings': parsed_url }) def test_prepare_add_topic_3(self): prepare_add_topic_mock1 = MagicMock(return_value=None) self.tracker1.prepare_add_topic = prepare_add_topic_mock1 prepare_add_topic_mock2 = MagicMock(return_value=None) self.tracker2.prepare_add_topic = prepare_add_topic_mock2 result = self.trackers_manager.prepare_add_topic( 'http://tracker.com/1/') self.assertIsNone(result) prepare_add_topic_mock1.assert_called_with('http://tracker.com/1/') prepare_add_topic_mock2.assert_called_with('http://tracker.com/1/') def test_add_topic_1(self): can_parse_url_mock1 = MagicMock(return_value=True) add_topic_mock1 = MagicMock(return_value=True) self.tracker1.can_parse_url = can_parse_url_mock1 self.tracker1.add_topic = add_topic_mock1 params = {'display_name': "Some Name / Translated Name"} url = 'http://tracker.com/1/' self.assertTrue(self.trackers_manager.add_topic(url, params)) can_parse_url_mock1.assert_called_with(url) add_topic_mock1.assert_called_with(url, params) def test_add_topic_2(self): can_parse_url_mock1 = MagicMock(return_value=False) add_topic_mock1 = MagicMock(return_value=False) self.tracker1.can_parse_url = can_parse_url_mock1 self.tracker1.add_topic = add_topic_mock1 can_parse_url_mock2 = MagicMock(return_value=True) add_topic_mock2 = MagicMock(return_value=True) self.tracker2.can_parse_url = can_parse_url_mock2 self.tracker2.add_topic = add_topic_mock2 params = {'display_name': "Some Name / Translated Name"} url = 'http://tracker.com/1/' self.assertTrue(self.trackers_manager.add_topic(url, params)) can_parse_url_mock1.assert_called_with(url) add_topic_mock1.assert_not_called() can_parse_url_mock2.assert_called_with(url) add_topic_mock2.assert_called_with(url, params) def test_add_topic_3(self): can_parse_url_mock1 = MagicMock(return_value=False) add_topic_mock1 = MagicMock(return_value=False) self.tracker1.can_parse_url = can_parse_url_mock1 self.tracker1.add_topic = add_topic_mock1 can_parse_url_mock2 = MagicMock(return_value=False) add_topic_mock2 = MagicMock(return_value=False) self.tracker2.can_parse_url = can_parse_url_mock2 self.tracker2.add_topic = add_topic_mock2 params = {'display_name': "Some Name / Translated Name"} url = 'http://tracker.com/1/' self.assertFalse(self.trackers_manager.add_topic(url, params)) can_parse_url_mock1.assert_called_with(url) add_topic_mock1.assert_not_called() can_parse_url_mock2.assert_called_with(url) add_topic_mock2.assert_not_called()
class TrackersManagerDbPartTest(DbTestCase): DISPLAY_NAME1 = "Some Name / Translated Name" URL1 = "http://tracker.com/1/" def setUp(self): super(TrackersManagerDbPartTest, self).setUp() with DBSession() as db: topic = Tracker1Topic(display_name=self.DISPLAY_NAME1, url=self.URL1, type=TRACKER1_PLUGIN_NAME, some_addition_field=1) db.add(topic) db.commit() self.tracker1_id1 = topic.id self.tracker1 = Tracker1() self.tracker2 = Tracker2() tracker_settings = TrackerSettings(10, None) settings_manager = Mock() settings_manager.tracker_settings = tracker_settings # noinspection PyTypeChecker self.trackers_manager = TrackersManager(settings_manager, { TRACKER1_PLUGIN_NAME: self.tracker1, TRACKER2_PLUGIN_NAME: self.tracker2, }) def create_removed_topic(self): remove_type = TRACKER1_PLUGIN_NAME + ".uk" with DBSession() as db: topic = Topic(display_name=self.DISPLAY_NAME1 + " / Test", url="http://tracker.com/2/", type=remove_type) result = db.execute(topic.__table__.insert(), row2dict(topic, fields=['display_name', 'url', 'type'])) tracker1_id2 = result.inserted_primary_key[0] return tracker1_id2 def test_remove_topic_1(self): self.assertTrue(self.trackers_manager.remove_topic(self.tracker1_id1)) with DBSession() as db: topic = db.query(Topic).filter(Topic.id == self.tracker1_id1).first() self.assertIsNone(topic) def test_remove_topic_2(self): with self.assertRaises(KeyError): self.trackers_manager.remove_topic(self.tracker1_id1 + 1) with DBSession() as db: topic = db.query(Topic).filter(Topic.id == self.tracker1_id1).first() self.assertIsNotNone(topic) def test_get_topic_1(self): topic_settings = {'display_name': self.DISPLAY_NAME1} get_topic_mock = MagicMock(return_value=topic_settings) self.tracker1.get_topic = get_topic_mock result = self.trackers_manager.get_topic(self.tracker1_id1) self.assertEqual({'form': self.tracker1.topic_form, 'settings': topic_settings}, result) get_topic_mock.assert_called_with(self.tracker1_id1) def test_get_topic_2(self): with self.assertRaises(KeyError): self.trackers_manager.get_topic(self.tracker1_id1 + 1) def test_get_topic_3(self): tracker1_id2 = self.create_removed_topic() with self.assertRaises(KeyError): self.trackers_manager.get_topic(tracker1_id2) @data(True, False) def test_update_topic_1(self, value): topic_settings = {'display_name': self.DISPLAY_NAME1} update_topic_mock = MagicMock(return_value=value) self.tracker1.update_topic = update_topic_mock self.assertEqual(value, self.trackers_manager.update_topic(self.tracker1_id1, topic_settings)) update_topic_mock.assert_called_with(self.tracker1_id1, topic_settings) def test_update_topic_2(self): tracker1_id2 = self.create_removed_topic() with self.assertRaises(KeyError): self.trackers_manager.get_topic(tracker1_id2) def test_reset_topic_status_1(self): with DBSession() as db: topic = db.query(Topic).filter(Topic.id == self.tracker1_id1).first() topic.status = Status.NotFound topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['status'], str(Status.NotFound)) self.trackers_manager.reset_topic_status(self.tracker1_id1) topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['status'], str(Status.Ok)) def test_reset_topic_status_2(self): tracker1_id2 = self.tracker1_id1 * 100 with self.assertRaises(KeyError): self.trackers_manager.reset_topic_status(tracker1_id2) def test_set_topic_paused_success(self): with DBSession() as db: topic = db.query(Topic).filter(Topic.id == self.tracker1_id1).first() topic.paused = True topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['paused'], True) self.trackers_manager.set_topic_paused(self.tracker1_id1, False) topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['paused'], False) self.trackers_manager.set_topic_paused(self.tracker1_id1, True) topic = self.trackers_manager.get_watching_topics()[0] self.assertEqual(topic['paused'], True) def test_reset_topic_status_failed(self): tracker1_id2 = self.tracker1_id1 * 100 with self.assertRaises(KeyError): self.trackers_manager.set_topic_paused(tracker1_id2, True) def test_get_watching_topics_1(self): topics = self.trackers_manager.get_watching_topics() self.assertIsNotNone(topics) self.assertEqual(1, len(topics)) self.assertEqual([ { 'id': self.tracker1_id1, 'display_name': self.DISPLAY_NAME1, 'url': self.URL1, 'last_update': None, 'info': None, 'tracker': TRACKER1_PLUGIN_NAME, 'status': Status.Ok.__str__(), 'paused': False }], topics) def test_get_watching_topics_2(self): self.create_removed_topic() topics = self.trackers_manager.get_watching_topics() self.assertIsNotNone(topics) self.assertEqual(1, len(topics)) self.assertEqual([ { 'id': self.tracker1_id1, 'display_name': self.DISPLAY_NAME1, 'url': self.URL1, 'last_update': None, 'info': None, 'tracker': TRACKER1_PLUGIN_NAME, 'status': Status.Ok.__str__(), 'paused': False }], topics) def test_get_tracker_topics(self): topics = self.trackers_manager.get_tracker_topics(TRACKER1_PLUGIN_NAME) self.assertIsNotNone(topics) self.assertEqual(len(topics), 1) self.assertEqual(topics[0].id, self.tracker1_id1) topics = self.trackers_manager.get_tracker_topics(TRACKER2_PLUGIN_NAME) self.assertEqual(topics, []) def test_get_tracker_topics_key_error(self): topics = self.trackers_manager.get_tracker_topics(TRACKER1_PLUGIN_NAME) self.assertIsNotNone(topics) self.assertEqual(len(topics), 1) self.assertEqual(topics[0].id, self.tracker1_id1) with self.assertRaises(KeyError): self.trackers_manager.get_tracker_topics('UnknowTracker') def test_get_status_topics(self): with DBSession() as db: topic1 = Tracker1Topic(display_name=self.DISPLAY_NAME1 + '/1', url=self.URL1 + '/1', type=TRACKER1_PLUGIN_NAME, some_addition_field=1, status=Status.Error) db.add(topic1) topic2 = Tracker1Topic(display_name=self.DISPLAY_NAME1 + '/2', url=self.URL1 + '/2', type=TRACKER1_PLUGIN_NAME, some_addition_field=1, status=Status.NotFound) db.add(topic2) topic3 = Tracker2Topic(display_name=self.DISPLAY_NAME1 + '/3', url=self.URL1 + '/3', type=TRACKER2_PLUGIN_NAME, some_addition_field=1, status=Status.Unknown) db.add(topic3) db.commit() topic1_id = topic1.id topic2_id = topic2.id topic3_id = topic3.id topics = self.trackers_manager.get_status_topics_ids([Status.Ok]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], self.tracker1_id1) topics = self.trackers_manager.get_status_topics_ids([Status.Error]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], topic1_id) topics = self.trackers_manager.get_status_topics_ids([Status.NotFound]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], topic2_id) topics = self.trackers_manager.get_status_topics_ids([Status.Unknown]) self.assertEqual(len(topics), 1) self.assertEqual(topics[0], topic3_id) topics = self.trackers_manager.get_status_topics_ids([Status.Error, Status.NotFound]) self.assertEqual(len(topics), 2) self.assertListEqual(sorted(topics), sorted([topic1_id, topic2_id])) def test_execute_success(self): engine = Mock() engine.log = Mock() engine.log.info = MagicMock() engine.log.failed = MagicMock() execute_mock = MagicMock() topics = [Mock()] get_topics_mock = Mock(return_value=topics) self.tracker1.execute = execute_mock self.tracker1.get_topics = get_topics_mock self.tracker2.execute = execute_mock self.tracker2.get_topics = get_topics_mock self.trackers_manager.execute(engine, None) self.assertTrue(engine.log.info.called) self.assertFalse(engine.log.failed.called) get_topics_mock.assert_called_with(None) execute_mock.assert_called_with(topics, engine) def test_execute_fails(self): engine = Mock() engine.log = Mock() engine.log.info = MagicMock() engine.log.failed = MagicMock() topics = [Mock()] get_topics_mock = Mock(return_value=topics) execute_mock1 = MagicMock(side_effect=Exception) execute_mock2 = MagicMock(side_effect=Exception) self.tracker1.execute = execute_mock1 self.tracker1.get_topics = get_topics_mock self.tracker2.execute = execute_mock2 self.tracker2.get_topics = get_topics_mock self.trackers_manager.execute(engine, None) self.assertTrue(engine.log.info.called) self.assertTrue(engine.log.failed.called) get_topics_mock.assert_called_with(None) execute_mock1.assert_called_with(topics, engine) execute_mock2.assert_called_with(topics, engine) def test_execute_skip_one_plugin(self): engine = Mock() engine.log = Mock() engine.log.info = MagicMock() engine.log.failed = MagicMock() topics1 = [Mock()] get_topics_mock1 = Mock(return_value=topics1) topics2 = [] get_topics_mock2 = Mock(return_value=topics2) execute_mock1 = Mock() # Exception shouldn't be thrown because there are no tocpis for plugin execute_mock2 = Mock(return_value=Exception) self.tracker1.execute = execute_mock1 self.tracker1.get_topics = get_topics_mock1 self.tracker2.execute = execute_mock2 self.tracker2.get_topics = get_topics_mock2 self.trackers_manager.execute(engine, None) self.assertTrue(engine.log.info.called) self.assertFalse(engine.log.failed.called) # Check that exception from tracker2 wasn't raised get_topics_mock1.assert_called_with(None) execute_mock1.assert_called_with(topics1, engine) get_topics_mock2.assert_called_with(None) execute_mock2.assert_not_called() def test_execute_with_ids(self): engine = Mock() engine.log = Mock() engine.log.info = MagicMock() engine.log.failed = MagicMock() topics1 = [Mock()] get_topics_mock1 = Mock(return_value=topics1) topics2 = [] get_topics_mock2 = Mock(return_value=topics2) execute_mock1 = Mock() # Exception shouldn't be thrown because there are no tocpis for plugin execute_mock2 = Mock(return_value=Exception) self.tracker1.execute = execute_mock1 self.tracker1.get_topics = get_topics_mock1 self.tracker2.execute = execute_mock2 self.tracker2.get_topics = get_topics_mock2 ids = [1, 2] self.trackers_manager.execute(engine, ids) self.assertTrue(engine.log.info.called) self.assertFalse(engine.log.failed.called) # Check that exception from tracker2 wasn't raised get_topics_mock1.assert_called_with(ids) execute_mock1.assert_called_with(topics1, engine) get_topics_mock2.assert_called_with(ids) execute_mock2.assert_not_called()
def main(): def try_int(s, base=10, val=None): if s is None: return None try: return int(s, base) except ValueError: return val class Config(object): debug = False ip = '0.0.0.0' port = 6687 db_path = 'monitorrent.db' config = 'config.py' def __init__(self, parsed_args): if parsed_args.config is not None and not os.path.isfile(parsed_args.config): warnings.warn('File not found: {}'.format(parsed_args.config)) config_path = parsed_args.config or self.config if os.path.isfile(config_path): # noinspection PyBroadException try: parsed_config = {} with open(config_path) as config_file: six.exec_(compile(config_file.read(), config_path, 'exec'), {}, parsed_config) self.debug = parsed_config.get('debug', self.debug) self.ip = parsed_config.get('ip', self.ip) self.port = parsed_config.get('port', self.port) self.db_path = parsed_config.get('db_path', self.db_path) except: ex, val, tb = sys.exc_info() warnings.warn('Error reading: {0}: {1} ({2}'.format(parsed_args.config, ex, val)) env_debug = (os.environ.get('MONITORRENT_DEBUG', None) in ['true', 'True', '1']) self.debug = parsed_args.debug or env_debug or self.debug self.ip = parsed_args.ip or os.environ.get('MONITORRENT_IP', None) or self.ip self.port = parsed_args.port or try_int(os.environ.get('MONITORRENT_PORT', None)) or self.port self.db_path = parsed_args.db_path or os.environ.get('MONITORRENT_DB_PATH', None) or self.db_path parser = argparse.ArgumentParser(description='Monitorrent server') parser.add_argument('--debug', action='store_true', help='Run in debug mode. Secret key is always the same.') parser.add_argument('--ip', type=str, dest='ip', help='Bind interface. Default is {0}'.format(Config.ip)) parser.add_argument('--port', type=int, dest='port', help='Port for server. Default is {0}'.format(Config.port)) parser.add_argument('--db-path', type=str, dest='db_path', help='Path to SQL lite database. Default is to {0}'.format(Config.db_path)) parser.add_argument('--config', type=str, dest='config', default=os.environ.get('MONITORRENT_CONFIG', None), help='Path to config file (default {0})'.format(Config.config)) parsed_args = parser.parse_args() config = Config(parsed_args) db_connection_string = "sqlite:///" + config.db_path init_db_engine(db_connection_string, False) load_plugins() upgrade() create_db() settings_manager = SettingsManager() tracker_manager = TrackersManager(settings_manager, get_plugins('tracker')) clients_manager = DbClientsManager(settings_manager, get_plugins('client')) notifier_manager = NotifierManager(settings_manager, get_plugins('notifier')) log_manager = ExecuteLogManager() engine_runner_logger = DbLoggerWrapper(log_manager, settings_manager) engine_runner = DBEngineRunner(engine_runner_logger, settings_manager, tracker_manager, clients_manager, notifier_manager) include_prerelease = settings_manager.get_new_version_check_include_prerelease() new_version_checker = NewVersionChecker(notifier_manager, include_prerelease) if settings_manager.get_is_new_version_checker_enabled(): # noinspection PyBroadException try: new_version_checker.execute() except: pass new_version_checker.start(settings_manager.new_version_check_interval) debug = config.debug if debug: secret_key = 'Secret!' token = 'monitorrent' else: secret_key = os.urandom(24) token = ''.join(random.choice(string.ascii_letters) for _ in range(8)) app = create_app(secret_key, token, tracker_manager, clients_manager, notifier_manager, settings_manager, engine_runner, log_manager, new_version_checker) server_start_params = (config.ip, config.port) server = wsgi.Server(server_start_params, app) print('Server started on {0}:{1}'.format(*server_start_params)) try: server.start() except KeyboardInterrupt: engine_runner.stop() server.stop()
class TrackersManagerTest(TestCase): def setUp(self): super(TrackersManagerTest, self).setUp() self.tracker1 = Tracker1() self.tracker2 = Tracker2() tracker_settings = TrackerSettings(10, None) settings_manager = Mock() settings_manager.tracker_settings = tracker_settings # noinspection PyTypeChecker self.trackers_manager = TrackersManager(settings_manager, OrderedDict(( (TRACKER1_PLUGIN_NAME, self.tracker1), (TRACKER2_PLUGIN_NAME, self.tracker2)) )) def test_get_settings(self): self.assertIsNone(self.trackers_manager.get_settings(TRACKER1_PLUGIN_NAME)) credentials2 = {'login': '******'} get_credentials_mock = MagicMock(return_value=credentials2) self.tracker2.get_credentials = get_credentials_mock self.assertEqual(self.trackers_manager.get_settings(TRACKER2_PLUGIN_NAME), credentials2) get_credentials_mock.assert_called_with() def test_set_settings(self): credentials1 = {'login': '******'} self.assertFalse(self.trackers_manager.set_settings(TRACKER1_PLUGIN_NAME, credentials1)) credentials2 = {'login': '******', 'password': '******'} update_credentials_mock2 = MagicMock() self.tracker2.update_credentials = update_credentials_mock2 self.assertTrue(self.trackers_manager.set_settings(TRACKER2_PLUGIN_NAME, credentials2)) update_credentials_mock2.assert_called_with(credentials2) def test_check_connection(self): self.assertFalse(self.trackers_manager.check_connection(TRACKER1_PLUGIN_NAME)) verify_mock = MagicMock(return_value=True) self.tracker2.verify = verify_mock self.assertTrue(self.trackers_manager.check_connection(TRACKER2_PLUGIN_NAME)) verify_mock.assert_called_with() def test_prepare_add_topic_1(self): parsed_url = {'display_name': "Some Name / Translated Name"} prepare_add_topic_mock1 = MagicMock(return_value=parsed_url) self.tracker1.prepare_add_topic = prepare_add_topic_mock1 result = self.trackers_manager.prepare_add_topic('http://tracker.com/1/') self.assertIsNotNone(result) prepare_add_topic_mock1.assert_called_with('http://tracker.com/1/') self.assertEqual(result, {'form': TrackerPluginBase.topic_form, 'settings': parsed_url}) def test_prepare_add_topic_2(self): prepare_add_topic_mock1 = MagicMock(return_value=None) self.tracker1.prepare_add_topic = prepare_add_topic_mock1 parsed_url = {'display_name': "Some Name / Translated Name"} prepare_add_topic_mock2 = MagicMock(return_value=parsed_url) self.tracker2.prepare_add_topic = prepare_add_topic_mock2 result = self.trackers_manager.prepare_add_topic('http://tracker.com/1/') self.assertIsNotNone(result) prepare_add_topic_mock1.assert_called_with('http://tracker.com/1/') prepare_add_topic_mock2.assert_called_with('http://tracker.com/1/') self.assertEqual(result, {'form': TrackerPluginBase.topic_form, 'settings': parsed_url}) def test_prepare_add_topic_3(self): prepare_add_topic_mock1 = MagicMock(return_value=None) self.tracker1.prepare_add_topic = prepare_add_topic_mock1 prepare_add_topic_mock2 = MagicMock(return_value=None) self.tracker2.prepare_add_topic = prepare_add_topic_mock2 result = self.trackers_manager.prepare_add_topic('http://tracker.com/1/') self.assertIsNone(result) prepare_add_topic_mock1.assert_called_with('http://tracker.com/1/') prepare_add_topic_mock2.assert_called_with('http://tracker.com/1/') def test_add_topic_1(self): can_parse_url_mock1 = MagicMock(return_value=True) add_topic_mock1 = MagicMock(return_value=True) self.tracker1.can_parse_url = can_parse_url_mock1 self.tracker1.add_topic = add_topic_mock1 params = {'display_name': "Some Name / Translated Name"} url = 'http://tracker.com/1/' self.assertTrue(self.trackers_manager.add_topic(url, params)) can_parse_url_mock1.assert_called_with(url) add_topic_mock1.assert_called_with(url, params) def test_add_topic_2(self): can_parse_url_mock1 = MagicMock(return_value=False) add_topic_mock1 = MagicMock(return_value=False) self.tracker1.can_parse_url = can_parse_url_mock1 self.tracker1.add_topic = add_topic_mock1 can_parse_url_mock2 = MagicMock(return_value=True) add_topic_mock2 = MagicMock(return_value=True) self.tracker2.can_parse_url = can_parse_url_mock2 self.tracker2.add_topic = add_topic_mock2 params = {'display_name': "Some Name / Translated Name"} url = 'http://tracker.com/1/' self.assertTrue(self.trackers_manager.add_topic(url, params)) can_parse_url_mock1.assert_called_with(url) add_topic_mock1.assert_not_called() can_parse_url_mock2.assert_called_with(url) add_topic_mock2.assert_called_with(url, params) def test_add_topic_3(self): can_parse_url_mock1 = MagicMock(return_value=False) add_topic_mock1 = MagicMock(return_value=False) self.tracker1.can_parse_url = can_parse_url_mock1 self.tracker1.add_topic = add_topic_mock1 can_parse_url_mock2 = MagicMock(return_value=False) add_topic_mock2 = MagicMock(return_value=False) self.tracker2.can_parse_url = can_parse_url_mock2 self.tracker2.add_topic = add_topic_mock2 params = {'display_name': "Some Name / Translated Name"} url = 'http://tracker.com/1/' self.assertFalse(self.trackers_manager.add_topic(url, params)) can_parse_url_mock1.assert_called_with(url) add_topic_mock1.assert_not_called() can_parse_url_mock2.assert_called_with(url) add_topic_mock2.assert_not_called()