"""Tests for top tracks endpoints.""" from unittest.mock import MagicMock from oto import response as oto_response from owsrequest import constants as owsrequest_constants from analytics.logic import top_tracks from tests.unit.fixtures import fixture_api def test_top_tracks(monkeypatch, headers): """Test /top_tracks with correct params.""" account_type = owsrequest_constants.GRASS_ACCOUNT_TYPE account_id = owsrequest_constants.GRASS_ACCOUNT_ID url = '/top-tracks/' get_top_tracks_mock = MagicMock(return_value=oto_response.Response( {'items': ['item1']})) monkeypatch.setattr(top_tracks, 'get_top_tracks', get_top_tracks_mock) response = fixture_api.CLIENT.get(url, headers=headers) get_top_tracks_mock.assert_called_with( headers[account_type], headers[account_id], 25) assert response.status_code == 200 def test_top_tracks_with_limit(monkeypatch, headers): """Test /top_tracks with correct params.""" account_type = owsrequest_constants.GRASS_ACCOUNT_TYPE account_id = owsrequest_constants.GRASS_ACCOUNT_ID url = '/top-tracks/?limit=10' get_top_tracks_mock = MagicMock(return_value=oto_response.Response( {'items': ['item1']})) monkeypatch.setattr(top_tracks, 'get_top_tracks', get_top_tracks_mock) response = fixture_api.CLIENT.get(url, headers=headers) get_top_tracks_mock.assert_called_with( headers[account_type], headers[account_id], 10) assert response.status_code == 200