"""Tests for participants module.""" from analytics.schemas import participants def test_participant_metrics(): """Test that participant_metrics converts to JSON object.""" mock_model_response_message = { "metrics": [ { "id": "abce-1234-ghij-789", "streams_1_day": 20000, "growth_percentage_1_day": 0.1, "streams_7_days": 50000, "growth_percentage_7_days": 0.25, "streams_28_days": 80000, "growth_percentage_28_days": 0.5, "streams_all_time": 1000000, }, { "id": "mfhao-98732-cba-123", "streams_1_day": 100000, "growth_percentage_1_day": 0.01, "streams_7_days": 500000, "growth_percentage_7_days": 0.3, "streams_28_days": 600000, "growth_percentage_28_days": 0.08, "streams_all_time": 700000, }, ] } expected_result = { "metrics": [ { "id": "abce-1234-ghij-789", "streams_1_day": 20000, "growth_percentage_1_day": 0.1, "streams_7_days": 50000, "growth_percentage_7_days": 0.25, "streams_28_days": 80000, "growth_percentage_28_days": 0.5, "streams_all_time": 1000000, }, { "id": "mfhao-98732-cba-123", "streams_1_day": 100000, "growth_percentage_1_day": 0.01, "streams_7_days": 500000, "growth_percentage_7_days": 0.3, "streams_28_days": 600000, "growth_percentage_28_days": 0.08, "streams_all_time": 700000, }, ] } result = participants.ParticipantMetricsSchema().dump(mock_model_response_message) assert result == expected_result TRACK_STREAMS_ALL = [ { "date": "2021-01-16T00:00:00Z", "streams": 1000, "skip_rate": 0.325823532, "saves": 500, }, { "date": "2021-01-17T00:00:00Z", "streams": 500, "skip_rate": 0.2597351, "saves": 125, }, ] def test_participant_streams_all(): """Test that track_streams_all schema converts to JSON object.""" input_data = { "global_participant_id": "global_participant_id", "items": TRACK_STREAMS_ALL, } expected_result = { "global_participant_id": "global_participant_id", "items": TRACK_STREAMS_ALL, } result = participants.ParticipantStreamsAllSchema().dump(input_data) assert result == expected_result TRACK_STREAMS_STORE = [ { "id": 1, "name": "Apple Music", "items": [ { "date": "2021-01-16T00:00:00Z", "streams": 1000, "skip_rate": 0.325823532, "saves": 500, }, { "date": "2021-01-17T00:00:00Z", "streams": 500, "skip_rate": 0.2597351, "saves": 125, }, ], }, { "id": 286, "name": "Spotify", "items": [ { "date": "2021-01-16T00:00:00Z", "streams": 1500, "skip_rate": 0.421415667, "saves": 700, }, { "date": "2021-01-17T00:00:00Z", "streams": 300, "skip_rate": 0.1245356, "saves": 100, }, ], }, ] def test_participant_streams_store(): """Test that track_streams_store schema converts to JSON object.""" input_data = { "global_participant_id": "global_participant_id", "stores": TRACK_STREAMS_STORE, } expected_result = { "global_participant_id": "global_participant_id", "stores": TRACK_STREAMS_STORE, } result = participants.ParticipantStreamsStoreSchema().dump(input_data) assert result == expected_result