# pylint: disable=unused-argument,protected-access import pytest from dae_apollo_api_scraper.exceptions import S3FileUploadException def test_s3_service__prepare_rows(s3_service, api_responce_test, payload_test): prepared_rows = s3_service._prepare_rows(api_responce_test.data) assert prepared_rows[0] == ['isrc', 'artistId', 'application'] assert len(prepared_rows) == len(api_responce_test.data) + 1 assert prepared_rows[3] == [ api_responce_test.data[2].isrc, api_responce_test.data[2].artistId, payload_test.application ] def test_s3_service__create_csv_content(s3_service, api_responce_test): csv_content = s3_service._create_csv_content(api_responce_test.data) assert isinstance(csv_content, str) def test_s3_service__prepare_upload_path(s3_service, payload_test): file_name = '26640_1618316450.csv' expected_path = 'starred_tracks/report_type=stream_milestones/version=v2/' \ f'report_date=2021-07-02/application=rti/{file_name}' assert s3_service._prepare_upload_path(file_name) == expected_path def test_s3_service_upload(s3_service, s3_client, api_responce_test): file_name = '26640_1618316450.csv' upload_path = s3_service._prepare_upload_path(file_name) csv_file_content = s3_service._create_csv_content(api_responce_test.data) result = s3_service._upload(upload_path, csv_file_content) assert result['ResponseMetadata']['HTTPStatusCode'] == 200 # assert result['ResponseMetadata']['HTTPHeaders']['content-length'] s3_service._bucket = 'unknown' with pytest.raises(S3FileUploadException): s3_service._upload(upload_path, csv_file_content)