aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-01-21 16:37:09 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-01-21 16:37:09 +0000
commit1aade17fe69e52973fd43c4090dbdfaf50009c89 (patch)
tree3efa176ff0ebd7d94b203a29b9a4e1bc401665ac
parent0bfe3454fde753425d37246b73b3eda1b9a756b9 (diff)
passing test - added address type model
Diffstat (limited to '')
-rw-r--r--ctrack/organisations/migrations/0004_auto_20200121_1027.py26
-rw-r--r--ctrack/organisations/migrations/0005_auto_20200121_1028.py19
-rw-r--r--ctrack/organisations/models.py5
-rw-r--r--ctrack/organisations/tests/test_models.py1
-rw-r--r--ctrack/users/tests/factories.py15
5 files changed, 62 insertions, 4 deletions
diff --git a/ctrack/organisations/migrations/0004_auto_20200121_1027.py b/ctrack/organisations/migrations/0004_auto_20200121_1027.py
new file mode 100644
index 0000000..a2e8dd1
--- /dev/null
+++ b/ctrack/organisations/migrations/0004_auto_20200121_1027.py
@@ -0,0 +1,26 @@
+# Generated by Django 2.2.9 on 2020-01-21 10:27
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('organisations', '0003_organisation_address'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='AddressType',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('descriptor', models.CharField(max_length=50)),
+ ],
+ ),
+ migrations.AddField(
+ model_name='address',
+ name='type',
+ field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='organisations.AddressType'),
+ ),
+ ]
diff --git a/ctrack/organisations/migrations/0005_auto_20200121_1028.py b/ctrack/organisations/migrations/0005_auto_20200121_1028.py
new file mode 100644
index 0000000..9ee8833
--- /dev/null
+++ b/ctrack/organisations/migrations/0005_auto_20200121_1028.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.2.9 on 2020-01-21 10:28
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('organisations', '0004_auto_20200121_1027'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='address',
+ name='type',
+ field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='organisations.AddressType'),
+ ),
+ ]
diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py
index 3ef794c..cf8e7de 100644
--- a/ctrack/organisations/models.py
+++ b/ctrack/organisations/models.py
@@ -5,7 +5,12 @@ from django.urls import reverse
from slugify import slugify
+class AddressType(models.Model):
+ descriptor = models.CharField(max_length=50)
+
+
class Address(models.Model):
+ type = models.ForeignKey(AddressType, on_delete=models.CASCADE, default=1)
line1 = models.CharField(max_length=255)
line2 = models.CharField(max_length=255)
line3 = models.CharField(max_length=255)
diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py
index b178508..460d3d7 100644
--- a/ctrack/organisations/tests/test_models.py
+++ b/ctrack/organisations/tests/test_models.py
@@ -14,3 +14,4 @@ def test_organisation_get_absolute_url(org: Organisation):
def test_create_organisation(addr: Address):
Organisation(name="Big Bad OES Corporation", address=addr).save()
assert Organisation.objects.get(name="Big Bad OES Corporation")
+ assert Organisation.objects.get(name="Big Bad OES Corporation").address.type.descriptor == "Primary Address"
diff --git a/ctrack/users/tests/factories.py b/ctrack/users/tests/factories.py
index 6c5c7cd..0a4acd6 100644
--- a/ctrack/users/tests/factories.py
+++ b/ctrack/users/tests/factories.py
@@ -1,19 +1,27 @@
from typing import Any, Sequence
from django.contrib.auth import get_user_model
-from ctrack.organisations.models import Organisation, Address
-from factory import DjangoModelFactory, Faker, post_generation
+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"
+
+ class Meta:
+ model = AddressType
+
+
class AddressFactory(DjangoModelFactory):
+ type = SubFactory(AddressTypeFactory)
line1 = Faker("secondary_address", locale="en_GB")
line2 = Faker("street_name", locale="en_GB")
line3 = Faker("secondary_address", locale="en_GB")
@@ -28,7 +36,6 @@ class AddressFactory(DjangoModelFactory):
class UserFactory(DjangoModelFactory):
-
username = Faker("user_name")
email = Faker("email")
name = Faker("name")