"""Integration tests for the placement endpoint. 'sound-recording//placement/'. """ import pytest from sound_recordings import config from tests.integration.request import request_get_cache class TestPlacement(object): """Test sound recording placement endpoint.""" @pytest.fixture def response_not_found(self, insights_employee_request_headers): """Response for a 404.""" return request_get_cache( config.PLACEMENT_URL.replace("", "someisrc").replace( "", "anonexistantplaylist" ), headers=insights_employee_request_headers, ) def test_not_found(self, response_not_found): """Test not found response.""" assert response_not_found.status_code == 404 @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "USA561156358" @pytest.fixture def playlist_id(self): """Mock playlist_id.""" return "0JpvR1nVBBSbHt6fN51mZn" @pytest.fixture def response_placement_found( self, isrc, playlist_id, insights_employee_request_headers ): """Placement found response.""" return request_get_cache( config.PLACEMENT_URL.replace("", isrc).replace( "", playlist_id ), headers=insights_employee_request_headers, ) @pytest.fixture def payload(self, response_placement_found): """Return payload.""" return response_placement_found.json() def test_succeeds(self, response_placement_found): """Test successful response.""" code = response_placement_found.status_code assert code == 200, "Reason: {}, URL: {}".format( response_placement_found.reason, response_placement_found.url ) @pytest.mark.parametrize( "placements_field", [ "storefront_placements", "previous_position", "added", "isrc", "streams", "playlist", "position", ], ) def test_returns_correct_fields(self, placements_field, payload): """Test contains PlacementSchema fields.""" assert placements_field in payload