diff --git a/tests/common.py b/tests/common.py index 0b4c199..00bdd42 100644 --- a/tests/common.py +++ b/tests/common.py @@ -48,23 +48,39 @@ def file_contents(filename): @pytest.fixture -def testdata_api_videos_response_file_contents(): - return file_contents("tests/testdata/api_videos_response.json") +def testdata_api_videos_response_page_1_of_2_file_contents(): + return file_contents("tests/testdata/api_videos_response_page_1_of_2.json") @pytest.fixture -def testdata_api_videos_response_json(testdata_api_videos_response_file_contents): - return json.loads(testdata_api_videos_response_file_contents) +def testdata_api_videos_response_page_1_of_2_json( + testdata_api_videos_response_page_1_of_2_file_contents, +): + return json.loads(testdata_api_videos_response_page_1_of_2_file_contents) @pytest.fixture -def testdata_api_videos_response_unicode_file_contents(): - return file_contents("tests/testdata/api_videos_response_unicode.json") +def testdata_api_videos_response_page_2_of_2_file_contents(): + return file_contents("tests/testdata/api_videos_response_page_2_of_2.json") @pytest.fixture -def testdata_api_videos_response_unicode_json(testdata_api_videos_response_unicode_file_contents): - return json.loads(testdata_api_videos_response_unicode_file_contents) +def testdata_api_videos_response_page_2_of_2_json( + testdata_api_videos_response_page_2_of_2_file_contents, +): + return json.loads(testdata_api_videos_response_page_2_of_2_file_contents) + + +@pytest.fixture +def testdata_api_videos_response_unicode_with_null_bytes_file_contents(): + return file_contents("tests/testdata/api_videos_response_unicode_with_null_bytes.json") + + +@pytest.fixture +def testdata_api_videos_response_unicode_with_null_bytes_json( + testdata_api_videos_response_unicode_with_null_bytes_file_contents, +): + return json.loads(testdata_api_videos_response_unicode_with_null_bytes_file_contents) @pytest.fixture diff --git a/tests/test_api_client.py b/tests/test_api_client.py index 978e756..ef5a1c4 100644 --- a/tests/test_api_client.py +++ b/tests/test_api_client.py @@ -414,7 +414,7 @@ def test_tiktok_request_client_removes_null_chars( basic_video_query, mocked_access_token_fetch, mocked_video_responses, - testdata_api_videos_response_unicode_json, + testdata_api_videos_response_unicode_with_null_bytes_json, ): request_client = api_client.TikTokApiRequestClient.from_credentials_file( FAKE_SECRETS_YAML_FILE, @@ -848,17 +848,19 @@ def test_TikTokVideoRequest_as_json(basic_video_query_config): } -def test_NullByteRemovingJSONDencoder(testdata_api_videos_response_unicode_file_contents): +def test_NullByteRemovingJSONDencoder( + testdata_api_videos_response_unicode_with_null_bytes_file_contents, +): assert ( "\x00" - in json.loads(testdata_api_videos_response_unicode_file_contents)["data"]["videos"][0][ - "username" - ] + in json.loads(testdata_api_videos_response_unicode_with_null_bytes_file_contents)["data"][ + "videos" + ][0]["username"] ) assert ( "\x00" not in json.loads( - testdata_api_videos_response_unicode_file_contents, + testdata_api_videos_response_unicode_with_null_bytes_file_contents, cls=api_client.NullByteRemovingJSONDencoder, )["data"]["videos"][0]["username"] ) diff --git a/tests/test_integration.py b/tests/test_integration.py index ce61763..87e234c 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -38,10 +38,12 @@ def mocked_access_token_responses(responses_mock): @pytest.fixture -def mocked_video_responses(responses_mock, testdata_api_videos_response_unicode_json): +def mocked_video_responses( + responses_mock, testdata_api_videos_response_unicode_with_null_bytes_json +): return responses_mock.post( re.compile("https://open.tiktokapis.com/v2/*"), - json=testdata_api_videos_response_unicode_json, + json=testdata_api_videos_response_unicode_with_null_bytes_json, ) @@ -49,7 +51,7 @@ def test_tiktok_request_client_removes_null_chars( basic_video_query, basic_video_query_config, basic_acquisition_config, - testdata_api_videos_response_unicode_json, + testdata_api_videos_response_unicode_with_null_bytes_json, test_database_engine, mocked_access_token_responses, mocked_video_responses, @@ -66,5 +68,5 @@ def test_tiktok_request_client_removes_null_chars( client.fetch_and_store_all(basic_video_query_config) with Session(test_database_engine) as session: assert session.scalars(select(Video.id).order_by(Video.id)).all() == [ - testdata_api_videos_response_unicode_json["data"]["videos"][0]["id"] + testdata_api_videos_response_unicode_with_null_bytes_json["data"]["videos"][0]["id"] ] diff --git a/tests/testdata/api_videos_response_unicode.json b/tests/testdata/api_videos_response_unicode_with_null_bytes.json similarity index 100% rename from tests/testdata/api_videos_response_unicode.json rename to tests/testdata/api_videos_response_unicode_with_null_bytes.json