"""Tests for Rights Attribute Logic.""" from backend.logic import rights_attribute as rights_attribute_logic def test_get_rights_attributes(mocker): """Test if generic get_rights_attributes works.""" mocker.patch( 'backend.models.rights_attribute_query.RightsAttributeQuery.get_rights_attributes', return_value=[ {'id': 1, 'description': 'Public Domain'}, {'id': 2, 'description': 'Compilations'}, {'id': 3, 'description': 'Various Artists'} ]) get_rights_attributes_response = rights_attribute_logic.get_rights_attributes() assert get_rights_attributes_response == [ {'id': 1, 'description': 'Public Domain'}, {'id': 2, 'description': 'Compilations'}, {'id': 3, 'description': 'Various Artists'} ] def test_get_tracks_rights_attribute(mocker): """Test if tuid specific get_track_rights_attributes works.""" mocker.patch('backend.models.rights_attribute_query.RightsAttributeQuery.get_track_rights_attributes', return_value=[{'rights_attribute_id': 1, 'description': 'Public Domain', 'track_rights_attribute_id': 1}]) get_track_rights_attributes_response = rights_attribute_logic.get_track_rights_attributes( 182) assert get_track_rights_attributes_response == [{'rights_attribute_id': 1, 'description': 'Public Domain', 'track_rights_attribute_id': 1}] def test_get_tracks_rights_attribute_edits(mocker): """Test if tuid specific get_track_rights_attributes_edits works.""" mocker.patch('backend.models.rights_attribute_query.RightsAttributeQuery.get_track_rights_attributes_edits', return_value=[{'rights_attribute_id': 1, 'description': 'Public Domain', 'track_rights_attribute_id': 1}]) get_track_rights_attributes_edits_response = rights_attribute_logic.get_track_rights_attributes_edits( 182) assert get_track_rights_attributes_edits_response == [{'rights_attribute_id': 1, 'description': 'Public Domain', 'track_rights_attribute_id': 1}] def test_sync_track_rights_attributes(mocker): """Test if update_track_rights_attributes works.""" mocker.patch( 'backend.models.track_rights_attribute_persister.TrackRightsAttributePersister.sync_track_rights_attributes', return_value=[ {'id': 1, 'unique_track_id': 182, 'rights_attribute_id': 3}, {'id': 2, 'unique_track_id': 182, 'rights_attribute_id': 1}, {'id': 3, 'unique_track_id': 182, 'rights_attribute_id': 2} ]) orchard_identity_id = 'uuid' tracks = [{'tuid': 182, 'track_atttributes': [1, 2, 3]}] sync_track_rights_attributes_response = rights_attribute_logic.update_track_rights_attributes( tracks, orchard_identity_id) assert sync_track_rights_attributes_response == [ {'id': 1, 'unique_track_id': 182, 'rights_attribute_id': 3}, {'id': 2, 'unique_track_id': 182, 'rights_attribute_id': 1}, {'id': 3, 'unique_track_id': 182, 'rights_attribute_id': 2} ]