"""Unit tests for demographics Marhsmallow schemas.""" import pytest from sound_recordings.schemas.demographics import DemographicsSchema @pytest.fixture def sources(): """Test the sources.""" return [ {"id": 1, "name": "Apple Music", "error": {"code": "rubbish"}}, {"id": 286, "name": "Spotify"}, ] @pytest.fixture def demographics(): """Test demographics.""" return { "age": { "_17": 5214236, "_18_22": 18016044, "_23_27": 11165474, "_28_34": 5969109, "_35_44": 2942418, "_45_59": 1606414, "_60_": 436636, "UA": 77677, }, "gender": {"M": 8273548, "F": 34247706, "UG": 2906754}, } @pytest.fixture def payload(sources, demographics): """Return the complete payload.""" return {"isrc": "TEST", "sources": sources, "demographics": demographics} def test_demographics_schema(payload): """Top level marshaller test.""" result = DemographicsSchema().dump(payload) assert result == { "isrc": "TEST", "sources": [ {"id": 1, "name": "Apple Music", "error": {"code": "rubbish"}}, {"id": 286, "name": "Spotify"}, ], "demographics": { "age": { "_17": 5214236, "_18_22": 18016044, "_23_27": 11165474, "_28_34": 5969109, "_35_44": 2942418, "_45_59": 1606414, "_60_": 436636, "UA": 77677, }, "gender": {"M": 8273548, "F": 34247706, "UG": 2906754}, }, }