"""Testing the EUPointOfSaleByProductView.""" from collections import OrderedDict import pytest from reporting.models.eu_point_of_sale_by_product_view import ( EUPointOfSaleByProductView, ) def default_params(): """Get the default params.""" return { 'param_sub_label': [], 'param_vendor_id': [21989], 'param_subacct_id': [25037], 'param_first_day_of_release_week': ['2018-08-17'], } @pytest.mark.parametrize( 'feature_method, is_enabled', [ ('is_point_of_sale_price_columns_enabled', True), ('is_point_of_sale_price_columns_enabled', False), ], ) def test_standard_query(mock_feature_util, is_enabled): """Test the standard query.""" results = EUPointOfSaleByProductView.all(default_params()) expected = OrderedDict() expected['Product Name'] = 'Okemah and the Melody of Riot' expected['Artist'] = 'Son Volt' expected['Label Name'] = 'Transmit Sound' expected['Sub Label'] = 'Transmit Sound' expected['Genre'] = 'Rock' expected['Sub Genre'] = 'Americana' expected['Product Code'] = 'TS2019CD' expected['UPC/EAN'] = '752830541474' expected['Release Date'] = '2018-08-31' expected['Product Type'] = 'CD' expected['Format'] = 'Album' expected['Units Per Set'] = 2 expected['Display Configuration'] = '2 x CD Album' expected['Exclusive'] = 'N' expected['Exclusive For'] = '' expected['Aggregated Scans'] = 2 expected['All Time Scans'] = 12 if is_enabled: expected['Orchard Price'] = '12.00' expected['Wholesale Price'] = 0 fields = [ 'Product Name', 'Artist', 'Label Name', 'Sub Label', 'Genre', 'Sub Genre', 'Product Code', 'UPC/EAN', 'Release Date', 'Product Type', 'Format', 'Units Per Set', 'Display Configuration', 'Exclusive', 'Exclusive For', 'Scans by Weeks', 'Aggregated Scans', 'All Time Scans', ] if is_enabled: fields.extend(['Orchard Price', 'Wholesale Price']) for field in fields: if field != 'Scans by Weeks': results.message['content'][0][field] = expected[field] else: results.message['content'][0]['Scans by Weeks'][0]['Date'] = ( '2018-08-17' ) results.message['content'][0]['Scans by Weeks'][0][ 'Weekly Scans' ] = 2 assert len(results.message['content']) == 1 @pytest.mark.parametrize( 'feature_method, is_enabled', [ ('is_point_of_sale_price_columns_enabled', True), ('is_point_of_sale_price_columns_enabled', False), ], ) @pytest.mark.parametrize( 'param,column_name,value', [ ('param_artist', 'Artist', 'Son Volt'), ('param_product_type', 'Product Type', 'CD'), ( 'param_product_name', 'Product Name', 'Okemah and the Melody of Riot', ), ('param_sub_label', 'Sub Label', 'Transmit Sound'), ('param_release_date', 'Release Date', '2018-08-31'), ( 'param_first_day_of_release_week', 'First Day of Release Week', '2018-08-17', ), ], ) def test_filters(mock_feature_util, is_enabled, param, column_name, value): """Test filters.""" params = default_params() params[param] = [value] results = EUPointOfSaleByProductView.all(params) if column_name != 'First Day of Release Week': assert results.message['content'][0][column_name] == value assert ( results.message['content'][0]['Scans by Weeks'][0]['Date'] == '2018-08-17' ) assert len(results.message['content']) == 1 @pytest.mark.parametrize( 'feature_method, is_enabled', [ ('is_point_of_sale_price_columns_enabled', True), ('is_point_of_sale_price_columns_enabled', False), ], ) def test_multiple_release_weeks(mock_feature_util, is_enabled): """Test results if quering for 2 release weeks.""" params = default_params() params['param_first_day_of_release_week'] = ['2018-08-10', '2018-08-17'] results = EUPointOfSaleByProductView.all(params) assert ( results.message['content'][0]['Scans by Weeks'][0]['Date'] == '2018-08-10' ) assert ( results.message['content'][0]['Scans by Weeks'][0]['Weekly Scans'] == 1 ) assert ( results.message['content'][0]['Scans by Weeks'][1]['Date'] == '2018-08-17' ) assert ( results.message['content'][0]['Scans by Weeks'][1]['Weekly Scans'] == 2 ) assert results.message['content'][0]['Aggregated Scans'] == 3 assert len(results.message['content']) == 1 @pytest.mark.parametrize( 'feature_method, is_enabled', [ ('is_point_of_sale_price_columns_enabled', True), ('is_point_of_sale_price_columns_enabled', False), ], ) def test_only_max_first_day_of_release_week_by_default( mock_feature_util, is_enabled ): """Test the default request.""" params = default_params() del params['param_first_day_of_release_week'] results = EUPointOfSaleByProductView.all(params) assert ( results.message['content'][0]['Scans by Weeks'][0]['Date'] == '2018-08-17' ) assert len(results.message['content'][0]['Scans by Weeks']) == 1 @pytest.mark.parametrize( 'feature_method, is_enabled', [ ('is_point_of_sale_price_columns_enabled', True), ('is_point_of_sale_price_columns_enabled', False), ], ) def test_vendor_id(mock_feature_util, is_enabled): """Test vendor id.""" params = default_params() params['param_vendor_id'] = ['21989'] results = EUPointOfSaleByProductView.all(params) assert ( results.message['content'][0]['Product Name'] == 'Okemah and the Melody of Riot' ) assert len(results.message['content']) == 1 @pytest.mark.parametrize( 'feature_method, is_enabled', [ ('is_point_of_sale_price_columns_enabled', True), ('is_point_of_sale_price_columns_enabled', False), ], ) def test_subaccount_id(mock_feature_util, is_enabled): """Test vendor id.""" params = default_params() params['param_vendor_id'] = [21989] params['param_subacct_id'] = [25037] results = EUPointOfSaleByProductView.all(params) assert ( results.message['content'][0]['Product Name'] == 'Okemah and the Melody of Riot' ) assert len(results.message['content']) == 1 @pytest.mark.parametrize( 'feature_method, is_enabled', [ ('is_point_of_sale_price_columns_enabled', True), ('is_point_of_sale_price_columns_enabled', False), ], ) def test_get_filters(mock_feature_util, is_enabled): """Test getting the filter values.""" results = EUPointOfSaleByProductView.filter(21989, None) assert results.message == { 'sub_label': ['Transmit Sound'], 'product_type': ['CD'], 'product_name': ['Okemah and the Melody of Riot'], 'artist': ['Son Volt'], 'product_code': ['TS2019CD'], 'upc_ean': ['752830541474'], } @pytest.mark.parametrize( 'feature_method, is_enabled', [ ('is_point_of_sale_price_columns_enabled', True), ('is_point_of_sale_price_columns_enabled', False), ], ) def test_get_filters_with_subaccount(mock_feature_util, is_enabled): """Test getting the filter values with a sub-account.""" vendor_id = 21989 subaccount_id = 25037 results = EUPointOfSaleByProductView.filter(vendor_id, subaccount_id) assert results.message == { 'sub_label': ['Transmit Sound'], 'product_type': ['CD'], 'product_name': ['Okemah and the Melody of Riot'], 'artist': ['Son Volt'], 'product_code': ['TS2019CD'], 'upc_ean': ['752830541474'], }