"""Function test for get product.""" import json from ows_product_physical.constant import field from ows_product_physical.constant import header from ows_product_physical.constant import marketing from ows_product_physical.constant import service_name def test_get_product(client, valid_post_header, db_release_id, db_project_id, ows_request_mocker, db_with_data, db_releases, db_release_artist_names, db_product_physical, db_release_subgenre, feature_engine): """Test getting a product.""" product_description = 'some description' ows_request_mocker.add( { 'method': 'get', 'service': service_name.OWS_MARKETING, 'path': '/highlights/release/{}?mkt_program_id={}'.format( db_release_id, marketing.PROGRAM_MARKETING_HIGHLIGHTS), 'status': 200, 'json': { 'items': [{'description': product_description}] } }) ows_request_mocker.add({ 'method': 'head', 'service': service_name.OWS_PROJECT, 'path': '/ownership/{}/{}/project/{}'.format( valid_post_header[header.GRASS_ACCOUNT_TYPE], valid_post_header[header.GRASS_ACCOUNT_ID], db_project_id ), 'status': 200 }) ows_request_mocker.apply() client_response = client.get( '/product/{}'.format(db_release_id), headers=valid_post_header ) assert client_response.status_code == 200 actual_data = json.loads(client_response.data.decode('utf-8')) release_row = db_releases[0] prod_phys_row = db_product_physical[0] release_subgenre_row = db_release_subgenre[0] release_row.update({ field.COUNTRY_OF_ORIGIN: 3 }) expected_data = { # artists from release_artists 'primary_artist': ', '.join(db_release_artist_names), # subgenre from release_subgenre 'subgenre_id': release_subgenre_row['subgenre_id'], # description from microservice 'product_highlights': product_description, # upc-related fields from releases 'display_upc': release_row['display_upc'], 'upc': release_row['upc'], 'manufacturer_upc': release_row['manufacturer_upc'], # Fields from releases # Fields renamed from releases 'cline': release_row['c_line'], 'product_type': release_row['new_release'], 'product_name': release_row['release_name'], 'product_id': release_row['release_id'], # Fields copied through from releases 'version': release_row['version'], 'sale_start_date': release_row['sale_start_date'], 'distribution_format_id': release_row['distribution_format_id'], 'description': release_row['description'], 'project_id': release_row['project_id'], 'special_instructions': release_row['special_instructions'], 'release_date': release_row['release_date'], 'release_status': release_row['release_status'], 'subaccount_id': release_row['subaccount_id'], 'artist_id': release_row['artist_id'], 'label': release_row['label'], 'genre_id': release_row['genre_id'], 'product_code': release_row['product_code'], # Fields from product_physical # Fields renamed from product_physical 'artist_is_individual': prod_phys_row['individual'], # Fields copied through from product_physical 'box_lot': prod_phys_row['box_lot'], 'discount': prod_phys_row['discount'], 'end_date': prod_phys_row['end_date'], 'exclusive_for': prod_phys_row['exclusive_for'], 'explicit': prod_phys_row['explicit'], 'initial_stock': prod_phys_row['initial_stock'], 'manufacturing_obligation': prod_phys_row['manufacturing_obligation'], 'country_of_origin': release_row['country_of_origin'], 'packaging_id': prod_phys_row['packaging_id'], 'pline': prod_phys_row['pline'], 'pricing': prod_phys_row['pricing'], 'production_notes': prod_phys_row['production_notes'], 'units_per_set': prod_phys_row['units_per_set'], 'wholesale_price': prod_phys_row['wholesale_price'], 'display_configuration': prod_phys_row['display_configuration'], 'japan_distribution': prod_phys_row['japan_distribution'], 'edition': prod_phys_row['edition'] } assert actual_data == expected_data