"""Testing territory model layer.""" from product_digital_marketing.models import territory from tests.unit.factories import territory_factory from tests.unit.test_utils import db def test_to_dict(): """Check that territory to_dict works .""" territory_obj = territory_factory.TerritoryFactory( name='Lego Island', category='continent' ) assert territory_obj.to_dict() == { 'name': 'Lego Island', 'id': territory_obj.pk, 'category': 'continent' } @db.test_schema def test_get_territories(): """Check that get territories works.""" territory_1 = territory_factory.TerritoryFactory( name='Lego Island', category='continent' ) territory_2 = territory_factory.TerritoryFactory( name='D\'ni', category='region' ) territory_3 = territory_factory.TerritoryFactory( name='Lumpy Space', category='region' ) db.seed_models([territory_1, territory_2, territory_3]) response = territory.get_territories() assert response assert response.message == { 'items': [ { 'name': 'Lego Island', 'id': territory_1.pk, 'category': 'continent' }, { 'name': 'D\'ni', 'id': territory_2.pk, 'category': 'region' }, { 'name': 'Lumpy Space', 'id': territory_3.pk, 'category': 'region' } ] } @db.test_schema def test_get_territories_not_found(): """Check that get territories fails with 404.""" response = territory.get_territories() assert not response assert response.status == 404