From 63e4cef7d709a5af9bbbeb80fe77a93db7d80ace Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 11 Dec 2023 18:30:58 +0000 Subject: [PATCH] Initial commit --- .../__pycache__/downloader.cpython-311.pyc | Bin 0 -> 3717 bytes .../downloader/downloader.py | 61 ++++++ penny_dreadful_downloader/downloader/runtest | 2 + .../downloader/test_downloader.py | 175 ++++++++++++++++++ 4 files changed, 238 insertions(+) create mode 100644 penny_dreadful_downloader/downloader/__pycache__/downloader.cpython-311.pyc create mode 100755 penny_dreadful_downloader/downloader/downloader.py create mode 100755 penny_dreadful_downloader/downloader/runtest create mode 100644 penny_dreadful_downloader/downloader/test_downloader.py diff --git a/penny_dreadful_downloader/downloader/__pycache__/downloader.cpython-311.pyc b/penny_dreadful_downloader/downloader/__pycache__/downloader.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6c7da0e0262b60d3dd223abbd55343ce4dc394d2 GIT binary patch literal 3717 zcmb_f-%lIK9iROLw%2y~;TTgOfg}`60wy%1xl5En0=diO!bKs~DfH-S@ovDmwav{e zAy6Z^(mkLmx}sC0@X!bMbeH6mm#C`Rs87BBU>B_vYbB&eeY%&*Rr(O!Q@=B|*FQ)j zozyY&*_qj|XU3oJ=lh-EaVQi(P`*6zFHLJj=%2JxEqtZ%Y7-g{k%lzRKnvw3x4=Q4 zH~6%$AaF<%7DP?_94$zi1lXdr0JdtafIiI!=-2#!0WAP1YcgO^4{5Y2=jqG4UtV1|UDFRMn%-0&KTrkZLZ>1_cTB2)qD ztD681k;%cMQto(dje7*`r(S;xnNrmXp&YtHXJAF+AHffPS|t|Eqqs1)IkaM$tK{88 zd4tvcv3-vvv*`rURg#7MZ^|oX+8A3^G0|~cbbVO=Y)vO7afM~w#B>!`H1&HXFeR?4 z%Q~T3>i^+4{~wyP?0Uw?s+x|0Ds-Qi3d;|b90$mweYx}gc`G(; z%NHH_Vt!^{j_pSN*j>10%M*?~VTlv3zz!un8lgjf5~JUM#zRUaJj+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_number = downloader.get_season_number(mock_tag) + + self.assertEqual(season_number, expected_season_number) + + def test_get_season_number_returns_correct_number_when_single_digit_season(self): + expected_season_number = "7" + mock_soup = BeautifulSoup("

Season " + expected_season_number + " (RIX)

", "html.parser") + mock_tag = mock_soup.div + + season_number = downloader.get_season_number(mock_tag) + + self.assertEqual(season_number, expected_season_number) + + def test_get_season_cards_url_returns_correct_url_from_list(self): + expected_url = "TEST_SEASON_CARDS_URL" + mock_soup = BeautifulSoup('''

Season 23 (VOW)

''', "html.parser") + mock_tag = mock_soup.div + + season_url = downloader.get_season_cards_url(mock_tag) + + self.assertEqual(season_url, expected_url) + + def test_get_season_cards_url_returns_http_when_url_is_https(self): + expected_url = "http://pdmtgo.com/VOW_legal_cards.txt" + source_url = "https://pdmtgo.com/VOW_legal_cards.txt" + mock_soup = BeautifulSoup('''

Season 23 (VOW)

''', "html.parser") + mock_tag = mock_soup.div + + season_url = downloader.get_season_cards_url(mock_tag) + + self.assertEqual(season_url, expected_url) + + def test_get_seasons_returns_dictionary_of_season_to_url(self): + expected_season_number = "23" + expected_url = "TEST_SEASON_CARDS_URL" + mock_soup = BeautifulSoup('''

Season ''' + expected_season_number + ''' (VOW)

''', "html.parser") + + seasons_list = downloader.get_seasons(mock_soup) + + self.assertEqual(seasons_list, {expected_season_number: expected_url}) + + def test_download_season_lists_pulls_file_from_web(self): + expected_season_number = "23" + expected_url = "TEST_SEASON_CARDS_URL" + + test_cards = "CARDS CARDS MORE CARDS" + requests.get = Mock(return_value=get_mock_cards_response(test_cards)) + + downloader.download_season_lists({expected_season_number: expected_url}) + + requests.get.assert_called_once_with(expected_url) + + def test_download_season_lists_gets_all_files(self): + test_url_1 = "SEASON_23_URL" + test_url_2 = "SEASON_42_URL" + test_seasons = { + "23": test_url_1, + "42": test_url_2} + + test_cards = "CARDS CARDS MORE CARDS" + requests.get = Mock(return_value=get_mock_cards_response(test_cards)) + + downloader.download_season_lists(test_seasons) + + requests.get.assert_has_calls([call(test_url_1), call(test_url_2)]) + + def test_write_season_lists_writes_response_text_to_disk(self): + test_cards = "CARDS CARDS MORE CARDS" + test_responses = {"23": test_cards} + + open_mock = mock_open() + with unittest.mock.patch("builtins.open", open_mock): + downloader.write_season_lists(test_responses) + + handle = open_mock() + handle.write.assert_called_with(test_cards) + + def test_main_runs_program(self): + mock_soup = BeautifulSoup("", "html.parser") + downloader.download_seasons_html = Mock(return_value=mock_soup) + + mock_seasons = {"23": "URL"} + downloader.get_seasons = Mock(return_value=mock_seasons) + + mock_lists = {"23": "CARDS UPON CARDS"} + downloader.download_season_lists = Mock(return_value=mock_lists) + + # downloader.write_season_lists = Mock() # TODO: Find out why this causes the above test to fail + + with unittest.mock.patch("builtins.open", mock_open()): + downloader.main() + + downloader.download_seasons_html.assert_called_once() + downloader.get_seasons.assert_called_once_with(mock_soup) + downloader.download_season_lists.assert_called_once_with(mock_seasons) + # downloader.write_season_lists.assert_called_once_with(mock_lists) + +if __name__ == '__main__': + unittest.main()