diff --git a/api/serializers/gebruiker.py b/api/serializers/gebruiker.py index 7dee6cdf..1292e010 100644 --- a/api/serializers/gebruiker.py +++ b/api/serializers/gebruiker.py @@ -2,6 +2,7 @@ from api.models.gebruiker import Gebruiker from api.models.vak import Vak + class GebruikerSerializer(serializers.ModelSerializer): """ Serializer voor het serialiseren en deserialiseren van Gebruiker objecten. @@ -16,13 +17,13 @@ class GebruikerSerializer(serializers.ModelSerializer): update(self, instance, validated_data): Werkt een bestaande gebruiker bij in de database. """ - first_name = serializers.CharField(source='user.first_name', read_only=True) - last_name = serializers.CharField(source='user.last_name', read_only=True) - email = serializers.EmailField(source='user.email', read_only=True) + first_name = serializers.CharField(source="user.first_name", read_only=True) + last_name = serializers.CharField(source="user.last_name", read_only=True) + email = serializers.EmailField(source="user.email", read_only=True) class Meta: model = Gebruiker - fields = ['user', 'is_lesgever', 'first_name', 'last_name', 'email'] + fields = ["user", "is_lesgever", "first_name", "last_name", "email"] def create(self, validated_data): """ @@ -52,8 +53,13 @@ def update(self, instance, validated_data): instance.save() return instance + def validate_lesgever_change(instance): if instance.is_lesgever and Vak.objects.filter(lesgevers=instance): - raise serializers.ValidationError(f"De lesgever {instance} moet eerst verwijderd worden als lesgever in zijn huidige vakken") + raise serializers.ValidationError( + f"De lesgever {instance} moet eerst verwijderd worden als lesgever in zijn huidige vakken" + ) elif not instance.is_lesgever and Vak.objects.filter(studenten=instance): - raise serializers.ValidationError(f"De student {instance} moet eerst verwijderd worden als student in zijn huidige vakken") \ No newline at end of file + raise serializers.ValidationError( + f"De student {instance} moet eerst verwijderd worden als student in zijn huidige vakken" + ) diff --git a/api/tests/factories/indiening.py b/api/tests/factories/indiening.py index 38d63ece..457a0a1c 100644 --- a/api/tests/factories/indiening.py +++ b/api/tests/factories/indiening.py @@ -22,6 +22,11 @@ class Meta: fake.date_time_between(start_date="+1d", end_date="+30d") ) ) + status = factory.Faker("boolean") + + indiening_bestanden = factory.RelatedFactory( + "api.tests.factories.indiening.IndieningBestandFactory", "indiening" + ) class IndieningBestandFactory(DjangoModelFactory): diff --git a/api/tests/factories/project.py b/api/tests/factories/project.py index 216d1998..19669fc5 100644 --- a/api/tests/factories/project.py +++ b/api/tests/factories/project.py @@ -23,4 +23,11 @@ class Meta: fake.date_time_between(start_date="+1d", end_date="+30d") ) ) + extra_deadline = factory.LazyFunction( + lambda: timezone.make_aware( + fake.date_time_between(start_date="+30d", end_date="+40d") + ) + ) max_score = factory.Faker("random_int", min=10, max=100) + zichtbaar = factory.Faker('boolean') + gearchiveerd = factory.Faker('boolean') diff --git a/api/tests/models/test_indiening.py b/api/tests/models/test_indiening.py index b3bd52a6..094c0f63 100644 --- a/api/tests/models/test_indiening.py +++ b/api/tests/models/test_indiening.py @@ -15,14 +15,12 @@ def test_groep(self): def test_tijdstip(self): self.assertIsNotNone(self.indiening.tijdstip) - - def test_indiening_bestand(self): - self.assertEqual(self.indiening.indieningbestand_set.count(), 0) - - def test_indiening_bestand_add(self): - IndieningBestandFactory.create(indiening=self.indiening) - self.assertEqual(self.indiening.indieningbestand_set.count(), 1) - + + def test_status(self): + self.assertIsNotNone(self.indiening.status) + + def test_indiening_bestanden(self): + self.assertEqual(self.indiening.indiening_bestanden.count(), 1) class IndieningBestandModelTest(TestCase): def setUp(self): diff --git a/api/tests/models/test_project.py b/api/tests/models/test_project.py index 971c0eec..29ec4d61 100644 --- a/api/tests/models/test_project.py +++ b/api/tests/models/test_project.py @@ -14,3 +14,18 @@ def test_project_vak(self): def test_project_max_score(self): self.assertTrue(10 <= self.project.max_score <= 100) + + def test_project_zichtbaar(self): + self.assertIsNotNone(self.project.zichtbaar) + + def test_project_gearchiveerd(self): + self.assertIsNotNone(self.project.gearchiveerd) + + def test_project_deadline(self): + self.assertIsNotNone(self.project.deadline) + + def test_project_extra_deadline(self): + self.assertIsNotNone(self.project.extra_deadline) + + def test_project_opgave_bestand(self): + self.assertEqual(self.project.opgave_bestand.read(), b"file content")