Exemplo n.º 1
0
 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}
Exemplo n.º 2
0
    def test_execute_reset_status_and_download(self, download, torrent_mock):
        def download_func(request, **kwargs):
            self.assertEqual(12, kwargs['timeout'])
            response = Response()
            response._content = br"d9:"
            response.status_code = 200
            return response, request[1]

        engine_tracker, _, _, engine_downloads = self.create_engine_tracker()

        last_update = datetime.now(pytz.utc)
        engine_downloads.add_torrent.return_value = last_update
        download.side_effect = download_func
        torrent = torrent_mock.return_value
        torrent.info_hash = 'HASH1'

        with DBSession() as db:
            topic1 = self.ExecuteMockTopic(display_name='Russian / English',
                                           url='http://mocktracker2.com/1',
                                           additional_attribute='English',
                                           hash='OLDHASH',
                                           status=Status.Error)
            db.add(topic1)
            db.commit()
            topic1_id = topic1.id
            db.expunge_all()
        plugin = self.MockTrackerPlugin()
        plugin.init(TrackerSettings(12, None))
        plugin.execute(plugin.get_topics(None), engine_tracker)
        with DBSession() as db:
            topic = db.query(self.ExecuteMockTopic).filter(self.ExecuteMockTopic.id == topic1_id).first()
            self.assertEqual(topic.last_update, last_update)
            self.assertEqual(topic.status, Status.Ok)
            self.assertEqual(topic.hash, 'HASH1')
 def setUp(self):
     self.tracker_settings = TrackerSettings(10)
     self.plugin = UnionpeerOrgPlugin()
     self.plugin.init(self.tracker_settings)
     self.urls_to_check = [
         "http://unionpeer.org/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html"
     ]
Exemplo n.º 4
0
    def test_execute_and_download_html_should_failed(self, download, torrent_mock):
        def download_func(request, **kwargs):
            self.assertEqual(12, kwargs['timeout'])
            response = Response()
            response._content = "<html>HTML</html>"
            response.status_code = 200
            response.headers['content-type'] = 'text/html'
            return response, request[1]

        download.side_effect = download_func
        torrent = torrent_mock.return_value
        torrent.info_hash = 'OLDHASH'

        engine_tracker, _, _, engine_downloads = self.create_engine_tracker()

        topic1 = self.ExecuteMockTopic(display_name='Russian / English',
                                       url='http://mocktracker2.com/1',
                                       additional_attribute='English',
                                       hash='OLDHASH',
                                       status=Status.Ok)
        plugin = self.MockTrackerPlugin()
        plugin.check_changes = Mock(return_value=True)
        plugin.init(TrackerSettings(12, None))
        plugin.save_topic = Mock()
        plugin.execute([topic1], engine_tracker)

        plugin.check_changes.assert_called_once_with(topic1)
        download.assert_called_once_with(('http://mocktracker2.com/1', 'file.torrent'), proxies=ANY, timeout=ANY)
        engine_tracker.failed.assert_called_once()
        plugin.save_topic.assert_not_called()
Exemplo n.º 5
0
    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(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,
            })
Exemplo n.º 7
0
 def setUp(self):
     self.tracker_settings = TrackerSettings(10, None)
     self.tracker = FreeTorrentsOrgTracker()
     self.tracker.tracker_settings = self.tracker_settings
     self.helper = FreeTorrentsHelper()
     self.urls_to_check = [
         "http://free-torrents.org/forum/viewtopic.php?t=207456",
         "http://www.free-torrents.org/forum/viewtopic.php?t=207456"
     ]
    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):
     self.tracker_settings = TrackerSettings(10)
     self.tracker = RutrackerTracker()
     self.tracker.tracker_settings = self.tracker_settings
     self.helper = RutrackerHelper()
     self.urls_to_check = [
         "http://rutracker.org/forum/viewtopic.php?t=5062041",
         "http://www.rutracker.org/forum/viewtopic.php?t=5062041"
     ]
Exemplo n.º 10
0
 def setUp(self):
     super(NnmClubPluginTest, self).setUp()
     plugin_settings = TrackerSettings(10, None)
     self.plugin = NnmClubPlugin()
     self.plugin.init(plugin_settings)
     self.urls_to_check = [
         u"http://nnmclub.to/forum/viewtopic.php?t=409969",
         u"http://nnmclub.to/forum/viewtopic.php?t=409969"
     ]
