Esempio n. 1
0
    def test_download_info(self):
        url = 'http://www.lostfilm.tv/series/Grimm/seasons'
        tracker = LostFilmTVTracker(helper.real_session)
        tracker.tracker_settings = self.tracker_settings
        downloads = tracker.get_download_info(url, 160, 4, 22)

        assert len(downloads) == 3
        assert [LostFilmQuality.SD, LostFilmQuality.FullHD, LostFilmQuality.HD] == [d.quality for d in downloads]
    def test_login_failed_unknown_2(self):
        mock_tracker = LostFilmTVTracker()
        login_mock = Mock(side_effect=Exception)
        mock_tracker.login = login_mock
        self.plugin.tracker = mock_tracker
        self.plugin.update_credentials({'username': '******', 'password': '******'})
        self.assertEqual(self.plugin.login(), LoginResult.Unknown)

        login_mock.assert_called_with('monitorrent', 'monitorrent')
    def test_login_failed_unknown_2(self):
        mock_tracker = LostFilmTVTracker()
        login_mock = Mock(side_effect=Exception)
        mock_tracker.login = login_mock
        self.plugin.tracker = mock_tracker
        self.plugin.update_credentials({'username': '******', 'password': '******'})
        assert self.plugin.login() == LoginResult.Unknown

        login_mock.assert_called_with('monitorrent', 'monitorrent')
    def test_login_failed_incorrect_login_password(self):
        mock_tracker = LostFilmTVTracker()
        mock_tracker.tracker_settings = self.tracker_settings
        login_mock = Mock(side_effect=LostFilmTVLoginFailedException(6, 'incorrect login/password', ''))
        mock_tracker.login = login_mock
        self.plugin.tracker = mock_tracker
        self.plugin.update_credentials({'username': '******', 'password': '******'})
        self.assertEqual(self.plugin.login(), LoginResult.IncorrentLoginPassword)

        login_mock.assert_called_with('monitorrent', 'monitorrent')
    def test_login_failed_unknown_1(self):
        mock_tracker = LostFilmTVTracker()
        mock_tracker.tracker_settings = self.tracker_settings
        login_mock = Mock(side_effect=LostFilmTVLoginFailedException(1, 'temp_code', 'temp_message'))
        mock_tracker.login = login_mock
        self.plugin.tracker = mock_tracker
        self.plugin.update_credentials({'username': '******', 'password': '******'})
        self.assertEqual(self.plugin.login(), LoginResult.Unknown)

        login_mock.assert_called_with('monitorrent', 'monitorrent')
    def test_login_failed_incorrect_login_password(self):
        mock_tracker = LostFilmTVTracker()
        mock_tracker.tracker_settings = self.tracker_settings
        login_mock = Mock(side_effect=LostFilmTVLoginFailedException(3))
        mock_tracker.login = login_mock
        self.plugin.tracker = mock_tracker
        self.plugin.update_credentials({'username': '******', 'password': '******'})
        assert self.plugin.login() == LoginResult.IncorrentLoginPassword

        login_mock.assert_called_with('monitorrent', 'monitorrent')
    def test_login_success(self):
        mock_tracker = LostFilmTVTracker()
        mock_tracker.tracker_settings = self.tracker_settings
        mock_tracker.c_uid = '123456'
        login_mock = Mock()
        mock_tracker.login = login_mock
        self.plugin.tracker = mock_tracker
        self.plugin.update_credentials({'username': '******', 'password': '******'})
        assert self.plugin.login() == LoginResult.Ok

        login_mock.assert_called_with('monitorrent', 'monitorrent')
    def test_download_info(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=160'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        downloads = tracker.get_download_info(url, 4, 22)

        self.assertEqual(3, len(downloads))
        if PY3:
            # Python 3.4+
            self.assertCountEqual(['SD', '720p', '1080p'], [d['quality'] for d in downloads])
        else:
            # Python 2.7
            self.assertItemsEqual(['SD', '720p', '1080p'], [d['quality'] for d in downloads])
    def test_download_info(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=160'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        downloads = tracker.get_download_info(url, 4, 22)

        self.assertEqual(3, len(downloads))
        if PY3:
            # Python 3.4+
            self.assertCountEqual(['SD', '720p', '1080p'], [d['quality'] for d in downloads])
        else:
            # Python 2.7
            self.assertItemsEqual(['SD', '720p', '1080p'], [d['quality'] for d in downloads])
Esempio n. 10
0
    def test_download_info_2(self):
        url = 'http://www.lostfilm.tv/series/Eureka/seasons'
        tracker = LostFilmTVTracker(helper.real_session)
        tracker.tracker_settings = self.tracker_settings
        downloads_4_9 = tracker.get_download_info(url, 37, 4, 9)

        assert len(downloads_4_9) == 1
        assert downloads_4_9[0].quality == LostFilmQuality.SD

        downloads_4_10 = tracker.get_download_info(url, 37, 4, 10)

        assert len(downloads_4_10) == 2
        assert [d.quality for d in downloads_4_10] == [LostFilmQuality.SD, LostFilmQuality.HD]
    def test_login_failed_unknown_1(self):
        mock_tracker = LostFilmTVTracker()
        mock_tracker.tracker_settings = self.tracker_settings
        login_mock = Mock(side_effect=LostFilmTVLoginFailedException(
            1, 'temp_code', 'temp_message'))
        mock_tracker.login = login_mock
        self.plugin.tracker = mock_tracker
        self.plugin.update_credentials({
            'username': '******',
            'password': '******'
        })
        self.assertEqual(self.plugin.login(), LoginResult.Unknown)

        login_mock.assert_called_with('monitorrent', 'monitorrent')
    def test_download_info_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=37'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        downloads_4_9 = tracker.get_download_info(url, 4, 9)

        self.assertEqual(1, len(downloads_4_9))
        self.assertEqual('SD', downloads_4_9[0]['quality'])

        downloads_4_10 = tracker.get_download_info(url, 4, 10)

        self.assertEqual(2, len(downloads_4_10))
        if PY3:
            self.assertCountEqual(['SD', '720p'], [d['quality'] for d in downloads_4_10])
        else:
            self.assertItemsEqual(['SD', '720p'], [d['quality'] for d in downloads_4_10])
    def test_download_info_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=37'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        downloads_4_9 = tracker.get_download_info(url, 4, 9)

        self.assertEqual(1, len(downloads_4_9))
        self.assertEqual('SD', downloads_4_9[0]['quality'])

        downloads_4_10 = tracker.get_download_info(url, 4, 10)

        self.assertEqual(2, len(downloads_4_10))
        if PY3:
            self.assertCountEqual(['SD', '720p'], [d['quality'] for d in downloads_4_10])
        else:
            self.assertItemsEqual(['SD', '720p'], [d['quality'] for d in downloads_4_10])
 def test_parse_special_rss_title4(self):
     t1 = u'Люди (Humans). Эпизод 8 [WEBRip]. (S01E08)'
     parsed = LostFilmTVTracker.parse_rss_title(t1)
     self.assertEqual(u'Люди', parsed['name'])
     self.assertEqual(u'Humans', parsed['original_name'])
     self.assertEqual(u'Эпизод 8', parsed['title'])
     self.assertIsNone(parsed['original_title'])
     self.assertEqual(u'unknown', parsed['quality'])
     self.assertEqual(u'S01E08', parsed['episode_info'])
     self.assertEqual(1, parsed['season'])
     self.assertEqual(8, parsed['episode'])
 def test_parse_special_rss_title(self):
     t1 = u'Под куполом (Under the Dome). Идите дальше/А я останусь (Move On/But I\'m Not) [1080p]. (S03E01E02)'
     parsed = LostFilmTVTracker.parse_rss_title(t1)
     self.assertEqual(u'Под куполом', parsed['name'])
     self.assertEqual(u'Under the Dome', parsed['original_name'])
     self.assertEqual(u'Идите дальше/А я останусь', parsed['title'])
     self.assertEqual(u'Move On/But I\'m Not', parsed['original_title'])
     self.assertEqual(u'1080p', parsed['quality'])
     self.assertEqual(u'S03E01E02', parsed['episode_info'])
     self.assertEqual(3, parsed['season'])
     self.assertEqual(2, parsed['episode'])
 def test_parse_corrent_rss_title1(self):
     t1 = u'Мистер Робот (Mr. Robot). уя3вим0сти.wmv (3xpl0its.wmv). (S01E05)'
     parsed = LostFilmTVTracker.parse_rss_title(t1)
     self.assertEqual(u'Мистер Робот', parsed['name'])
     self.assertEqual(u'Mr. Robot', parsed['original_name'])
     self.assertEqual(u'уя3вим0сти.wmv', parsed['title'])
     self.assertEqual(u'3xpl0its.wmv', parsed['original_title'])
     self.assertEqual(u'SD', parsed['quality'])
     self.assertEqual(u'S01E05', parsed['episode_info'])
     self.assertEqual(1, parsed['season'])
     self.assertEqual(5, parsed['episode'])
 def test_parse_corrent_rss_title1(self):
     t1 = u'Мистер Робот (Mr. Robot). уя3вим0сти.wmv (3xpl0its.wmv). (S01E05)'
     parsed = LostFilmTVTracker.parse_rss_title(t1)
     self.assertEqual(u'Мистер Робот', parsed['name'])
     self.assertEqual(u'Mr. Robot', parsed['original_name'])
     self.assertEqual(u'уя3вим0сти.wmv', parsed['title'])
     self.assertEqual(u'3xpl0its.wmv', parsed['original_title'])
     self.assertEqual(u'SD', parsed['quality'])
     self.assertEqual(u'S01E05', parsed['episode_info'])
     self.assertEqual(1, parsed['season'])
     self.assertEqual(5, parsed['episode'])
 def test_parse_special_rss_title(self):
     t1 = u'Под куполом (Under the Dome). Идите дальше/А я останусь (Move On/But I\'m Not) [1080p]. (S03E01E02)'
     parsed = LostFilmTVTracker.parse_rss_title(t1)
     self.assertEqual(u'Под куполом', parsed['name'])
     self.assertEqual(u'Under the Dome', parsed['original_name'])
     self.assertEqual(u'Идите дальше/А я останусь', parsed['title'])
     self.assertEqual(u'Move On/But I\'m Not', parsed['original_title'])
     self.assertEqual(u'1080p', parsed['quality'])
     self.assertEqual(u'S03E01E02', parsed['episode_info'])
     self.assertEqual(3, parsed['season'])
     self.assertEqual(2, parsed['episode'])
 def test_parse_special_rss_title4(self):
     t1 = u'Люди (Humans). Эпизод 8 [WEBRip]. (S01E08)'
     parsed = LostFilmTVTracker.parse_rss_title(t1)
     self.assertEqual(u'Люди', parsed['name'])
     self.assertEqual(u'Humans', parsed['original_name'])
     self.assertEqual(u'Эпизод 8', parsed['title'])
     self.assertIsNone(parsed['original_title'])
     self.assertEqual(u'unknown', parsed['quality'])
     self.assertEqual(u'S01E08', parsed['episode_info'])
     self.assertEqual(1, parsed['season'])
     self.assertEqual(8, parsed['episode'])
    def test_login_success(self):
        mock_tracker = LostFilmTVTracker()
        mock_tracker.tracker_settings = self.tracker_settings
        mock_tracker.c_uid = '123456'
        mock_tracker.c_pass = '******'
        mock_tracker.c_uid = 'e9853fcd82cd46a5294349151700643e'
        login_mock = Mock()
        mock_tracker.login = login_mock
        self.plugin.tracker = mock_tracker
        self.plugin.update_credentials({
            'username': '******',
            'password': '******'
        })
        self.assertEqual(self.plugin.login(), LoginResult.Ok)

        login_mock.assert_called_with('monitorrent', 'monitorrent')
    def test_login_success(self):
        mock_tracker = LostFilmTVTracker()
        mock_tracker.tracker_settings = self.tracker_settings
        mock_tracker.c_uid = '123456'
        mock_tracker.c_pass = '******'
        mock_tracker.c_uid = 'e9853fcd82cd46a5294349151700643e'
        login_mock = Mock()
        mock_tracker.login = login_mock
        self.plugin.tracker = mock_tracker
        self.plugin.update_credentials({'username': '******', 'password': '******'})
        self.assertEqual(self.plugin.login(), LoginResult.Ok)

        login_mock.assert_called_with('monitorrent', 'monitorrent')
Esempio n. 22
0
    def test_parse_all_series(self):
        pytest.fail("This test need to be updated")

        error_hrefs = []
        lock = Lock()
        queue = Queue()
        tracker = LostFilmTVTracker()
        threads = []

        def process():
            while True:
                try:
                    url = queue.get(False)
                except Empty:
                    return
                try:
                    tracker.parse_url(url, True)
                except Exception:
                    with lock:
                        error_hrefs.append(url)

        all_series = requests.get('http://www.lostfilm.tv/serials.php')
        soup = get_soup(all_series.text, 'html5')

        mid = soup.find('div', class_='mid')
        series = mid.find_all('a', class_='bb_a')
        for s in series:
            queue.put('http://www.lostfilm.tv' + s.attrs['href'])

        for i in range(0, 20):
            t = Thread(target=process)
            threads.append(t)
            t.start()

        for i in range(0, len(threads)):
            threads[i].join()

        for e in error_hrefs:
            print("Error parse: {0}".format(e))

        self.assertEqual(0, len(error_hrefs))
 def test_parse_correct_title_strange(self):
     title = LostFilmTVTracker._parse_title(u'Род человеческий')
     self.assertEqual(u'Род человеческий', title['original_name'])
Esempio n. 24
0
class TestLostFilmTracker(ReadContentMixin):
    def setup(self):
        self.tracker_settings = TrackerSettings(10, None)
        self.tracker = LostFilmTVTracker()
        self.tracker.tracker_settings = self.tracker_settings

    @helper.use_vcr()
    def test_login(self):
        self.tracker.login(helper.real_email, helper.real_password)
        assert self.tracker.session is not None

    @use_vcr()
    def test_fail_login(self):
        with pytest.raises(LostFilmTVLoginFailedException) as cm:
            self.tracker.login("*****@*****.**", "FAKE_PASSWORD")
        assert cm.value.code == 3

    @helper.use_vcr()
    def test_verify_success(self):
        tracker = LostFilmTVTracker(helper.real_session)
        tracker.tracker_settings = self.tracker_settings
        assert tracker.verify()

    def test_verify_false(self):
        assert not self.tracker.verify()

    @use_vcr()
    def test_verify_fail(self):
        tracker = LostFilmTVTracker("1234567890abcdefghjklmnopqrstuvuywxyz")
        tracker.tracker_settings = self.tracker_settings
        assert not tracker.verify()

    @pytest.mark.parametrize(
        'url, value',
        [('http://www.lostfilm.tv/series/12_Monkeys/seasons', True),
         ('http://www.lostfilm.tv/series/12_Monkeys/bombolaya', True),
         ('http://www.lostfilm.tv/series/12_Monkeys', True),
         ('http://www.lostfilm.tv/my.php', False)])
    def test_can_parse_url(self, url, value):
        assert self.tracker.can_parse_url(url) == value

    @use_vcr()
    def test_parse_correct_url_success(self):
        title = self.tracker.parse_url(
            'http://www.lostfilm.tv/series/12_Monkeys')
        assert title.russian_name == u'12 обезьян'
        assert title.original_name == u'12 Monkeys'
        assert title.seasons_url == 'https://www.lostfilm.tv/series/12_Monkeys/seasons'

    @use_vcr()
    def test_parse_https_url_success(self):
        title = self.tracker.parse_url(
            'https://www.lostfilm.tv/series/12_Monkeys')
        assert title.russian_name == u'12 обезьян'
        assert title.original_name == u'12 Monkeys'
        assert title.seasons_url == 'https://www.lostfilm.tv/series/12_Monkeys/seasons'

    @use_vcr()
    def test_parse_correct_url_issue_22_1(self):
        title = self.tracker.parse_url(
            'http://www.lostfilm.tv/series/The_Vampire_Diaries')
        assert title.russian_name == u'Дневники вампира'
        assert title.original_name == u'The Vampire Diaries'

    @use_vcr()
    def test_parse_correct_url_issue_22_2(self):
        title = self.tracker.parse_url('http://www.lostfilm.tv/series/Grimm')
        assert title.russian_name == u'Гримм'
        assert title.original_name == u'Grimm'
        assert title.seasons_url == 'https://www.lostfilm.tv/series/Grimm/seasons'

    @use_vcr()
    def test_parse_incorrect_url_1(self):
        url = 'http://www.lostfilm.tv/not_a_series/SuperSeries'
        assert self.tracker.parse_url(url) is None

    @use_vcr()
    def test_parse_incorrect_url_2(self):
        url = 'http://www.lostfilm.tv/series/UnknowSeries'
        resp = self.tracker.parse_url(url)
        assert resp is not None
        assert resp.status_code == 200

    @use_vcr()
    def test_parse_series_success(self):
        url = 'http://www.lostfilm.tv/series/Grimm'
        show = self.tracker.parse_url(url, True)
        assert show.cat == 160
        assert show.url_name == 'Grimm'
        assert show.russian_name == u'Гримм'
        assert show.original_name == u'Grimm'
        assert len(show) == 6
        assert len(show[6]) == 13
        assert len(show[5]) == 22
        assert len(show[4]) == 22
        assert len(show[3]) == 22
        assert len(show[2]) == 22
        assert len(show[1]) == 22

    @use_vcr()
    def test_parse_series_success_2(self):
        url = 'http://www.lostfilm.tv/series/Sherlock/news'
        show = self.tracker.parse_url(url, True)
        assert show.cat == 130
        assert show.url_name == 'Sherlock'
        assert show.russian_name == u'Шерлок'
        assert show.original_name == u'Sherlock'
        assert len(show) == 5
        assert len(show[4]) == 3
        assert len(show[3]) == 3
        assert len(show[2]) == 3
        assert len(show[1]) == 3
        assert len(show[SpecialSeasons.Additional]) == 1

    @use_vcr()
    def test_parse_series_success_3(self):
        url = 'http://www.lostfilm.tv/series/Castle/video'
        show = self.tracker.parse_url(url, True)
        assert show.cat == 129
        assert show.russian_name == u'Касл'
        assert show.original_name == u'Castle'
        assert len(show) == 8
        assert len(show[8]) == 22
        assert len(show[7]) == 23
        assert len(show[6]) == 23
        assert len(show[5]) == 24
        assert len(show[4]) == 23
        assert len(show[3]) == 24
        assert len(show[2]) == 24
        assert len(show[1]) == 10

    @use_vcr()
    def test_parse_series_with_multiple_episodes_in_one_file(self):
        # on old lostfilm is 1 and 2 episode in one file for 3 season of Under the Dome show
        url = 'http://www.lostfilm.tv/series/Under_the_Dome/cast'
        show = self.tracker.parse_url(url, True)
        assert show.cat == 186
        assert show.russian_name == u'Под куполом'
        assert show.original_name == u'Under the Dome'
        assert len(show) == 3
        assert len(show[3]) == 13
        assert len(show[2]) == 13
        assert len(show[1]) == 13

    @use_vcr()
    def test_parse_series_with_intermediate_seasons(self):
        # http://old.lostfilm.tv/browse.php?cat=40
        # On old site Farscape has only complete seasons and additional season 4.5 with 1 and 2 episodes in one file
        # On new site it show all episodes, but when you tries to download particular episode,
        # it downloads the whole season
        url = 'http://www.lostfilm.tv/series/Farscape/seasons'
        show = self.tracker.parse_url(url, True)
        assert show.cat == 40
        assert len(show) == 4
        # assert len(parsed_url['special_episodes']) == 1
        # assert parsed_url['special_episodes'][0]['season_info']) == (4, 5, 2)

    @pytest.mark.parametrize("info,result", [
        (u"Unknown", SpecialSeasons.Unknown),
        (u"Дополнительные материалы", SpecialSeasons.Additional),
        (u"1 сезон", 1),
        (u"5 сезон", 5),
        (u"12 сезон", 12),
        (u"1 сезон 1 серия", (1, 1)),
        (u"12 сезон 6 серия", (12, 6)),
    ])
    def test_parse_season_info(self, info, result):
        assert self.tracker._parse_season_info(info) == result

    @helper.use_vcr()
    def test_download_info(self):
        url = 'http://www.lostfilm.tv/series/Grimm/seasons'
        tracker = LostFilmTVTracker(helper.real_session)
        tracker.tracker_settings = self.tracker_settings
        downloads = tracker.get_download_info(url, 160, 4, 22)

        assert len(downloads) == 3
        assert [
            LostFilmQuality.SD, LostFilmQuality.FullHD, LostFilmQuality.HD
        ] == [d.quality for d in downloads]

    @helper.use_vcr()
    def test_download_info_2(self):
        url = 'http://www.lostfilm.tv/series/Eureka/seasons'
        tracker = LostFilmTVTracker(helper.real_session)
        tracker.tracker_settings = self.tracker_settings
        downloads_4_9 = tracker.get_download_info(url, 37, 4, 9)

        assert len(downloads_4_9) == 1
        assert downloads_4_9[0].quality == LostFilmQuality.SD

        downloads_4_10 = tracker.get_download_info(url, 37, 4, 10)

        assert len(downloads_4_10) == 2
        assert [d.quality for d in downloads_4_10
                ] == [LostFilmQuality.SD, LostFilmQuality.HD]

    def test_download_info_3(self):
        url = 'http://www.lostfilm.tv/path/WrongShow/seasons'
        tracker = LostFilmTVTracker(helper.real_session)
        tracker.tracker_settings = self.tracker_settings
        assert tracker.get_download_info(url, 2, 4, 9) is None

    def test_httpretty_login_success(self):
        with requests_mock.Mocker() as mocker:
            session = u'e76e71e0f32e65c2470e42016dbb785e'

            mocker.post(u'http://www.lostfilm.tv/ajaxik.php',
                        text=json.dumps({
                            "name": "fakelogin",
                            "success": True,
                            "result": "ok"
                        }),
                        status_code=200,
                        cookies={u"lf_session": session},
                        headers={'location': u'/'})

            self.tracker.login(u'fakelogin', u'p@$$w0rd')

            assert self.tracker.session == session

    def test_httpretty_unknown_login_failed(self):
        """
        :type mocker: requests_mock.Mocker
        """
        with requests_mock.Mocker() as mocker:
            session = u'e76e71e0f32e65c2470e42016dbb785e'

            mocker.post(u'http://www.lostfilm.tv/ajaxik.php',
                        text=json.dumps({
                            "error": 4,
                            "result": "ok"
                        }),
                        status_code=500,
                        cookies={u"lf_session": session},
                        headers={'location': u'/'})

            with pytest.raises(LostFilmTVLoginFailedException) as cm:
                self.tracker.login(u'fakelogin', u'p@$$w0rd')
            assert cm.value.code == 4
 def test_verify(self):
     tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
     tracker.tracker_settings = self.tracker_settings
     self.assertTrue(tracker.verify())
 def test_verify_fail(self):
     tracker = LostFilmTVTracker("457686", '1'*32, '2'*32)
     tracker.tracker_settings = self.tracker_settings
     self.assertFalse(tracker.verify())
 def test_parse_correct_title_strange(self):
     title = LostFilmTVTracker._parse_title(u'Род человеческий')
     self.assertEqual(u'Род человеческий', title['original_name'])
class LostFilmTrackerTest(ReadContentMixin, TestCase):
    def setUp(self):
        self.tracker_settings = TrackerSettings(10)
        self.tracker = LostFilmTVTracker()
        self.tracker.tracker_settings = self.tracker_settings
        super(LostFilmTrackerTest, self).setUp()

    @helper.use_vcr()
    def test_login(self):
        self.tracker.login(helper.real_login, helper.real_password)
        self.assertTrue((self.tracker.c_uid == helper.real_uid) or (self.tracker.c_uid == helper.fake_uid))
        self.assertTrue((self.tracker.c_pass == helper.real_pass) or (self.tracker.c_pass == helper.fake_pass))
        self.assertTrue((self.tracker.c_usess == helper.real_usess) or (self.tracker.c_usess == helper.fake_usess))

    @use_vcr()
    def test_fail_login(self):
        with self.assertRaises(LostFilmTVLoginFailedException) as cm:
            self.tracker.login("admin", "FAKE_PASSWORD")
        self.assertEqual(cm.exception.code, 6)
        self.assertEqual(cm.exception.text, u'incorrect login/password')
        self.assertEqual(cm.exception.message, u'Не удалось войти. Возможно не правильный логин/пароль')

    @helper.use_vcr()
    def test_verify(self):
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        self.assertTrue(tracker.verify())

    def test_verify_false(self):
        self.assertFalse(self.tracker.verify())

    @use_vcr()
    def test_verify_fail(self):
        tracker = LostFilmTVTracker("457686", '1'*32, '2'*32)
        tracker.tracker_settings = self.tracker_settings
        self.assertFalse(tracker.verify())

    def test_parse_correct_title(self):
        title = LostFilmTVTracker._parse_title(u'Род человеческий (Extant)')
        self.assertEqual(u'Род человеческий', title['name'])
        self.assertEqual(u'Extant', title['original_name'])

    def test_parse_correct_title_strange(self):
        title = LostFilmTVTracker._parse_title(u'Род человеческий')
        self.assertEqual(u'Род человеческий', title['original_name'])

    @data(('http://www.lostfilm.tv/browse.php?cat=236', True),
          ('http://www.lostfilm.tv/my.php', False))
    @unpack
    def test_can_parse_url(self, url, value):
        self.assertEqual(value, self.tracker.can_parse_url(url))

    @use_vcr()
    def test_parse_correct_url(self):
        title = self.tracker.parse_url('http://www.lostfilm.tv/browse.php?cat=236')
        self.assertEqual(u'12 обезьян', title['name'])
        self.assertEqual(u'12 Monkeys', title['original_name'])

    @use_vcr()
    def test_parse_correct_url_issue_22_1(self):
        title = self.tracker.parse_url('http://www.lostfilm.tv/browse.php?cat=114')
        self.assertEqual(u'Дневники вампира', title['name'])
        self.assertEqual(u'The Vampire Diaries', title['original_name'])

    @use_vcr()
    def test_parse_correct_url_issue_22_2(self):
        title = self.tracker.parse_url('http://www.lostfilm.tv/browse.php?cat=160')
        self.assertEqual(u'Гримм', title['name'])
        self.assertEqual(u'Grimm', title['original_name'])

    @use_vcr()
    def test_parse_incorrect_url_1(self):
        url = 'http://www.lostfilm.tv/browse_wrong.php?cat=236'
        self.assertIsNone(self.tracker.parse_url(url))

    @use_vcr()
    def test_parse_incorrect_url_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=2'
        resp = self.tracker.parse_url(url)
        self.assertIsNotNone(resp)
        self.assertNotEqual(resp.status_code, 200)

    @use_vcr()
    def test_parse_series(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=160'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(160, parsed_url['cat'])
        self.assertEqual(u'Гримм', parsed_url['name'])
        self.assertEqual(u'Grimm', parsed_url['original_name'])
        self.assertEqual(88, len(parsed_url['episodes']))
        self.assertEqual(4, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_without_original_name(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=129'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(129, parsed_url['cat'])
        self.assertEqual(u'Касл', parsed_url['name'])
        self.assertEqual(u'Castle', parsed_url['original_name'])
        self.assertEqual(119, len(parsed_url['episodes']))
        self.assertEqual(7, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_without_original_name_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=134'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(134, parsed_url['cat'])
        self.assertEqual(u'Ходячие мертвецы', parsed_url['name'])
        self.assertEqual(u'The Walking Dead', parsed_url['original_name'])
        self.assertEqual(67, len(parsed_url['episodes']))
        self.assertEqual(5, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_without_original_name_3(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=247'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(247, parsed_url['cat'])
        self.assertEqual(u'Люди', parsed_url['name'])
        self.assertEqual(u'Humans', parsed_url['original_name'])
        self.assertEqual(8, len(parsed_url['episodes']))
        self.assertEqual(1, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_with_multiple_episodes_in_one_file(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=186'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(186, parsed_url['cat'])
        self.assertEqual(u'Под куполом', parsed_url['name'])
        self.assertEqual(u'Under the Dome', parsed_url['original_name'])
        self.assertEqual(39, len(parsed_url['episodes']))
        self.assertEqual(2, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_with_intermediate_seasons(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=40'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(40, parsed_url['cat'])
        self.assertEqual(0, len(parsed_url['episodes']))
        self.assertEqual(1, len(parsed_url['special_episodes']))
        self.assertEqual((4, 5, 2), parsed_url['special_episodes'][0]['season_info'])
        self.assertEqual(4, len(parsed_url['complete_seasons']))
        self.assertEqual(0, len(parsed_url['special_complete_seasons']))

    @httpretty.activate
    def test_parse_series_with_intermediate_seasons_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=40'

        httpretty.HTTPretty.allow_net_connect = False
        content = self.read_httpretty_content('browse.php_cat-40(Farscape).fake_intermediate_season.html',
                                              encoding='utf-8')
        httpretty.register_uri(httpretty.GET, re.compile(re.escape(url)), body=content, match_querystring=True)

        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(40, parsed_url['cat'])
        self.assertEqual(0, len(parsed_url['episodes']))
        self.assertEqual(0, len(parsed_url['special_episodes']))
        self.assertEqual(4, len(parsed_url['complete_seasons']))
        self.assertEqual(1, len(parsed_url['special_complete_seasons']))
        self.assertEqual((4, 5), parsed_url['special_complete_seasons'][0]['season_info'])

    @use_vcr()
    def test_parse_series_special_serires_1(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=112'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(112, parsed_url['cat'])
        self.assertEqual(30, len(parsed_url['episodes']))
        self.assertEqual(3, len(parsed_url['complete_seasons']))

    @helper.use_vcr()
    def test_download_info(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=160'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        downloads = tracker.get_download_info(url, 4, 22)

        self.assertEqual(3, len(downloads))
        if PY3:
            # Python 3.4+
            self.assertCountEqual(['SD', '720p', '1080p'], [d['quality'] for d in downloads])
        else:
            # Python 2.7
            self.assertItemsEqual(['SD', '720p', '1080p'], [d['quality'] for d in downloads])

    @helper.use_vcr()
    def test_download_info_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=37'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        downloads_4_9 = tracker.get_download_info(url, 4, 9)

        self.assertEqual(1, len(downloads_4_9))
        self.assertEqual('SD', downloads_4_9[0]['quality'])

        downloads_4_10 = tracker.get_download_info(url, 4, 10)

        self.assertEqual(2, len(downloads_4_10))
        if PY3:
            self.assertCountEqual(['SD', '720p'], [d['quality'] for d in downloads_4_10])
        else:
            self.assertItemsEqual(['SD', '720p'], [d['quality'] for d in downloads_4_10])

    def test_download_info_3(self):
        url = 'http://www.lostfilm.tv/browse_wrong.php?cat=2'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        self.assertIsNone(tracker.get_download_info(url, 4, 9))

    def test_parse_corrent_rss_title0(self):
        t1 = u'Мистер Робот (Mr. Robot). уя3вим0сти.wmv (3xpl0its.wmv) [MP4]. (S01E05)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Мистер Робот', parsed['name'])
        self.assertEqual(u'Mr. Robot', parsed['original_name'])
        self.assertEqual(u'уя3вим0сти.wmv', parsed['title'])
        self.assertEqual(u'3xpl0its.wmv', parsed['original_title'])
        self.assertEqual(u'720p', parsed['quality'])
        self.assertEqual(u'S01E05', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(5, parsed['episode'])

    def test_parse_corrent_rss_title1(self):
        t1 = u'Мистер Робот (Mr. Robot). уя3вим0сти.wmv (3xpl0its.wmv). (S01E05)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Мистер Робот', parsed['name'])
        self.assertEqual(u'Mr. Robot', parsed['original_name'])
        self.assertEqual(u'уя3вим0сти.wmv', parsed['title'])
        self.assertEqual(u'3xpl0its.wmv', parsed['original_title'])
        self.assertEqual(u'SD', parsed['quality'])
        self.assertEqual(u'S01E05', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(5, parsed['episode'])

    @data(u'Мистер Робот (Mr. Robot. уя3вим0сти.wmv (3xpl0its.wmv). (S01E05)',
          u'Мистер Робот (Mr. Robot). уя3вим0сти.wmv (3xpl0its.wmv). (S01E)')
    def test_parse_incorrent_rss_title1(self, title):
        self.assertIsNone(LostFilmTVTracker.parse_rss_title(title))

    def test_parse_special_rss_title(self):
        t1 = u'Под куполом (Under the Dome). Идите дальше/А я останусь (Move On/But I\'m Not) [1080p]. (S03E01E02)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Под куполом', parsed['name'])
        self.assertEqual(u'Under the Dome', parsed['original_name'])
        self.assertEqual(u'Идите дальше/А я останусь', parsed['title'])
        self.assertEqual(u'Move On/But I\'m Not', parsed['original_title'])
        self.assertEqual(u'1080p', parsed['quality'])
        self.assertEqual(u'S03E01E02', parsed['episode_info'])
        self.assertEqual(3, parsed['season'])
        self.assertEqual(2, parsed['episode'])

    def test_parse_special_rss_title2(self):
        t1 = u'Люди (Humans). Эпизод 8 [MP4]. (S01E08)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Люди', parsed['name'])
        self.assertEqual(u'Humans', parsed['original_name'])
        self.assertEqual(u'Эпизод 8', parsed['title'])
        self.assertIsNone(parsed['original_title'])
        self.assertEqual(u'720p', parsed['quality'])
        self.assertEqual(u'S01E08', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(8, parsed['episode'])

    def test_parse_special_rss_title3(self):
        t1 = u'Люди (Humans). Эпизод 8. (S01E08)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Люди', parsed['name'])
        self.assertEqual(u'Humans', parsed['original_name'])
        self.assertEqual(u'Эпизод 8', parsed['title'])
        self.assertIsNone(parsed['original_title'])
        self.assertEqual(u'SD', parsed['quality'])
        self.assertEqual(u'S01E08', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(8, parsed['episode'])

    def test_parse_special_rss_title4(self):
        t1 = u'Люди (Humans). Эпизод 8 [WEBRip]. (S01E08)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Люди', parsed['name'])
        self.assertEqual(u'Humans', parsed['original_name'])
        self.assertEqual(u'Эпизод 8', parsed['title'])
        self.assertIsNone(parsed['original_title'])
        self.assertEqual(u'unknown', parsed['quality'])
        self.assertEqual(u'S01E08', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(8, parsed['episode'])

    @httpretty.activate
    def test_httpretty_login_success(self):
        uid = u'151548'
        pass_ = u'dd770c2445d297ed0aa192c153e5424c'
        usess = u'e76e71e0f32e65c2470e42016dbb785e'

        httpretty.HTTPretty.allow_net_connect = False
        httpretty.register_uri(httpretty.POST,
                               u'https://login1.bogi.ru/login.php?referer=https%3A%2F%2Fwww.lostfilm.tv%2F',
                               body=self.read_httpretty_content(u'test_lostfilmtracker.1.login1.bogi.ru.html',
                                                                encoding='utf-8'))

        # hack for pass multiple cookies
        httpretty.register_uri(httpretty.POST,
                               u'http://www.lostfilm.tv/blg.php?ref=random',
                               body='', status=302,
                               set_cookie=u"uid={0}\r\n"
                                          u"Set-Cookie: pass={1}".format(uid, pass_),
                               location=u'/')
        httpretty.register_uri(httpretty.GET, u'http://www.lostfilm.tv/my.php',
                               body=u'(usess={})'.format(usess))

        self.tracker.login(u'fakelogin', u'p@$$w0rd')

        self.assertEqual(self.tracker.c_uid, uid)
        self.assertEqual(self.tracker.c_pass, pass_)
        self.assertEqual(self.tracker.c_usess, usess)

    @httpretty.activate
    def test_httpretty_unknown_login_failed(self):
        httpretty.HTTPretty.allow_net_connect = False
        httpretty.register_uri(httpretty.POST,
                               u'https://login1.bogi.ru/login.php?referer=https%3A%2F%2Fwww.lostfilm.tv%2F',
                               body=self.read_httpretty_content(u'test_lostfilmtracker.1.login1.bogi.ru.html',
                                                                encoding='utf-8'))

        # hack for pass multiple cookies
        httpretty.register_uri(httpretty.POST,
                               u'http://www.lostfilm.tv/blg.php?ref=random',
                               body=u'Internal server error', status=500)

        with self.assertRaises(LostFilmTVLoginFailedException) as cm:
            self.tracker.login(u'fakelogin', u'p@$$w0rd')
        self.assertEqual(cm.exception.code, -2)
        self.assertIsNone(cm.exception.text)
        self.assertIsNone(cm.exception.message)

    @httpretty.activate
    def test_httpretty_unknown_login_failed_2(self):
        httpretty.HTTPretty.allow_net_connect = False
        httpretty.register_uri(httpretty.POST,
                               'https://login1.bogi.ru/login.php?referer=https%3A%2F%2Fwww.lostfilm.tv%2F',
                               body='', status=302,
                               location='http://some-error.url/error.php')
        httpretty.register_uri(httpretty.GET,
                               'http://some-error.url/error.php',
                               body='', status=200)

        with self.assertRaises(LostFilmTVLoginFailedException) as cm:
            self.tracker.login('fakelogin', 'p@$$w0rd')
        self.assertEqual(cm.exception.code, -1)
        self.assertIsNone(cm.exception.text)
        self.assertIsNone(cm.exception.message)
 def setUp(self):
     self.tracker_settings = TrackerSettings(10)
     self.tracker = LostFilmTVTracker()
     self.tracker.tracker_settings = self.tracker_settings
     super(LostFilmTrackerTest, self).setUp()
Esempio n. 30
0
 def test_verify_fail(self):
     tracker = LostFilmTVTracker("1234567890abcdefghjklmnopqrstuvuywxyz")
     tracker.tracker_settings = self.tracker_settings
     assert not tracker.verify()
 def test_download_info_3(self):
     url = 'http://www.lostfilm.tv/browse_wrong.php?cat=2'
     tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
     tracker.tracker_settings = self.tracker_settings
     self.assertIsNone(tracker.get_download_info(url, 4, 9))
 def setUp(self):
     self.tracker_settings = TrackerSettings(10)
     self.tracker = LostFilmTVTracker()
     self.tracker.tracker_settings = self.tracker_settings
     super(LostFilmTrackerTest, self).setUp()
class LostFilmTrackerTest(ReadContentMixin, TestCase):
    def setUp(self):
        self.tracker_settings = TrackerSettings(10)
        self.tracker = LostFilmTVTracker()
        self.tracker.tracker_settings = self.tracker_settings
        super(LostFilmTrackerTest, self).setUp()

    @helper.use_vcr()
    def test_login(self):
        self.tracker.login(helper.real_login, helper.real_password)
        self.assertTrue((self.tracker.c_uid == helper.real_uid) or (self.tracker.c_uid == helper.fake_uid))
        self.assertTrue((self.tracker.c_pass == helper.real_pass) or (self.tracker.c_pass == helper.fake_pass))
        self.assertTrue((self.tracker.c_usess == helper.real_usess) or (self.tracker.c_usess == helper.fake_usess))

    @use_vcr()
    def test_fail_login(self):
        with self.assertRaises(LostFilmTVLoginFailedException) as cm:
            self.tracker.login("admin", "FAKE_PASSWORD")
        self.assertEqual(cm.exception.code, 6)
        self.assertEqual(cm.exception.text, u'incorrect login/password')
        self.assertEqual(cm.exception.message, u'Не удалось войти. Возможно не правильный логин/пароль')

    @helper.use_vcr()
    def test_verify(self):
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        self.assertTrue(tracker.verify())

    def test_verify_false(self):
        self.assertFalse(self.tracker.verify())

    @use_vcr()
    def test_verify_fail(self):
        tracker = LostFilmTVTracker("457686", '1'*32, '2'*32)
        tracker.tracker_settings = self.tracker_settings
        self.assertFalse(tracker.verify())

    def test_parse_correct_title(self):
        title = LostFilmTVTracker._parse_title(u'Род человеческий (Extant)')
        self.assertEqual(u'Род человеческий', title['name'])
        self.assertEqual(u'Extant', title['original_name'])

    def test_parse_correct_title_strange(self):
        title = LostFilmTVTracker._parse_title(u'Род человеческий')
        self.assertEqual(u'Род человеческий', title['original_name'])

    @data(('http://www.lostfilm.tv/browse.php?cat=236', True),
          ('http://www.lostfilm.tv/my.php', False))
    @unpack
    def test_can_parse_url(self, url, value):
        self.assertEqual(value, self.tracker.can_parse_url(url))

    @use_vcr()
    def test_parse_correct_url(self):
        title = self.tracker.parse_url('http://www.lostfilm.tv/browse.php?cat=236')
        self.assertEqual(u'12 обезьян', title['name'])
        self.assertEqual(u'12 Monkeys', title['original_name'])

    @use_vcr()
    def test_parse_correct_url_issue_22_1(self):
        title = self.tracker.parse_url('http://www.lostfilm.tv/browse.php?cat=114')
        self.assertEqual(u'Дневники вампира', title['name'])
        self.assertEqual(u'The Vampire Diaries', title['original_name'])

    @use_vcr()
    def test_parse_correct_url_issue_22_2(self):
        title = self.tracker.parse_url('http://www.lostfilm.tv/browse.php?cat=160')
        self.assertEqual(u'Гримм', title['name'])
        self.assertEqual(u'Grimm', title['original_name'])

    @use_vcr()
    def test_parse_incorrect_url_1(self):
        url = 'http://www.lostfilm.tv/browse_wrong.php?cat=236'
        self.assertIsNone(self.tracker.parse_url(url))

    @use_vcr()
    def test_parse_incorrect_url_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=2'
        resp = self.tracker.parse_url(url)
        self.assertIsNotNone(resp)
        self.assertNotEqual(resp.status_code, 200)

    @use_vcr()
    def test_parse_series(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=160'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(160, parsed_url['cat'])
        self.assertEqual(u'Гримм', parsed_url['name'])
        self.assertEqual(u'Grimm', parsed_url['original_name'])
        self.assertEqual(88, len(parsed_url['episodes']))
        self.assertEqual(4, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_without_original_name(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=129'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(129, parsed_url['cat'])
        self.assertEqual(u'Касл', parsed_url['name'])
        self.assertEqual(u'Castle', parsed_url['original_name'])
        self.assertEqual(119, len(parsed_url['episodes']))
        self.assertEqual(7, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_without_original_name_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=134'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(134, parsed_url['cat'])
        self.assertEqual(u'Ходячие мертвецы', parsed_url['name'])
        self.assertEqual(u'The Walking Dead', parsed_url['original_name'])
        self.assertEqual(67, len(parsed_url['episodes']))
        self.assertEqual(5, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_without_original_name_3(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=247'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(247, parsed_url['cat'])
        self.assertEqual(u'Люди', parsed_url['name'])
        self.assertEqual(u'Humans', parsed_url['original_name'])
        self.assertEqual(8, len(parsed_url['episodes']))
        self.assertEqual(1, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_with_multiple_episodes_in_one_file(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=186'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(186, parsed_url['cat'])
        self.assertEqual(u'Под куполом', parsed_url['name'])
        self.assertEqual(u'Under the Dome', parsed_url['original_name'])
        self.assertEqual(39, len(parsed_url['episodes']))
        self.assertEqual(2, len(parsed_url['complete_seasons']))

    @use_vcr()
    def test_parse_series_with_intermediate_seasons(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=40'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(40, parsed_url['cat'])
        self.assertEqual(0, len(parsed_url['episodes']))
        self.assertEqual(1, len(parsed_url['special_episodes']))
        self.assertEqual((4, 5, 2), parsed_url['special_episodes'][0]['season_info'])
        self.assertEqual(4, len(parsed_url['complete_seasons']))
        self.assertEqual(0, len(parsed_url['special_complete_seasons']))

    @httpretty.activate
    def test_parse_series_with_intermediate_seasons_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=40'

        httpretty.HTTPretty.allow_net_connect = False
        content = self.read_httpretty_content('browse.php_cat-40(Farscape).fake_intermediate_season.html',
                                              encoding='utf-8')
        httpretty.register_uri(httpretty.GET, re.compile(re.escape(url)), body=content, match_querystring=True)

        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(40, parsed_url['cat'])
        self.assertEqual(0, len(parsed_url['episodes']))
        self.assertEqual(0, len(parsed_url['special_episodes']))
        self.assertEqual(4, len(parsed_url['complete_seasons']))
        self.assertEqual(1, len(parsed_url['special_complete_seasons']))
        self.assertEqual((4, 5), parsed_url['special_complete_seasons'][0]['season_info'])

    @use_vcr()
    def test_parse_series_special_serires_1(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=112'
        parsed_url = self.tracker.parse_url(url, True)
        self.assertEqual(112, parsed_url['cat'])
        self.assertEqual(30, len(parsed_url['episodes']))
        self.assertEqual(3, len(parsed_url['complete_seasons']))

    @helper.use_vcr()
    def test_download_info(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=160'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        downloads = tracker.get_download_info(url, 4, 22)

        self.assertEqual(3, len(downloads))
        if PY3:
            # Python 3.4+
            self.assertCountEqual(['SD', '720p', '1080p'], [d['quality'] for d in downloads])
        else:
            # Python 2.7
            self.assertItemsEqual(['SD', '720p', '1080p'], [d['quality'] for d in downloads])

    @helper.use_vcr()
    def test_download_info_2(self):
        url = 'http://www.lostfilm.tv/browse.php?cat=37'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        downloads_4_9 = tracker.get_download_info(url, 4, 9)

        self.assertEqual(1, len(downloads_4_9))
        self.assertEqual('SD', downloads_4_9[0]['quality'])

        downloads_4_10 = tracker.get_download_info(url, 4, 10)

        self.assertEqual(2, len(downloads_4_10))
        if PY3:
            self.assertCountEqual(['SD', '720p'], [d['quality'] for d in downloads_4_10])
        else:
            self.assertItemsEqual(['SD', '720p'], [d['quality'] for d in downloads_4_10])

    def test_download_info_3(self):
        url = 'http://www.lostfilm.tv/browse_wrong.php?cat=2'
        tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
        tracker.tracker_settings = self.tracker_settings
        self.assertIsNone(tracker.get_download_info(url, 4, 9))

    def test_parse_corrent_rss_title0(self):
        t1 = u'Мистер Робот (Mr. Robot). уя3вим0сти.wmv (3xpl0its.wmv) [MP4]. (S01E05)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Мистер Робот', parsed['name'])
        self.assertEqual(u'Mr. Robot', parsed['original_name'])
        self.assertEqual(u'уя3вим0сти.wmv', parsed['title'])
        self.assertEqual(u'3xpl0its.wmv', parsed['original_title'])
        self.assertEqual(u'720p', parsed['quality'])
        self.assertEqual(u'S01E05', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(5, parsed['episode'])

    def test_parse_corrent_rss_title1(self):
        t1 = u'Мистер Робот (Mr. Robot). уя3вим0сти.wmv (3xpl0its.wmv). (S01E05)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Мистер Робот', parsed['name'])
        self.assertEqual(u'Mr. Robot', parsed['original_name'])
        self.assertEqual(u'уя3вим0сти.wmv', parsed['title'])
        self.assertEqual(u'3xpl0its.wmv', parsed['original_title'])
        self.assertEqual(u'SD', parsed['quality'])
        self.assertEqual(u'S01E05', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(5, parsed['episode'])

    @data(u'Мистер Робот (Mr. Robot. уя3вим0сти.wmv (3xpl0its.wmv). (S01E05)',
          u'Мистер Робот (Mr. Robot). уя3вим0сти.wmv (3xpl0its.wmv). (S01E)')
    def test_parse_incorrent_rss_title1(self, title):
        self.assertIsNone(LostFilmTVTracker.parse_rss_title(title))

    def test_parse_special_rss_title(self):
        t1 = u'Под куполом (Under the Dome). Идите дальше/А я останусь (Move On/But I\'m Not) [1080p]. (S03E01E02)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Под куполом', parsed['name'])
        self.assertEqual(u'Under the Dome', parsed['original_name'])
        self.assertEqual(u'Идите дальше/А я останусь', parsed['title'])
        self.assertEqual(u'Move On/But I\'m Not', parsed['original_title'])
        self.assertEqual(u'1080p', parsed['quality'])
        self.assertEqual(u'S03E01E02', parsed['episode_info'])
        self.assertEqual(3, parsed['season'])
        self.assertEqual(2, parsed['episode'])

    def test_parse_special_rss_title2(self):
        t1 = u'Люди (Humans). Эпизод 8 [MP4]. (S01E08)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Люди', parsed['name'])
        self.assertEqual(u'Humans', parsed['original_name'])
        self.assertEqual(u'Эпизод 8', parsed['title'])
        self.assertIsNone(parsed['original_title'])
        self.assertEqual(u'720p', parsed['quality'])
        self.assertEqual(u'S01E08', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(8, parsed['episode'])

    def test_parse_special_rss_title3(self):
        t1 = u'Люди (Humans). Эпизод 8. (S01E08)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Люди', parsed['name'])
        self.assertEqual(u'Humans', parsed['original_name'])
        self.assertEqual(u'Эпизод 8', parsed['title'])
        self.assertIsNone(parsed['original_title'])
        self.assertEqual(u'SD', parsed['quality'])
        self.assertEqual(u'S01E08', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(8, parsed['episode'])

    def test_parse_special_rss_title4(self):
        t1 = u'Люди (Humans). Эпизод 8 [WEBRip]. (S01E08)'
        parsed = LostFilmTVTracker.parse_rss_title(t1)
        self.assertEqual(u'Люди', parsed['name'])
        self.assertEqual(u'Humans', parsed['original_name'])
        self.assertEqual(u'Эпизод 8', parsed['title'])
        self.assertIsNone(parsed['original_title'])
        self.assertEqual(u'unknown', parsed['quality'])
        self.assertEqual(u'S01E08', parsed['episode_info'])
        self.assertEqual(1, parsed['season'])
        self.assertEqual(8, parsed['episode'])

    @httpretty.activate
    def test_httpretty_login_success(self):
        uid = '151548'
        pass_ = 'dd770c2445d297ed0aa192c153e5424c'
        usess = 'e76e71e0f32e65c2470e42016dbb785e'

        httpretty.HTTPretty.allow_net_connect = False
        httpretty.register_uri(httpretty.POST,
                               'https://login1.bogi.ru/login.php?referer=https%3A%2F%2Fwww.lostfilm.tv%2F',
                               body=self.read_httpretty_content('test_lostfilmtracker.1.login1.bogi.ru.html'))

        # hack for pass multiple cookies
        httpretty.register_uri(httpretty.POST,
                               'http://www.lostfilm.tv/blg.php?ref=random',
                               body='', status=302,
                               set_cookie="uid={0}\r\n"
                                          "Set-Cookie: pass={1}".format(uid, pass_),
                               location='/')
        httpretty.register_uri(httpretty.GET, 'http://www.lostfilm.tv/my.php',
                               body='(usess={})'.format(usess))

        self.tracker.login('fakelogin', 'p@$$w0rd')

        self.assertEqual(self.tracker.c_uid, uid)
        self.assertEqual(self.tracker.c_pass, pass_)
        self.assertEqual(self.tracker.c_usess, usess)

    @httpretty.activate
    def test_httpretty_unknown_login_failed(self):
        httpretty.HTTPretty.allow_net_connect = False
        httpretty.register_uri(httpretty.POST,
                               'https://login1.bogi.ru/login.php?referer=https%3A%2F%2Fwww.lostfilm.tv%2F',
                               body=self.read_httpretty_content('test_lostfilmtracker.1.login1.bogi.ru.html'))

        # hack for pass multiple cookies
        httpretty.register_uri(httpretty.POST,
                               'http://www.lostfilm.tv/blg.php?ref=random',
                               body='Internal server error', status=500)

        with self.assertRaises(LostFilmTVLoginFailedException) as cm:
            self.tracker.login('fakelogin', 'p@$$w0rd')
        self.assertEqual(cm.exception.code, -2)
        self.assertIsNone(cm.exception.text)
        self.assertIsNone(cm.exception.message)

    @httpretty.activate
    def test_httpretty_unknown_login_failed_2(self):
        httpretty.HTTPretty.allow_net_connect = False
        httpretty.register_uri(httpretty.POST,
                               'https://login1.bogi.ru/login.php?referer=https%3A%2F%2Fwww.lostfilm.tv%2F',
                               body='', status=302,
                               location='http://some-error.url/error.php')
        httpretty.register_uri(httpretty.GET,
                               'http://some-error.url/error.php',
                               body='', status=200)

        with self.assertRaises(LostFilmTVLoginFailedException) as cm:
            self.tracker.login('fakelogin', 'p@$$w0rd')
        self.assertEqual(cm.exception.code, -1)
        self.assertIsNone(cm.exception.text)
        self.assertIsNone(cm.exception.message)
 def test_parse_incorrent_rss_title1(self, title):
     self.assertIsNone(LostFilmTVTracker.parse_rss_title(title))
 def test_verify(self):
     tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
     tracker.tracker_settings = self.tracker_settings
     self.assertTrue(tracker.verify())
Esempio n. 36
0
 def setup(self):
     self.tracker_settings = TrackerSettings(10, None)
     self.tracker = LostFilmTVTracker()
     self.tracker.tracker_settings = self.tracker_settings
 def test_parse_incorrent_rss_title1(self, title):
     self.assertIsNone(LostFilmTVTracker.parse_rss_title(title))
Esempio n. 38
0
 def test_verify_success(self):
     tracker = LostFilmTVTracker(helper.real_session)
     tracker.tracker_settings = self.tracker_settings
     assert tracker.verify()
 def test_download_info_3(self):
     url = 'http://www.lostfilm.tv/browse_wrong.php?cat=2'
     tracker = LostFilmTVTracker(helper.real_uid, helper.real_pass, helper.real_usess)
     tracker.tracker_settings = self.tracker_settings
     self.assertIsNone(tracker.get_download_info(url, 4, 9))
Esempio n. 40
0
 def test_download_info_3(self):
     url = 'http://www.lostfilm.tv/path/WrongShow/seasons'
     tracker = LostFilmTVTracker(helper.real_session)
     tracker.tracker_settings = self.tracker_settings
     assert tracker.get_download_info(url, 2, 4, 9) is None
 def test_verify_fail(self):
     tracker = LostFilmTVTracker("457686", '1'*32, '2'*32)
     tracker.tracker_settings = self.tracker_settings
     self.assertFalse(tracker.verify())