Skip to content

Commit

Permalink
tussentijdse commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnoutAllaert committed Mar 13, 2024
1 parent ec1ef57 commit be13246
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 38 deletions.
17 changes: 10 additions & 7 deletions api/tests/factories/gebruiker.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import factory
from django.contrib.auth.models import User
from api.models.gebruiker import Gebruiker
import factory
from factory.django import DjangoModelFactory
from factory import SubFactory, Faker


class UserFactory(factory.django.DjangoModelFactory):
class UserFactory(DjangoModelFactory):
class Meta:
model = User

username = factory.Sequence(lambda n: f"user{n}")
password = factory.PostGenerationMethodCall("set_password", "password")
first_name = Faker('first_name')
last_name = Faker('last_name')
email = Faker('email')


class GebruikerFactory(factory.django.DjangoModelFactory):
class GebruikerFactory(DjangoModelFactory):
class Meta:
model = Gebruiker

user = factory.SubFactory(UserFactory)
is_lesgever = False
user = SubFactory(UserFactory)
is_lesgever = Faker('boolean')
13 changes: 8 additions & 5 deletions api/tests/factories/groep.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import factory
from api.models.groep import Groep
from factory.django import DjangoModelFactory
from factory import SubFactory
from api.tests.factories.gebruiker import GebruikerFactory
from api.tests.factories.project import ProjectFactory


class GroepFactory(factory.django.DjangoModelFactory):
class GroepFactory(DjangoModelFactory):
class Meta:
model = Groep

project = factory.SubFactory(ProjectFactory)
groep_id = factory.Sequence(lambda n: n)
project = SubFactory(ProjectFactory)

@factory.post_generation
def students(self, create, extracted, **kwargs):
def studenten(self, create, extracted, **kwargs):
if not create:
return

if extracted:
for student in extracted:
self.students.add(student)
self.studenten.add(student)
else:
self.students.add(GebruikerFactory())
self.students.add(GebruikerFactory())
24 changes: 17 additions & 7 deletions api/tests/factories/indiening.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import factory
from api.models.indiening import Indiening
from api.tests.factories.groep import GroepFactory
from api.models.indiening import Indiening, IndieningBestand
from factory.django import DjangoModelFactory
from factory import SubFactory, Faker
from .groep import GroepFactory
from django.utils import timezone
from faker import Faker
from factory.django import FileField

fake = Faker()

fake = Faker()

class IndieningFactory(factory.django.DjangoModelFactory):
class IndieningFactory(DjangoModelFactory):
class Meta:
model = Indiening

indiener = factory.SubFactory(GroepFactory)
indieningsbestanden = factory.django.FileField(data=b"file content")
indiening_id = factory.Sequence(lambda n: n)
groep = SubFactory(GroepFactory)
tijdstip = factory.LazyFunction(
lambda: timezone.make_aware(
fake.date_time_between(start_date="+1d", end_date="+30d")
)
)

class IndieningBestandFactory(DjangoModelFactory):
class Meta:
model = IndieningBestand

indiening_bestand_id = factory.Sequence(lambda n: n)
indiening = SubFactory(IndieningFactory)
bestand = FileField(filename='test.txt', data=b"file content")
23 changes: 13 additions & 10 deletions api/tests/factories/project.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
from django.utils import timezone
import factory
from api.models.project import Project
from api.tests.factories.vak import VakFactory
from faker import Faker

fake = Faker()
from django.core.files.base import ContentFile
from factory.django import DjangoModelFactory
from factory import SubFactory, Faker
from django.utils import timezone
from .vak import VakFactory

fake = Faker('provider')

class ProjectFactory(factory.django.DjangoModelFactory):
class ProjectFactory(DjangoModelFactory):
class Meta:
model = Project

titel = factory.Faker("sentence", nb_words=4)
description = factory.Faker("paragraph")
opgavebestanden = factory.django.FileField(filename="opgave.pdf")
vak = factory.SubFactory(VakFactory)
project_id = factory.Sequence(lambda n: n)
titel = Faker('title')
beschrijving = Faker('paragraph')
opgave_bestand = factory.django.FileField(data=b"file content")
vak = SubFactory(VakFactory)
deadline = factory.LazyFunction(
lambda: timezone.make_aware(
fake.date_time_between(start_date="+1d", end_date="+30d")
)
)
max_score = Faker('random_int', min=10, max=30)
10 changes: 8 additions & 2 deletions api/tests/factories/score.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import factory
from api.models.score import Score
from factory.django import DjangoModelFactory
from factory import SubFactory, Faker
from api.tests.factories.indiening import IndieningFactory


class ScoreFactory(factory.django.DjangoModelFactory):

class ScoreFactory(DjangoModelFactory):
class Meta:
model = Score

score = factory.Faker("pyint")
score_id = factory.Sequence(lambda n: n)
score = Faker('random_int', min=0, max=100)
indiening = SubFactory(IndieningFactory)
10 changes: 8 additions & 2 deletions api/tests/factories/vak.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import factory
from api.models.vak import Vak
from factory.django import DjangoModelFactory
from factory import Faker
from .gebruiker import GebruikerFactory


class VakFactory(factory.django.DjangoModelFactory):
class VakFactory(DjangoModelFactory):
class Meta:
model = Vak

name = factory.Faker("word")
vak_id = factory.Sequence(lambda n: n)
naam = Faker('name')
studenten = factory.RelatedFactory(GebruikerFactory, 'vak_gebruikers')
lesgevers = factory.RelatedFactory(GebruikerFactory, 'vak_lesgevers')
6 changes: 1 addition & 5 deletions api/tests/models/test_gebruiker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def test_user_label(self):
field_label = self.gebruiker1._meta.get_field("user").verbose_name
self.assertEqual(field_label, "user")

def test_subjects_label(self):
field_label = self.gebruiker1._meta.get_field("subjects").verbose_name
self.assertEqual(field_label, "subjects")

def test_str_method(self):
expected_object_name = self.gebruiker1.user.first_name
expected_object_name = self.gebruiker1.user.first_name + " " + self.gebruiker1.user.last_name
self.assertEqual(str(self.gebruiker1), expected_object_name)

0 comments on commit be13246

Please sign in to comment.