Exemplo n.º 11
0
 def setUp(self):
     self.tracker_settings = TrackerSettings(10, None)
     self.tracker = TapochekNetTracker()
     self.tracker.tracker_settings = self.tracker_settings
     self.helper = TapochekHelper()
     self.urls_to_check = [
         "http://tapochek.net/viewtopic.php?t=140574",
         "http://www.tapochek.net/viewtopic.php?t=140574"
     ]
Exemplo n.º 12
0
 def setUp(self):
     super(RutrackerPluginTest, self).setUp()
     self.tracker_settings = TrackerSettings(10)
     self.plugin = RutrackerPlugin()
     self.plugin.init(self.tracker_settings)
     self.helper = RutrackerHelper()
     self.urls_to_check = [
         "http://rutracker.org/forum/viewtopic.php?t=5062041",
         "http://www.rutracker.org/forum/viewtopic.php?t=5062041"
     ]
 def setUp(self):
     super(FreeTorrentsPluginTest, self).setUp()
     plugin_settings = TrackerSettings(10)
     self.plugin = FreeTorrentsOrgPlugin()
     self.plugin.init(plugin_settings)
     self.helper = FreeTorrentsHelper()
     self.urls_to_check = [
         "http://free-torrents.org/forum/viewtopic.php?t=207456",
         "http://www.free-torrents.org/forum/viewtopic.php?t=207456"
     ]
Exemplo n.º 14
0
 def setUp(self):
     super(TapochekPluginTest, self).setUp()
     self.tracker_settings = TrackerSettings(10, None)
     self.plugin = TapochekNetPlugin()
     self.plugin.init(self.tracker_settings)
     self.helper = TapochekHelper()
     self.urls_to_check = [
         "http://tapochek.net/viewtopic.php?t=140574",
         "http://www.tapochek.net/viewtopic.php?t=140574"
     ]
 def setUp(self):
     self.tracker_settings = TrackerSettings(10, None)
     self.plugin = AnilibriaTvPlugin()
     self.plugin.init(self.tracker_settings)
     self.urls_ok = [
         "https://www.anilibria.tv/release/inuyashiki.html",
         "https://anilibria.tv/release/inuyashiki.html"
     ]
     self.urls_fail = [
         "https://wwwanilibria.tv/release/inuyashiki.html",
         "https://rutracker.org/forum/viewtopic.php?t=5501844"
     ]
    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))))
Exemplo n.º 17
0
    def test_execute_check_changes_false_should_stop_download_torrent(self, download):

        engine_tracker, _, _, engine_downloads = self.create_engine_tracker()

        topic1 = self.ExecuteMockTopic(display_name='Russian / English',
                                       url='http://mocktracker2.com/1',
                                       additional_attribute='English',
                                       hash='OLDHASH',
                                       status=Status.Error)
        plugin = self.MockTrackerPlugin()
        plugin.check_changes = Mock(return_value=False)
        plugin.init(TrackerSettings(12, None))
        plugin.execute([topic1], engine_tracker)

        plugin.check_changes.assert_called_once_with(topic1)
        download.assert_not_called()
Exemplo n.º 18
0
 def setUp(self):
     self.tracker_settings = TrackerSettings(10, None)
     self.tracker = AnilibriaTvTracker()
     self.tracker.tracker_settings = self.tracker_settings
     self.urls_to_parse = [
         "https://www.anilibria.tv/release/inuyashiki.html",
         "https://anilibria.tv/release/inuyashiki.html"
     ]
     self.urls_not_to_parse = [
         "https://wwwanilibria.tv/release/inuyashiki.html",
         "http://unionpeer/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html"
     ]
     self.urls_parse_failed = [
         "https://wwwanilibria.tv/release/inuyashiki.html",
         "http://unionpeer/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html",
         "https://www.anilibria.tv/release/notfound.html",
     ]
Exemplo n.º 19
0
 def setUp(self):
     self.tracker_settings = TrackerSettings(10)
     self.tracker = UnionpeerOrgTracker()
     self.tracker.tracker_settings = self.tracker_settings
     self.urls_to_parse = [
         "http://unionpeer.org/topic/1177708",
         "http://unionpeer.org/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html",
         "http://www.unionpeer.org/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html",
         "https://unionpeer.org/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html"
     ]
     self.urls_not_to_parse = [
         "http://rutracker.org/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html",
         "http://unionpeer/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html",
     ]
     self.urls_parse_failed = [
         "http://rutracker.org/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html",
         "http://unionpeer/topic/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html",
         "http://unionpeer.org/topic1/1177708-zvezdnie-voyni-voyni-klonov-star-wars-the-clone-wars.html",
     ]
