diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-01-20 19:47:15 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-01-20 19:47:15 +0000 |
commit | b56df3b59558e790b1e9a7a4aab16fa4c798110c (patch) | |
tree | f0b2e5d192a95e1634df96a89f6c3b4d7dc46334 /ctrack | |
parent | 9ebc666f819897aac04e9bc529a39fb40ee7abfb (diff) |
first passing test!
Diffstat (limited to '')
-rw-r--r-- | ctrack/conftest.py | 8 | ||||
-rw-r--r-- | ctrack/organisations/__init__.py | 0 | ||||
-rw-r--r-- | ctrack/organisations/admin.py | 6 | ||||
-rw-r--r-- | ctrack/organisations/apps.py | 5 | ||||
-rw-r--r-- | ctrack/organisations/migrations/0001_initial.py | 21 | ||||
-rw-r--r-- | ctrack/organisations/migrations/__init__.py | 0 | ||||
-rw-r--r-- | ctrack/organisations/models.py | 15 | ||||
-rw-r--r-- | ctrack/organisations/tests/__init__.py | 0 | ||||
-rw-r--r-- | ctrack/organisations/tests/test_models.py | 11 | ||||
-rw-r--r-- | ctrack/organisations/urls.py | 9 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 2 | ||||
-rw-r--r-- | ctrack/users/tests/factories.py | 9 |
12 files changed, 85 insertions, 1 deletions
diff --git a/ctrack/conftest.py b/ctrack/conftest.py index b994f24..36254cd 100644 --- a/ctrack/conftest.py +++ b/ctrack/conftest.py @@ -2,7 +2,8 @@ import pytest from django.test import RequestFactory from ctrack.users.models import User -from ctrack.users.tests.factories import UserFactory +from ctrack.organisations.models import Organisation +from ctrack.users.tests.factories import UserFactory, OrganisationFactory @pytest.fixture(autouse=True) @@ -16,5 +17,10 @@ def user() -> User: @pytest.fixture +def org() -> Organisation: + return OrganisationFactory() + + +@pytest.fixture def request_factory() -> RequestFactory: return RequestFactory() diff --git a/ctrack/organisations/__init__.py b/ctrack/organisations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ctrack/organisations/__init__.py diff --git a/ctrack/organisations/admin.py b/ctrack/organisations/admin.py new file mode 100644 index 0000000..8890f15 --- /dev/null +++ b/ctrack/organisations/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +from .models import Organisation + +# Register your models here. +admin.site.register(Organisation) diff --git a/ctrack/organisations/apps.py b/ctrack/organisations/apps.py new file mode 100644 index 0000000..72eb1d9 --- /dev/null +++ b/ctrack/organisations/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class OrganisationsConfig(AppConfig): + name = 'ctrack.organisations' diff --git a/ctrack/organisations/migrations/0001_initial.py b/ctrack/organisations/migrations/0001_initial.py new file mode 100644 index 0000000..6171bb8 --- /dev/null +++ b/ctrack/organisations/migrations/0001_initial.py @@ -0,0 +1,21 @@ +# Generated by Django 2.2.9 on 2020-01-20 16:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Organisation', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + ), + ] diff --git a/ctrack/organisations/migrations/__init__.py b/ctrack/organisations/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ctrack/organisations/migrations/__init__.py diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py new file mode 100644 index 0000000..976e661 --- /dev/null +++ b/ctrack/organisations/models.py @@ -0,0 +1,15 @@ +from django.db import models + +# Create your models here. +from django.urls import reverse +from slugify import slugify + + +class Organisation(models.Model): + name = models.CharField(max_length=255, blank=False) + + def get_absolute_url(self): + return reverse("organisations:detail", kwargs={"name": self.slugify_name()}) + + def slugify_name(self): + return slugify(self.name) diff --git a/ctrack/organisations/tests/__init__.py b/ctrack/organisations/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ctrack/organisations/tests/__init__.py diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py new file mode 100644 index 0000000..1307a83 --- /dev/null +++ b/ctrack/organisations/tests/test_models.py @@ -0,0 +1,11 @@ +import pytest +from slugify import slugify + +from ..models import Organisation + +pytestmark = pytest.mark.django_db + + +def test_organisation_get_absolute_url(org: Organisation): + slug = slugify(org.name) + assert org.get_absolute_url() == f"/organisations/{slug}/" diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py new file mode 100644 index 0000000..a3b1b9f --- /dev/null +++ b/ctrack/organisations/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from ctrack.organisations.views import organisations_detail_view + +app_name = "organisations" + +urlpatterns = [ + path("<str:name>/", view=organisations_detail_view, name="detail") +] diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py new file mode 100644 index 0000000..30d00be --- /dev/null +++ b/ctrack/organisations/views.py @@ -0,0 +1,2 @@ +def organisations_detail_view(request): + pass diff --git a/ctrack/users/tests/factories.py b/ctrack/users/tests/factories.py index b537136..d4b9544 100644 --- a/ctrack/users/tests/factories.py +++ b/ctrack/users/tests/factories.py @@ -1,9 +1,18 @@ from typing import Any, Sequence from django.contrib.auth import get_user_model +from ctrack.organisations.models import Organisation from factory import DjangoModelFactory, Faker, post_generation +class OrganisationFactory(DjangoModelFactory): + + name = Faker("name") + + class Meta: + model = Organisation + + class UserFactory(DjangoModelFactory): username = Faker("user_name") |