diff options
Diffstat (limited to '')
-rw-r--r-- | ctrack/organisations/tests/test_models.py | 21 | ||||
-rw-r--r-- | ctrack/users/tests/factories.py | 15 |
2 files changed, 29 insertions, 7 deletions
diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py index 460d3d7..d070a84 100644 --- a/ctrack/organisations/tests/test_models.py +++ b/ctrack/organisations/tests/test_models.py @@ -13,5 +13,26 @@ def test_organisation_get_absolute_url(org: Organisation): def test_create_organisation(addr: Address): Organisation(name="Big Bad OES Corporation", address=addr).save() + # The organisation is saved in the db assert Organisation.objects.get(name="Big Bad OES Corporation") + # The organisation has the correct address assert Organisation.objects.get(name="Big Bad OES Corporation").address.type.descriptor == "Primary Address" + + +def test_delete_organisation(org: Organisation): + orgs = Organisation.objects.all() + assert org in orgs + Organisation.delete(org) + # Assert that the record has been deleted + assert Organisation.objects.count() == 0 + + +def test_update_organisation(org: Organisation): + # Change the name of the organisation + org.name = "Tonkers Ltd" + # Get current value of line1 of the address + addr_line1 = org.address.line1 + org.save() + assert org.name == "Tonkers Ltd" + # Assert that the address hasn't changed + assert addr_line1 == org.address.line1 diff --git a/ctrack/users/tests/factories.py b/ctrack/users/tests/factories.py index 0a4acd6..9907945 100644 --- a/ctrack/users/tests/factories.py +++ b/ctrack/users/tests/factories.py @@ -5,13 +5,6 @@ from ctrack.organisations.models import Organisation, Address, AddressType from factory import DjangoModelFactory, Faker, post_generation, SubFactory -class OrganisationFactory(DjangoModelFactory): - name = Faker("company", locale="en_GB") - - class Meta: - model = Organisation - - class AddressTypeFactory(DjangoModelFactory): descriptor = "Primary Address" @@ -35,6 +28,14 @@ class AddressFactory(DjangoModelFactory): model = Address +class OrganisationFactory(DjangoModelFactory): + name = Faker("company", locale="en_GB") + address = SubFactory(AddressFactory) + + class Meta: + model = Organisation + + class UserFactory(DjangoModelFactory): username = Faker("user_name") email = Faker("email") |