Exemplo n.º 20
0
 def setup(self):
     self.tracker_settings = TrackerSettings(10, None)
     self.tracker = LostFilmTVTracker()
     self.tracker.tracker_settings = self.tracker_settings
Exemplo n.º 21
0
    def test_execute(self, download, torrent_mock):
        def download_func(request, **kwargs):
            self.assertEqual(12, kwargs['timeout'])
            response = Response()
            response._content = br"d9:"
            if request[0] == 'http://mocktracker.com/3':
                raise Exception("Some strange exception")
            if request[0] == 'http://mocktracker.com/4':
                response.status_code = 500
                return response, None
            response.status_code = 200
            return response, request[1]

        last_update = datetime.now(pytz.utc)

        engine_tracker, _, _, engine_downloads = self.create_engine_tracker()
        engine_downloads.add_torrent.return_value = last_update

        download.side_effect = download_func
        torrent = torrent_mock.return_value
        torrent.info_hash = 'HASH1'

        with DBSession() as db:
            topic1 = self.ExecuteMixinMockTopic(display_name='Russian / English',
                                                url='http://mocktracker.com/1',
                                                additional_attribute='English')
            topic2 = self.ExecuteMixinMockTopic(display_name='Russian 2 / English 2',
                                                url='http://mocktracker.com/2',
                                                additional_attribute='English 2',
                                                hash='HASH1')
            topic3 = self.ExecuteMixinMockTopic(display_name='Russian 3 / English 3',
                                                url='http://mocktracker.com/3',
                                                additional_attribute='English 3',
                                                hash='HASH2')
            topic4 = self.ExecuteMixinMockTopic(display_name='Russian 4 / English 4',
                                                url='http://mocktracker.com/4',
                                                additional_attribute='English 4',
                                                hash='HASH3')
            db.add(topic1)
            db.add(topic2)
            db.add(topic3)
            db.add(topic4)
            db.commit()
            topic1_id = topic1.id
            topic2_id = topic2.id
            topic3_id = topic3.id
            topic4_id = topic4.id
        plugin = MockTrackerPlugin()
        plugin.init(TrackerSettings(12, None))
        plugin.execute(plugin.get_topics(None), engine_tracker)
        with DBSession() as db:
            # was successfully updated
            topic = db.query(self.ExecuteMixinMockTopic).filter(self.ExecuteMixinMockTopic.id == topic1_id).first()
            self.assertEqual(topic.hash, torrent.info_hash)
            self.assertEqual(topic.last_update, last_update)
            self.assertEqual(topic.status, Status.Ok)

            # was not update updated because of not changed hash
            # so last_update wasn't changed as well and it was null
            topic = db.query(self.ExecuteMixinMockTopic).filter(self.ExecuteMixinMockTopic.id == topic2_id).first()
            self.assertEqual(topic.hash, torrent.info_hash)
            self.assertIsNone(topic.last_update)
            self.assertEqual(topic.status, Status.Ok)

            # was not updated because of exception
            topic = db.query(self.ExecuteMixinMockTopic).filter(self.ExecuteMixinMockTopic.id == topic3_id).first()
            self.assertEqual(topic.hash, 'HASH2')
            self.assertIsNone(topic.last_update)
            self.assertEqual(topic.status, Status.Ok)

            # was not updated because of status code
            topic = db.query(self.ExecuteMixinMockTopic).filter(self.ExecuteMixinMockTopic.id == topic4_id).first()
            self.assertEqual(topic.hash, 'HASH3')
            self.assertIsNone(topic.last_update)
            self.assertEqual(topic.status, Status.Ok)
Exemplo n.º 22
0
 def setUp(self):
     super(AnidubPluginTest, self).setUp()
     self.tracker_settings = TrackerSettings(10, None)
     self.plugin = AnidubPlugin()
     self.plugin.init(self.tracker_settings)
Exemplo n.º 23
0
 def setUp(self):
     super(EngineRunnerTest, self).setUp()
     self.trackers_manager = TrackersManager(TrackerSettings(10), {})
