Skip to content

Commit

Permalink
Provide a new skiiservicetestcase with fixtures and Client/User facil…
Browse files Browse the repository at this point in the history
…ities
  • Loading branch information
boot-sandre committed Oct 6, 2023
1 parent bee9ebb commit 51c078f
Show file tree
Hide file tree
Showing 8 changed files with 539 additions and 325 deletions.
2 changes: 1 addition & 1 deletion skii/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.0"
__version__ = "0.4.0"
10 changes: 5 additions & 5 deletions skii/endpoint/routers/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
422: FormInvalidResponseContract,
},
)
def list(request: HttpRequest):
def location_list(request: HttpRequest):
return 200, RouterModel.objects.all()


Expand All @@ -40,7 +40,7 @@ def list(request: HttpRequest):
422: FormInvalidResponseContract,
},
)
def fetch(request: HttpRequest, pk: IntStrUUID4):
def location_fetch(request: HttpRequest, pk: IntStrUUID4):
return 200, get_object_or_404(RouterModel, pk=pk)


Expand All @@ -51,7 +51,7 @@ def fetch(request: HttpRequest, pk: IntStrUUID4):
422: FormInvalidResponseContract,
},
)
def record_delete(request: HttpRequest, pk: IntStrUUID4):
def location_delete(request: HttpRequest, pk: IntStrUUID4):
qs = RouterModel.objects.all().filter(pk=pk)
if qs.exists():
qs.delete()
Expand All @@ -65,7 +65,7 @@ def record_delete(request: HttpRequest, pk: IntStrUUID4):
422: FormInvalidResponseContract,
},
)
def record_update(request: HttpRequest, pk: IntStrUUID4, payload: RouterSaveContract):
def location_update(request: HttpRequest, pk: IntStrUUID4, payload: RouterSaveContract):
record_payload = payload.dict()
if "coordinate" in record_payload:
geo_coordinate = record_payload["coordinate"]
Expand All @@ -89,7 +89,7 @@ def record_update(request: HttpRequest, pk: IntStrUUID4, payload: RouterSaveCont
422: FormInvalidResponseContract,
},
)
def create(request: HttpRequest, payload: RouterSaveContract):
def location_create(request: HttpRequest, payload: RouterSaveContract):
record_payload = payload.dict()
if "coordinate" in record_payload:
geo_coordinate = record_payload["coordinate"]
Expand Down
39 changes: 25 additions & 14 deletions skii/platform/factories/factories.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from datetime import timedelta, datetime, UTC

import factory
from django.contrib.auth import get_user_model
from factory import fuzzy
from django.conf import settings

from django.contrib.auth.hashers import make_password

Expand All @@ -28,17 +28,28 @@

class UserFactory(factory.django.DjangoModelFactory):
"""
Create a fake dj user with Faker.
Create a fake standard dj user
"""

class Meta:
model = settings.AUTH_USER_MODEL
model = get_user_model()

# Business fields
username = factory.Faker("user_name")
email = factory.Faker("email")
password = make_password("password")
first_name = factory.Faker("name")
last_name = factory.Faker("name")
# Technical fields
is_active: bool = True
is_staff: bool = False
is_superuser: bool = False


class UserStaffFactory(UserFactory):
class Meta:
model = get_user_model()
is_staff: bool = True


class StudentAgentFactory(factory.django.DjangoModelFactory):
Expand All @@ -53,14 +64,16 @@ class Meta:


class TeacherAgentFactory(factory.django.DjangoModelFactory):
"""
Factory to create instance of a Teacher agent.
""" Factory to create instance of a Teacher agent.
Teacher agent have to be staff in order to access at the django
administration and skii api docs.
"""

class Meta:
model = TeacherAgent

user = factory.SubFactory(UserFactory)
user = factory.SubFactory(UserStaffFactory)


class MoneyResourceFactory(factory.django.DjangoModelFactory):
Expand Down Expand Up @@ -106,8 +119,8 @@ class Meta:


class VisualAlbumFactory(factory.django.DjangoModelFactory):
title = factory.Faker("text")
description = factory.Faker("text")
title = factory.Faker("text", max_nb_chars=20)
description = factory.Faker("text", max_nb_chars=255)

class Meta:
model = VisualAlbum
Expand All @@ -116,8 +129,8 @@ class Meta:
class VisualElementFactory(factory.django.DjangoModelFactory):
album = factory.SubFactory(VisualAlbumFactory)

title = factory.Faker("text")
description = factory.Faker("text")
title = factory.Faker("text", max_nb_chars=20)
description = factory.Faker("text", max_nb_chars=255)
picture = factory.django.ImageField()

class Meta:
Expand All @@ -126,22 +139,20 @@ class Meta:

class VisualPictureFactory(factory.django.DjangoModelFactory):
title = factory.Faker("text", max_nb_chars=20)
description = factory.Faker("text")
description = factory.Faker("text", max_nb_chars=255)
picture = factory.django.ImageField()

class Meta:
model = VisualPicture


class LocationResourceFactory(factory.django.DjangoModelFactory):
"""
Factory to create instance of a geographic location/place.
""" Factory to create instance of a geographic location/place.
"""

class Meta:
model = LocationResource


address1 = factory.Faker("address")
city = factory.Faker("city")
country = factory.Faker("country_code")
Expand Down
Loading

0 comments on commit 51c078f

Please sign in to comment.