"""Testing the UKPhysicalProductView.""" from collections import OrderedDict import pytest from reporting.models.uk_physical_product_view import UKPhysicalProductView def default_params(): """Get the default params.""" return { 'param_artist': [], 'param_inventory_data': True, 'param_product_name': [], 'param_product_status': '', 'param_product_type': [], 'param_sales_data': True, 'param_release_date': '', 'param_sub_label': [], 'param_vendor_id': [1], } def test_standard_query(): """Test get vendor by grass header account type vendor success.""" results = UKPhysicalProductView.all(default_params()) expected = OrderedDict() expected['Product Name'] = 'Product Name1' expected['Artist'] = 'Artist1' expected['Label Name'] = 'Label1' expected['Sub Label'] = 'SubLabel1' expected['Genre'] = 'Genre1' expected['Sub Genre'] = 'SubGenre1' expected['Product Code'] = 'ProductCode1' expected['UPC/EAN'] = '1' expected['Release Date'] = '2016-01-01' expected['Product Type'] = 'CD1' expected['Format'] = 'Album' expected['Units Per Set'] = 1 expected['Display Configuration'] = '1 x CD Album' expected['Exclusive'] = 'N' expected['On Hand'] = 0 expected['Available'] = 1 expected['Allocated'] = 1 expected['Faulty'] = 1 expected['Consignment'] = 1 content = results.message['content'] row = next(r for r in content if r['UPC/EAN'] == '1') assert row == expected assert len(content) == 2 def test_limit(): """Test limit.""" params = default_params() params['param_limit'] = 1 results = UKPhysicalProductView.all(params) assert len(results.message['content']) == 1 @pytest.mark.parametrize( 'param,column_name,value', [ ('param_artist', 'Artist', 'Artist2'), ('param_product_type', 'Product Type', 'CD2'), ('param_product_name', 'Product Name', 'Product Name2'), ('param_sub_label', 'Sub Label', 'SubLabel2'), ('param_release_date', 'Release Date', '2016-01-02'), ], ) def test_filters(param, column_name, value): """Test filters.""" params = default_params() params[param] = [value] results = UKPhysicalProductView.all(params) assert results.message['content'][0][column_name] == value assert len(results.message['content']) == 1 def test_vendor_id(): """Test vendor id.""" params = default_params() params['param_vendor_id'] = [2] results = UKPhysicalProductView.all(params) assert results.message['content'][0]['Artist'] == 'Artist3' assert len(results.message['content']) == 1 def test_get_filters(): """Test getting the filter values.""" results = UKPhysicalProductView.filter(1, None) assert results.message == { 'artist': ['Artist1', 'Artist2'], 'product_name': ['Product Name1', 'Product Name2'], 'product_type': ['CD1', 'CD2'], 'sub_label': ['SubLabel1', 'SubLabel2'], 'product_code': ['ProductCode1', 'ProductCode2'], 'upc_ean': ['1', '2'], }