Skip to content

Commit

Permalink
[FIX] Fix parts of lesson unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
boot-sandre committed Oct 5, 2023
1 parent 71ffd38 commit 814a6eb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
17 changes: 4 additions & 13 deletions skii/endpoint/routers/lesson.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def record_create(request: HttpRequest, payload: RouterSaveContract):


@router.get(
path="/read/{pk}/",
path="/fetch/{pk}/",
response={
200: RouterContract,
422: FormInvalidResponseContract,
Expand All @@ -57,13 +57,7 @@ def record_read(request: HttpRequest, pk: IntStrUUID4):
)
def record_update(request: HttpRequest, pk: IntStrUUID4, payload: RouterSaveContract):
record_payload = payload.dict()
if "coordinate" in record_payload:
geo_coordinate = record_payload["coordinate"]
del record_payload["coordinate"]
geo_coordinate_obj, created = GeoCoordinate.objects.update_or_create(
geo_coordinate, **geo_coordinate
)
record_payload["coordinate"] = geo_coordinate_obj

record = get_object_or_404(RouterModel, pk=pk)
for attr, value in record_payload.items():
setattr(record, attr, value)
Expand All @@ -72,7 +66,7 @@ def record_update(request: HttpRequest, pk: IntStrUUID4, payload: RouterSaveCont
return 200, record


@router.get(
@router.delete(
path="/delete/{pk}/",
response={
200: SkiiMsgContract,
Expand All @@ -83,7 +77,7 @@ def record_delete(request: HttpRequest, pk: IntStrUUID4):
qs = RouterModel.objects.all().filter(pk=pk)
if qs.exists():
qs.delete()
return 200, SkiiMsgContract(message="Record deleted")
return 200, SkiiMsgContract(message="OK")


@router.get(
Expand All @@ -95,6 +89,3 @@ def record_delete(request: HttpRequest, pk: IntStrUUID4):
)
def record_list(request: HttpRequest):
return 200, RouterModel.objects.all()


__all__ = [router]
7 changes: 4 additions & 3 deletions skii/platform/factories/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,22 @@ class LessonFactory(factory.django.DjangoModelFactory):
class Meta:
model = LessonEvent

label = factory.Faker("text")
label = factory.Faker("text", max_nb_chars=80)
description = factory.Faker("text", max_nb_chars=255)
teacher = factory.SubFactory(TeacherAgentFactory)
start = fuzzy.FuzzyDateTime(
start_dt=datetime.now(tz=UTC) - timedelta(hours=2),
end_dt=datetime.now(tz=UTC),
force_year=2023,
force_month=7,
force_day=13,
# force_day=13,
)
stop = fuzzy.FuzzyDateTime(
start_dt=datetime.now(tz=UTC),
end_dt=datetime.now(tz=UTC) + timedelta(hours=4),
force_year=2023,
force_month=7,
force_day=13,
# force_day=13,
)

@factory.post_generation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.6 on 2023-10-05 00:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("platform", "0002_rename_uuid_lessonevent_guid_and_more"),
]

operations = [
migrations.RemoveConstraint(
model_name="lessonevent",
name="check_no_overlap",
),
migrations.AddConstraint(
model_name="lessonevent",
constraint=models.CheckConstraint(
check=models.Q(("start__lt", models.F("stop"))), name="check_no_overlap"
),
),
]
14 changes: 4 additions & 10 deletions skii/platform/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ class Meta:
CheckConstraint(
check=(
Q(start__lt=F("stop"))
& ~Q( # Vérifie que start est inférieur à stop
start__range=(F("start"), F("stop"))
)
& ~Q( # Vérifie qu'il n'y a pas de chevauchement
stop__range=(F("start"), F("stop"))
) # Vérifie qu'il n'y a pas de chevauchement
),
name="check_no_overlap",
),
Expand All @@ -50,12 +44,12 @@ def gant_config(self):

return GanttConfigContract(
**{
"start": self.start.strftime(format="%Y-%m-%d %H:%M"),
"stop": self.stop.strftime(format="%Y-%m-%d %H:%M"),
"startGant": self.start.strftime(format="%Y-%m-%d %H:%M"),
"stopGant": self.stop.strftime(format="%Y-%m-%d %H:%M"),
"ganttBarConfig": {
"id": str(self.uuid),
"id": str(self.short_prefix_guid),
"hasHandles": True,
"label": self.title,
"label": self.label,
"style": {
"background": "#e09b69",
"color": "black",
Expand Down
12 changes: 11 additions & 1 deletion tests/endpoint/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@ class TestApiLesson(TestApiTeacher):
api_save_contract = LessonSaveContract

api_route_namespace = "lesson"
fields = []
fields = [
'pk',
'gant_config',
'start',
'stop',
'teacher',
'students',
'label',
'description'
]

0 comments on commit 814a6eb

Please sign in to comment.