"""Functional tests for updating publishing obligation for tracks in product. Test endpoint: PUT /product//tracks/publishing-obligation """ import json from oto import status as response_code from tests.testutils import db @db.test_schema_no_seed def test_put_product_tracks_pub_obl( mocker, client_update_product_tracks_pub_obl, tds_update_pub_obl_for_mech_admin): """Test publishing is successful.""" tds = tds_update_pub_obl_for_mech_admin db.merge_model_objects(tds['seed_data']) res = client_update_product_tracks_pub_obl( product_id=tds['product_id'], data=tds['request_data'], is_mech_admin=True) assert res.status_code == response_code.OK res_body = json.loads(res.data.decode()) tds['validate_response_message'](res_body) @db.test_schema_no_seed def test_put_product_tracks_pub_obl_field_null_allowed( mocker, client_update_product_tracks_pub_obl, track_factory): """Test null publishing obligation is allowed.""" seed = [] seed.append(track_factory(us_publishing_obligation='PublicDomain')) seed.append(track_factory()) db.merge_model_objects(seed) request_data = [ { 'tuid': 1, 'us_publishing_obligation': None, 'third_party_publisher': 'N', 'publisher_names': [] }, { 'tuid': 2, 'us_publishing_obligation': None, 'third_party_publisher': 'N', 'publisher_names': [] } ] res = client_update_product_tracks_pub_obl( product_id=1, data=request_data, is_mech_admin=True) assert res.status_code == response_code.OK res_body = json.loads(res.data.decode()) assert len(res_body['items']) == 2 for item in res_body['items']: assert item['us_publishing_obligation'] is None # This is returned as None when us_publishing_obligation is set to None assert item['third_party_publisher'] is None def test_put_product_tracks_pub_obl_no_additional_properties( mocker, client_update_product_tracks_pub_obl): """Test invalid publishing obligation isn't allowed.""" request_data = [ { 'tuid': 1, 'us_publishing_obligation': 'PublicDomain', 'track_name': 'Some track name 24' } ] res = client_update_product_tracks_pub_obl( product_id=1, data=request_data, is_mech_admin=True) assert res.status_code == response_code.BAD_REQUEST res_body = json.loads(res.data.decode()) assert res_body['message']['0'] == \ 'Additional properties are not allowed (\'track_name\' was unexpected)'