Exemplo n.º 24
0
    def test_execute(self, download, torrent_mock):
        def download_func(request, **kwargs):
            self.assertEqual(12, kwargs['timeout'])
            response = Response()
            response._content = br"d9:"
            if request[0] == 'http://mocktracker2.com/1':
                response.status_code = 302
                return response, None
            elif request[0] == 'http://mocktracker2.com/2':
                response.status_code = 500
                return response, None
            elif request[0] == 'http://mocktracker2.com/3':
                response.status_code = 444
                return response, None
            response.status_code = 200
            return response, request[1]

        last_update = datetime.now(pytz.utc)

        engine_tracker, _, _, engine_downloads = self.create_engine_tracker()

        engine_downloads.add_torrent.return_value = last_update

        download.side_effect = download_func
        torrent = torrent_mock.return_value
        torrent.info_hash = 'HASH1'

        with DBSession() as db:
            topic1 = self.ExecuteMockTopic(display_name='Russian / English',
                                           url='http://mocktracker2.com/1',
                                           additional_attribute='English')
            topic2 = self.ExecuteMockTopic(display_name='Russian 2 / English 2',
                                           url='http://mocktracker2.com/2',
                                           additional_attribute='English 2',
                                           hash='OldHash1')
            topic3 = self.ExecuteMockTopic(display_name='Russian 3 / English 3',
                                           url='http://mocktracker2.com/3',
                                           additional_attribute='English 3',
                                           hash='OldHash2')
            topic4 = self.ExecuteMockTopic(display_name='Russian 4 / English 4',
                                           url='http://mocktracker2.com/4',
                                           additional_attribute='English 4',
                                           hash='OldHash3')
            db.add(topic1)
            db.add(topic2)
            db.add(topic3)
            db.add(topic4)
            db.commit()
            topic1_id = topic1.id
            topic2_id = topic2.id
            topic3_id = topic3.id
            topic4_id = topic4.id
            db.expunge_all()
        plugin = self.MockTrackerPlugin()
        plugin.init(TrackerSettings(12, None))
        plugin.execute(plugin.get_topics(None), engine_tracker)
        with DBSession() as db:
            # Status code 302 update status to NotFound
            topic = db.query(self.ExecuteMockTopic).filter(self.ExecuteMockTopic.id == topic1_id).first()
            self.assertIsNone(topic.hash)
            self.assertIsNone(topic.last_update)
            self.assertEqual(topic.status, Status.NotFound)

            # Status code 500 update status to Error
            topic = db.query(self.ExecuteMockTopic).filter(self.ExecuteMockTopic.id == topic2_id).first()
            self.assertEqual(topic.hash, topic2.hash)
            self.assertIsNone(topic.last_update)
            self.assertEqual(topic.status, Status.Error)

            # Status code 444 is Unknow status
            topic = db.query(self.ExecuteMockTopic).filter(self.ExecuteMockTopic.id == topic3_id).first()
            self.assertEqual(topic.hash, topic3.hash)
            self.assertIsNone(topic.last_update)
            self.assertEqual(topic.status, Status.Unknown)

            # Status code 200 is Ok status
            topic = db.query(self.ExecuteMockTopic).filter(self.ExecuteMockTopic.id == topic4_id).first()
            self.assertEqual(topic.hash, 'HASH1')
            self.assertEqual(topic.last_update, last_update)
            self.assertEqual(topic.status, Status.Ok)
Exemplo n.º 25
0
 def setUp(self):
     super(DBExecuteEngineTest, self).setUp()
     self.trackers_manager = TrackersManager(TrackerSettings(10), {})
 def setUp(self):
     self.tracker_settings = TrackerSettings(10)
Exemplo n.º 27
0
 def trackers_manager_set_up(self):
     self.tracker_manager = TrackersManager(TrackerSettings(10))
Exemplo n.º 28
0
 def trackers_manager_set_up(self):
     self.tracker_manager = TrackersManager(
         TrackerSettings(10), {'test': TrackerCollectionTest.TestTracker()})
Exemplo n.º 29
0
 def setUp(self):
     super(RutorOrgTrackerTest, self).setUp()
     self.tracker_settings = TrackerSettings(10)
Exemplo n.º 30
0
 def setUp(self):
     super(TestLostFilmTrackerPlugin, self).setUp()
     self.tracker_settings = TrackerSettings(10, None)
     self.plugin = LostFilmPlugin()
     self.plugin.init(self.tracker_settings)