"""Test product preprocessing.""" import pytest from switchboard_consumer.logic.preprocessing.product import \ preprocess, preprocess_product_cline, preprocess_product_pline from tests.logic.preprocessing.conftest import \ product_with_tracks_and_no_publishers, \ product_with_tracks_and_publishers def test_preprocess_product_with_missing_cline_and_pline(): """Test product preprocessing with missing cLine and pLine.""" product = {} expected_product = { 'cLine': { 'cLineText': '', }, 'pLine': { 'pLineText': '' } } preprocess(product) assert product == expected_product def test_preprocess_product_with_publishers(): """Test product preprocessing with missing cLine and pLine.""" expected_product = { 'cLine': {'cLineText': ''}, 'pLine': {'pLineText': ''}, 'components': [{ 'sides': [{ 'productTracks': [ { 'track': { 'cLine': '', 'pLine': '', 'publishers': [ { 'name': 'Sony/ATV Melody', 'territoryCode': 'US' }, { 'name': 'EMI Blackwood Music, Inc.', 'territoryCode': 'US' } ] } } ] }] }] } preprocess(product_with_tracks_and_publishers) assert product_with_tracks_and_publishers == expected_product def test_preprocess_product_with_missing_publishers(): """Test product preprocessing with publishers.""" expected_product = { 'cLine': {'cLineText': ''}, 'pLine': {'pLineText': ''}, 'components': [{ 'sides': [{ 'productTracks': [ { 'track': { 'cLine': '', 'pLine': '', 'publishers': [] } } ] }] }] } preprocess(product_with_tracks_and_no_publishers) assert product_with_tracks_and_no_publishers == expected_product def test_preprocess_product_with_cline_and_pline(): """Test product preprocessing with cLine and pLine.""" product = { 'cLine': { 'cLineText': '(c) 2019 Vangelis' }, 'pLine': { 'pLineText': '(p) 2019 Vangelis' } } expected_product = { 'cLine': { 'cLineText': '2019 Vangelis' }, 'pLine': { 'pLineText': '2019 Vangelis' } } preprocess(product) assert product == expected_product @pytest.mark.parametrize('cline,expected', [ ('(c) 2019 Vangelis', '2019 Vangelis'), ('', ''), ]) def test_preprocess_product_cline(cline, expected): """Test product preprocessing cLine.""" product = { 'cLine': { 'cLineText': cline } } preprocess_product_cline(product) assert product['cLine']['cLineText'] == expected @pytest.mark.parametrize('pline,expected', [ ('(p) 2019 Vangelis', '2019 Vangelis'), ('', ''), ]) def test_preprocess_product_pline(pline, expected): """Test product preprocessing with pLine.""" product = { 'pLine': { 'pLineText': pline } } preprocess_product_pline(product) assert product['pLine']['pLineText'] == expected