Skip to content

Commit

Permalink
meer gebruiker testen (PUT gebruiker_detail werkt niet?)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnoutAllaert committed Mar 9, 2024
1 parent 7c3aa97 commit 297a87b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/tests/serializers/test_gebruiker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
self.serializer_data = GebruikerSerializer().data
self.gebruiker = Gebruiker.objects.create(**self.gebruiker_attributes)

subjects = ['Math', 'Science']
subjects = [1, 2]
for subject in subjects:
vak = Vak.objects.create(name=subject)
self.gebruiker.subjects.add(vak)
Expand Down
21 changes: 20 additions & 1 deletion api/tests/views/test_gebruiker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework.test import APIClient, APITestCase
from api.tests.factories.gebruiker import GebruikerFactory, UserFactory
from django.urls import reverse


class GebruikerListViewTest(APITestCase):
Expand All @@ -14,4 +15,22 @@ def test_get_gebruiker_list(self):
def test_post_gebruiker_list(self):
data = {'user': UserFactory.create().id, 'is_lesgever': True}
response = self.client.post('/api/gebruikers/', data)
self.assertEqual(response.status_code, 201)
self.assertEqual(response.status_code, 201)


class GebruikerDetailViewTest(APITestCase):
def setUp(self):
self.client = APIClient()
self.gebruiker = GebruikerFactory.create()
self.url = reverse('gebruiker_detail', kwargs={'id': self.gebruiker.user.id})

def test_get_gebruiker_detail(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['user'], self.gebruiker.user.id)

def test_put_gebruiker_detail(self):
data = {'user': self.gebruiker.user.id, 'is_lesgever': True, 'subjects': []}
response = self.client.put(self.url, data)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['is_lesgever'], True)
2 changes: 1 addition & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
path('login_redirect/', login_redirect),
path('api/', home),
path('api/gebruikers/', gebruiker_list),
path('api/gebruikers/<int:id>/', gebruiker_detail),
path('api/gebruikers/<int:id>/', gebruiker_detail, name='gebruiker_detail'),
path('api/vakken/', vak_list),
path('api/vakken/<int:id>/', vak_detail),
path('api/projecten/', project_list),
Expand Down

0 comments on commit 297a87b

Please sign in to comment.