"""Test for release_artist model.""" from product.connectors import mysql from product.constants import error from product.models import release_artist as release_artist_model from product.models.release_artist import ReleaseArtist from tests.factories.release_artist import ReleaseArtistFactory from tests.testutils import db product_id = 2 @db.test_schema def test_validate_artist_ids(): """Test validate_artist_ids with valid IDs.""" db.seed_models(ReleaseArtistFactory.build(release_artist_id=1)) db.seed_models(ReleaseArtistFactory.build(release_artist_id=2)) response = release_artist_model.validate_artist_ids(['1', '2']) assert response.status == 200 @db.test_schema def test_validate_artist_ids_invalid(): """Test validate_artist_ids when some ids are invalid.""" db.seed_models(ReleaseArtistFactory.build(release_artist_id=1)) db.seed_models(ReleaseArtistFactory.build(release_artist_id=2)) response = release_artist_model.validate_artist_ids(['1', '100', '2']) assert response.status == 400 assert response.errors['code'] == error.ERROR_CODE_INVALID_DATA @db.test_schema def test_get_artist_ids_for_product(test_product): """Test get_artist_ids_for_product with valid product id.""" db.seed_models(ReleaseArtistFactory.build(release_id=test_product)) db.seed_models(ReleaseArtistFactory.build( release_id=test_product, role='composer')) response_ids = release_artist_model.get_artist_ids_for_product( test_product) assert response_ids.status == 200 assert len(response_ids.message) == 2 @db.test_schema def test_get_artist_ids_for_product_no_artist(): """Test get_artist_ids_for_product that has no artists.""" response_ids = release_artist_model.get_artist_ids_for_product(100) assert response_ids.status == 200 assert len(response_ids.message) == 0 @db.test_schema def test_create_release_artist(): """Test successful creation of a release artist.""" values = { 'upc': 12345123451, 'role': 'bobby', 'release_id': product_id, 'artist_name': 'chunko', 'artist_info_id': 111, } result = release_artist_model.create(values) assert result.message == { 'id': 1, 'url': None, 'upc': 12345123451, 'role': 'bobby', 'release_id': product_id, 'artist_name': 'chunko', 'artist_info_id': 111, } @db.test_schema def test_update_release_artist(): """Test successful update of a release artist.""" initial_values = { 'upc': 12345123451, 'role': 'bobby', 'release_id': product_id, 'artist_name': 'chunko', } updated_values = {'artist_name': 'tinky'} release_artist_model.create(initial_values) result = release_artist_model.update(updated_values, product_id) assert result.message == { 'artist_name': 'tinky', } @db.test_schema def test_delete_release_artist(): """Test successful deletion of a release_artist.""" db.insert_release_artist() release_artist_model.delete(product_id) with mysql.db_session() as session: result = session.query(ReleaseArtist).all() assert result == [] @db.test_schema def test_get_release_artist(): """Test successful get of a release_artist.""" db.insert_release_artist() result = release_artist_model.get(product_id) assert result.message == { 'id': 1, 'role': 'performer', 'release_id': product_id, 'upc': 123456789, 'artist_name': 'Charlie', 'url': 'url', 'artist_info_id': 123, }