from unittest.mock import patch import pytest from marshmallow import ValidationError from analytics.logic.account_top_content import get_top_content def test_get_account_top_content_requires_account_id(): with pytest.raises(ValidationError): get_top_content({"aggregation_type": "streams"}, {}) MOCK_TOP_CONTENT_ROWS = [ { "result": '{\n "TOPN_ARTISTS": [\n {\n "GLOBAL_PARTICIPANT_ID": "03f1db0c-be3c-4619-8491-bcb6d1288fb5",\n "VALUE": 22082366027\n }\n ],\n "TOPN_PRODUCTS": [\n {\n "PRODUCT_ID": 3191557,\n "VALUE": 9580398167\n }\n ],\n "TOPN_SONGS": [\n {\n "ISRC": "USQX91601347",\n "VALUE": 4198647216\n }\n ]\n,\n "TOPN_STORES": [\n {\n "STORE_ID": 286,\n "VALUE": 4297651896\n }\n ]\n}' # noqa } ] # noqa def test_get_account_products_default(): with patch( "analytics.logic.account_top_content.AccountTopContentAllTimeStreams.execute", return_value=MOCK_TOP_CONTENT_ROWS, ): top_content = get_top_content( {"account_id": 123, "aggregation_type": "streams"}, {} ) assert top_content.get("topn_artists") == [ { "global_participant_id": "03f1db0c-be3c-4619-8491-bcb6d1288fb5", "value": 22082366027, } ] assert top_content.get("topn_products") == [ { "product_id": 3191557, "value": 9580398167, } ] assert top_content.get("topn_songs") == [ { "isrc": "usqx91601347", "value": 4198647216, } ] assert top_content.get("topn_stores") == [ {"store_id": 286, "value": 4297651896} ]