"""Test for the owner model.""" import pytest from owsresponse import response from account.models import owner from tests.unit import db_operations @pytest.fixture def db_fixture(): """Set up the owner table.""" db_operations.create_tables() db_operations.seed_owner_table() def test_get_owner_success(db_fixture): """Test succeeds when owner exists in DB.""" response = owner.get_owner('TEST1') assert response def test_get_owner_fails_for_non_existent(db_fixture): """Test fails when owner does not exist.""" response = owner.get_owner('TEST100') assert response.status == 404 assert not response def test_get_owners_success(db_fixture): """Test get owners.""" expected = [{'owner_abbrivation': 'TEST1', 'owner_name': 'Test Owner Name 1'}] response = owner.get_owners() assert response assert response.message == expected assert response.status == 200 def test_is_sme(): """Test for different SME response values.""" success = response.Response({'gras_sender_name': 'present'}) fail_not_sme = response.Response({'gras_sender_name': ''}) fail_not_valid = response.Response({'not_a_field': 'the only field is not even valid'}) assert owner.is_sme(success) assert not owner.is_sme(fail_not_sme) assert not owner.is_sme(fail_not_valid)