import json import os import pytest from exp_manager_lambda import ExpDspConfig, ExpDspConfigError, get_config_from_file, group_records from exp_manager_lambda.entities import ReportType FIXTURES_PATH = os.path.join(os.path.dirname(__file__), "fixtures") @pytest.mark.parametrize( 'initial, expected', [ ( [ { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps( { 'Context': 'Trends_TopSong', "OptionalConfig": { 'RDS_SECRET_KEY': 'key1' } } ) }, { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps( { 'Context': 'Trends_TopSong1', "OptionalConfig": { 'RDS_SECRET_KEY': 'key1' } } ) }, { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps( { 'Context': 'Trends_TopSong2', "OptionalConfig": { 'RDS_SECRET_KEY': 'key2' } } ) }, ], [ [ { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps( { 'Context': 'Trends_TopSong', "OptionalConfig": { 'RDS_SECRET_KEY': 'key1' } } ) }, { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps( { 'Context': 'Trends_TopSong1', "OptionalConfig": { 'RDS_SECRET_KEY': 'key1' } } ) } ], [ { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps( { 'Context': 'Trends_TopSong2', "OptionalConfig": { 'RDS_SECRET_KEY': 'key2' } } ) } ], ], ), ( [ { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps({ 'Context': 'Trends_TopSong', }) }, { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps({ 'Context': 'Trends_TopSong1', }) }, { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps( { 'Context': 'Trends_TopSong2', "OptionalConfig": { 'RDS_SECRET_KEY': 'key2' } } ) }, ], [ [ { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps({ 'Context': 'Trends_TopSong', }) }, { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps({ 'Context': 'Trends_TopSong1', }) } ], [ { 'messageId': 'a23dcbb9-a010-4d69-9530-96a1cb04c9c7', 'body': json.dumps( { 'Context': 'Trends_TopSong2', "OptionalConfig": { 'RDS_SECRET_KEY': 'key2' } } ) } ], ], ), ] ) def test_group_records(initial, expected): actual = group_records(initial, "RDS_SECRET_KEY") assert actual == expected def test_get_config_correct(): filepath = os.path.join(FIXTURES_PATH, "exploration-dsp-config.json") actual = get_config_from_file(filepath) expected = { "apple": ExpDspConfig( process_all=False, report_types={ 'amNonRoyaltyStreams': ReportType(report_type='amNonRoyaltyStreams', versions=['v1']), 'amStreams': ReportType(report_type='amStreams', versions=['v1_2']), 'amContent': ReportType(report_type='amContent', versions=[]), 'amContentDemographics': ReportType(report_type='amContentDemographics', versions=[]) } ), "spotify": ExpDspConfig( process_all=False, report_types={ 'aggregatedstreams': ReportType(report_type='aggregatedstreams', versions=[]), 'streams': ReportType(report_type='streams', versions=['v4']), 'sub_30_sec_streams': ReportType(report_type='sub_30_sec_streams', versions=[]), 'tracks': ReportType(report_type='tracks', versions=[]), 'users': ReportType(report_type='users', versions=["v1"]) } ), "vevo": ExpDspConfig(process_all=True, report_types={}), } assert actual == expected def test_get_config_raise_err(): filepath = os.path.join(FIXTURES_PATH, "exploration-dsp-config-incorrect.json") with pytest.raises(ExpDspConfigError): get_config_from_file(filepath)