-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from SELab-2/testing
Testing into develop
- Loading branch information
Showing
16 changed files
with
184 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# UGent-4 | ||
# UGent-4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.contrib.auth.models import User | ||
from api.models.gebruiker import Gebruiker | ||
import factory | ||
|
||
class UserFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = User | ||
|
||
username = factory.Sequence(lambda n: f'user{n}') | ||
password = factory.PostGenerationMethodCall('set_password', 'password') | ||
|
||
class GebruikerFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Gebruiker | ||
|
||
user = factory.SubFactory(UserFactory) | ||
is_lesgever = False |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.test import TestCase | ||
from api.models.gebruiker import Gebruiker | ||
from django.contrib.auth.models import User | ||
|
||
class GebruikerTestCase(TestCase): | ||
def setUp(self): | ||
user1 = User.objects.create_user(username='user1') | ||
user2 = User.objects.create_user(username='user2') | ||
Gebruiker.objects.create(user=user1, is_lesgever=False) | ||
Gebruiker.objects.create(user=user2, is_lesgever=True) | ||
|
||
def test_gebruiker_is_lesgever(self): | ||
user1 = Gebruiker.objects.get(user__username='user1') | ||
user2 = Gebruiker.objects.get(user__username='user2') | ||
self.assertEqual(user1.is_lesgever, False) | ||
self.assertEqual(user2.is_lesgever, True) | ||
|
||
def test_user_label(self): | ||
user = Gebruiker.objects.get(user__username='user1') | ||
field_label = user._meta.get_field('user').verbose_name | ||
self.assertEqual(field_label, 'user') | ||
|
||
def test_subjects_label(self): | ||
user = Gebruiker.objects.get(user__username='user1') | ||
field_label = user._meta.get_field('subjects').verbose_name | ||
self.assertEqual(field_label, 'subjects') | ||
|
||
def test_str_method(self): | ||
gebruiker = Gebruiker.objects.get(user__username='user1') | ||
expected_object_name = gebruiker.user.first_name | ||
self.assertEqual(str(gebruiker), expected_object_name) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.test import TestCase | ||
from rest_framework.test import APITestCase | ||
from rest_framework.exceptions import ValidationError | ||
from api.models.gebruiker import Gebruiker | ||
from api.serializers.gebruiker import GebruikerSerializer | ||
from django.contrib.auth.models import User | ||
from api.models.vak import Vak | ||
|
||
class GebruikerSerializerTest(APITestCase): | ||
|
||
def setUp(self): | ||
# Create a User instance | ||
self.user = User.objects.create_user(username='testuser') | ||
|
||
self.gebruiker_attributes = { | ||
'user': self.user, | ||
} | ||
|
||
self.serializer_data = GebruikerSerializer().data | ||
self.gebruiker = Gebruiker.objects.create(**self.gebruiker_attributes) | ||
|
||
subjects = [1, 2] | ||
for subject in subjects: | ||
vak = Vak.objects.create(name=subject) | ||
self.gebruiker.subjects.add(vak) | ||
|
||
self.serializer = GebruikerSerializer(instance=self.gebruiker) | ||
|
||
def test_contains_expected_fields(self): | ||
data = self.serializer.data | ||
self.assertCountEqual(data.keys(), ['user', 'is_lesgever', 'subjects']) | ||
|
||
def test_user_field_content(self): | ||
data = self.serializer.data | ||
self.assertEqual(data['user'], self.user.id) | ||
|
||
def test_subjects_field_content(self): | ||
data = self.serializer.data | ||
subjects = [subject.pk for subject in self.gebruiker.subjects.all()] | ||
self.assertEqual(data['subjects'], subjects) | ||
|
||
def test_validation_for_blank_items(self): | ||
serializer = GebruikerSerializer(data={'name': '', 'subjects': []}) | ||
self.assertRaises(ValidationError, serializer.is_valid, raise_exception=True) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
''' from django.test import TestCase | ||
from django.urls import reverse | ||
class TestViews(TestCase): | ||
def test_should_show_register_page(self): | ||
#self.client.get(reverse('register')) | ||
#self.assertEqual(response.status_code, 200) | ||
#self.assertTemplateUsed(response, "authentication/register") | ||
self.assertTrue(True) ''' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from rest_framework.test import APIClient, APITestCase | ||
from api.tests.factories.gebruiker import GebruikerFactory, UserFactory | ||
from django.urls import reverse | ||
|
||
|
||
class GebruikerListViewTest(APITestCase): | ||
def setUp(self): | ||
self.client = APIClient() | ||
self.gebruiker = GebruikerFactory.create() | ||
|
||
def test_get_gebruiker_list(self): | ||
response = self.client.get('/api/gebruikers/') | ||
self.assertEqual(response.status_code, 200) | ||
|
||
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) | ||
|
||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ django-auth-adfs | |
python-dotenv | ||
coverage | ||
flake8 | ||
factory_boy |