Skip to content
Snippets Groups Projects
Commit 751c227f authored by s2536528's avatar s2536528
Browse files

Merge branch '3-expand-tests' into empty_app

parents f4dc51e6 be989dc3
Branches
No related tags found
No related merge requests found
Showing
with 469 additions and 82 deletions
import socket
import debug_toolbar
hostname = socket.gethostname()
if hostname.startswith("runner"):
......
......@@ -13,5 +13,21 @@
"year": 2018,
"is_primary": true
}
},
{
"model": "MySU.studyrecord",
"pk": 2,
"fields": {
"slug": "89ac22dc-5a71-4fac-8af4-7544b7eb71a1",
"study": 1,
"institution": 1,
"student": 2,
"phase": "Bachelor",
"date_start": "2017-09-01",
"date_end": "2018-08-31",
"year": 2018,
"is_primary": true
}
}
]
......@@ -53,21 +53,23 @@ class AssociationSpecificData(models.Model):
raise ValidationError({"data_field": "Association of data_field doesn't match the association."})
# TODO: remove after django update to v3
if len(self.data_field.type) > 1:
if len(self.data_field.type[0]) > 1:
print(len(self.data_field.type))
print(self.data_field.type[0])
raise ValidationError({"data_field": "Validation does not work currently for more than one type"})
if self.data_field.type[0] == "Boolean":
if self.data_field.type == "Boolean":
if self.value not in ["true", "false"]:
raise ValidationError({"value": "Value for boolean data field should be 'true' or 'false'."})
if self.data_field.mandatory and self.value != "true":
raise ValidationError({"value": "Value has to be true (value='true'), when data field is mandatory."})
elif self.data_field.type[0] == "Number":
elif self.data_field.type == "Number":
if not self.value.isdigit():
raise ValidationError({"value": "Value should be a integer"})
elif self.data_field.type[0] == "String":
elif self.data_field.type == "String":
# any valid value for a text field is valid for a data field with type string
pass
elif self.data_field.type[0] == "Choice":
elif self.data_field.type == "Choice":
if self.value not in self.data_field.choices.split(","):
raise ValidationError({"value": "Value {} is not in the list of valid choices"
.format(self.value)})
......
from django.db.models import Q
from guardian.shortcuts import get_objects_for_user
from rest_framework import viewsets
from rest_framework import viewsets, status
from rest_framework.decorators import action
from rest_framework.permissions import BasePermission
from rest_framework.permissions import IsAuthenticated
from url_filter import filtersets
from rest_framework.response import Response
from apps.MySU.models import Association
from apps.MySU.models import AssociationSpecificData
......@@ -17,13 +19,15 @@ from apps.MySU.serializers.association_specific_data import AssociationSpecificD
GET: Everyone
PUT/PATCH: Board
POST: Board
DELETE: Staff
"""
class AssociationSpecificDataHttpPermissions(BasePermission):
def has_object_permission(self, request, view, obj):
if request.method == "PATCH" or request.method == "PUT": # HANDLES THE UPDATE
return request.user.has_perm('board', obj.association) or (obj.membership.user == request.user and not obj.data_field.board_only)
return request.user.has_perm('board', obj.association) or (
obj.membership.user == request.user and not obj.data_field.board_only)
return True
def has_permission(self, request, view):
......@@ -31,6 +35,8 @@ class AssociationSpecificDataHttpPermissions(BasePermission):
return True
if request.method == "POST": # HANDLES THE CREATION/INSERTION
return True
if request.method == "DELETE":
return request.user.is_staff
return True
......@@ -44,14 +50,19 @@ class AssociationSpecificDataViewSet(viewsets.ModelViewSet):
queryset = AssociationSpecificData.objects.none()
lookup_field = 'slug'
permission_classes = (IsAuthenticated, AssociationSpecificDataHttpPermissions,)
http_method_names = ['get', 'post', 'put', 'patch', 'head', 'options']
http_method_names = ['get', 'post', 'put', 'patch', 'head', 'options', 'delete']
filter_class = AssociationSpecificDataFilterSet
def get_queryset(self):
queryset = AssociationSpecificData.objects\
queryset = AssociationSpecificData.objects \
.filter(
Q(association__in=get_objects_for_user(self.request.user, 'board', Association)) |
Q(membership__user=self.request.user))\
.prefetch_related("association", "membership", "data_field")\
Q(association__in=get_objects_for_user(self.request.user, 'board', Association)) |
Q(membership__user=self.request.user)) \
.prefetch_related("association", "membership", "data_field") \
.distinct()
return queryset
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT)
......@@ -56,3 +56,5 @@ class AssociationSpecificDataFieldsViewSet(viewsets.ModelViewSet):
data_field = self.get_object()
self.perform_destroy(data_field)
return Response(status=status.HTTP_204_NO_CONTENT)
from django.shortcuts import get_object_or_404
from django.utils import timezone
from guardian.shortcuts import get_objects_for_user
from guardian.shortcuts import Q
......@@ -59,6 +60,12 @@ class EventViewSet(viewsets.ModelViewSet):
def get_serializer_class(self):
return EventSerializer
def get_object(self):
obj = get_object_or_404(self.get_queryset(), pk=self.kwargs.get("pk"))
print("method for retrieving the object was used ! [TEST]")
self.check_object_permissions(self.request, obj)
return obj
def get_queryset(self):
associations = get_objects_for_user(self.request.user, 'board', klass=Association)
queryset = Event.objects.filter(
......
from rest_framework.test import APIClient
from rest_framework.test import APITestCase
from apps.MySU.viewsets import association
from apps.MySU.models import User
from tests.tests import fixtures
......@@ -13,10 +14,6 @@ class AssociationTestCase(APITestCase):
self.client = APIClient()
self.client.force_authenticate(user=self.user)
def test_get_helios(self):
response = self.client.get('/associations/rising-sun-alienship-helios')
self.assertEqual(200, response.status_code)
def test_put_helios(self):
response = self.client.put('/associations/rising-sun-alienship-helios', data={})
self.assertEqual(403, response.status_code)
......
......@@ -3,6 +3,8 @@ from rest_framework.test import APITestCase
from apps.MySU.models import User
from tests.tests import fixtures
from rest_framework.parsers import JSONParser
from apps.MySU.serializers import AssociationSpecificDataSerializer
class AssociationSpecificDataTestCase(APITestCase):
......@@ -10,38 +12,94 @@ class AssociationSpecificDataTestCase(APITestCase):
def setUp(self):
self.user = User.objects.get(username='s1234567')
self.user.is_staff = True
self.client = APIClient()
self.client.force_authenticate(user=self.user)
def test_put_helios(self):
pass
data = {
"value": "No",
"data_field": "/association_data_fields/ca3cb4f6-015a-4751-a74c-b7063d3961bb",
"name": "ERO",
"membership": "/memberships/26ad699a-cb8a-4fcf-a709-437cc671a4e6",
"association": "/associations/rising-sun-alienship-helios"
}
response = self.client.put('/association_data/04672188-e7e9-43d4-9b2c-6acb6241c19b', data=data)
self.assertEqual(200, response.status_code)
def test_put_student_union(self):
pass
data = {
"value": "36",
"data_field": "/association_data_fields/8e4dcd33-d176-47fd-ad36-ba4e7c737c57",
"name": "Favorite Number",
"membership": "/memberships/ec47e37b-f30e-478f-9b7f-f9c7f3ca5aa6",
"association": "/associations/student-union"
}
response = self.client.put('/association_data/1db97210-f323-4fe2-bfc6-10d1c048cb67', data=data)
self.assertEqual(200, response.status_code)
def test_patch_helios(self):
pass
data = {
"value": "No",
"data_field": "/association_data_fields/ca3cb4f6-015a-4751-a74c-b7063d3961bb",
"name": "ERO"
}
response = self.client.patch('/association_data/04672188-e7e9-43d4-9b2c-6acb6241c19b', data=data)
self.assertEqual(200, response.status_code)
def test_patch_student_union(self):
pass
data = {
"value": "36",
"data_field": "/association_data_fields/8e4dcd33-d176-47fd-ad36-ba4e7c737c57",
"name": "Favorite Number"
}
response = self.client.patch('/association_data/1db97210-f323-4fe2-bfc6-10d1c048cb67', data=data)
self.assertEqual(200, response.status_code)
def test_post_helios(self):
def test_post_helios(self): #Only one answer can be given by each user
pass
def test_post_student_union(self):
def test_post_student_union(self): #Only one answer can be given by each user
pass
def test_delete_helios(self):
pass
data = {
"name": "ERO",
"membership": "/memberships/26ad699a-cb8a-4fcf-a709-437cc671a4e6",
"slug": "04672188-e7e9-43d4-9b2c-6acb6241c19b",
"data_field": "/association_data_fields/ca3cb4f6-015a-4751-a74c-b7063d3961bb",
"url": "/association_data/04672188-e7e9-43d4-9b2c-6acb6241c19b",
"value": "Yes",
"association": "/associations/rising-sun-alienship-helios"
}
response = self.client.delete('/association_data/04672188-e7e9-43d4-9b2c-6acb6241c19b', data=data)
self.assertEqual(204, response.status_code)
def test_delete_student_union(self):
pass
data = {
"name": "Favorite Number",
"membership": "/memberships/ec47e37b-f30e-478f-9b7f-f9c7f3ca5aa6",
"slug": "1db97210-f323-4fe2-bfc6-10d1c048cb67",
"data_field": "/association_data_fields/8e4dcd33-d176-47fd-ad36-ba4e7c737c57",
"url": "/association_data/1db97210-f323-4fe2-bfc6-10d1c048cb67",
"value": "48",
"association": "/associations/student-union"
}
response = self.client.delete('/association_data/1db97210-f323-4fe2-bfc6-10d1c048cb67', data=data)
self.assertEqual(204, response.status_code)
def test_get_helios(self):
pass
response = self.client.get('/association_data/04672188-e7e9-43d4-9b2c-6acb6241c19b')
self.assertEqual(200, response.status_code)
def test_get_student_union(self):
pass
response = self.client.get('/association_data/1db97210-f323-4fe2-bfc6-10d1c048cb67')
self.assertEqual(200, response.status_code)
def test_list(self):
response = self.client.get('/association_data/?ordering=association')
......
......@@ -14,13 +14,95 @@ class AssociationSpecificDataFieldsTestCase(APITestCase):
self.client = APIClient()
self.client.force_authenticate(user=self.user)
def test_put(self):
# TODO 1 with Number, 1 String, 1 Choice, 1 Boolean
pass
def test_put_Number(self):
data = {
"choices": "",
"default": "34",
"board_only": False,
"type": "Number",
"name": "Favorite Number",
"helper_text": "",
"mandatory": False,
"slug": "8e4dcd33-d176-47fd-ad36-ba4e7c737c57",
"association": "/associations/student-union",
"url": "/association_data_fields/8e4dcd33-d176-47fd-ad36-ba4e7c737c57"
}
response = self.client.put('/association_data_fields/8e4dcd33-d176-47fd-ad36-ba4e7c737c57', data=data)
self.assertEqual(200, response.status_code)
def test_patch(self):
# TODO 1 with Number, 1 String, 1 Choice, 1 Boolean
pass
def test_put_String(self):
data = {
"type": "String",
"slug": "a826094e-a8ea-49d6-aa8c-7de943e25f46",
"mandatory": False,
"helper_text": "",
"board_only": False,
"choices": "",
"default": "False",
"association": "/associations/student-union",
"url": "/association_data_fields/a826094e-a8ea-49d6-aa8c-7de943e25f46",
"name": "Drivers Test Licence"
}
response = self.client.put('/association_data_fields/a826094e-a8ea-49d6-aa8c-7de943e25f46', data=data)
self.assertEqual(200, response.status_code)
def test_put_Choice(self):
data = {
"type": "Choice",
"slug": "0d6ff0a9-f2cb-40da-b81b-d4952cc16442",
"mandatory": False,
"helper_text": "",
"board_only": True,
"choices": "apple pie,quark pie",
"default": "quark pie",
"association": "/associations/student-union",
"url": "/association_data_fields/0d6ff0a9-f2cb-40da-b81b-d4952cc16442",
"name": "Quark Pie"
}
response = self.client.put('/association_data_fields/0d6ff0a9-f2cb-40da-b81b-d4952cc16442', data=data)
self.assertEqual(200, response.status_code)
def test_put_Boolean(self):
data = {
"choices": "",
"mandatory": True,
"name": "Test",
"type": "Boolean",
"slug": "ca3cb4f6-015a-4751-a74c-b7063d3961bb",
"default": "False",
"board_only": False,
"association": "/associations/rising-sun-alienship-helios",
"url": "/association_data_fields/ca3cb4f6-015a-4751-a74c-b7063d3961bb",
"helper_text": ""
}
response = self.client.put("/association_data_fields/ca3cb4f6-015a-4751-a74c-b7063d3961bb", data=data)
self.assertEqual(403, response.status_code) # 403 is because only the board of helios can perform changes
def test_patch_Choice(self):
data = {
"type": "Choice",
"slug": "0d6ff0a9-f2cb-40da-b81b-d4952cc16442",
"mandatory": False,
"board_only": True,
"choices": "apple pie,quark pie",
"default": "quark pie",
"name": "Quark Pie"
}
response = self.client.patch('/association_data_fields/0d6ff0a9-f2cb-40da-b81b-d4952cc16442', data=data)
self.assertEqual(200, response.status_code)
def test_patch_Boolean(self):
data = {
"choices": "",
"mandatory": True,
"name": "Test",
"type": "Boolean",
"slug": "ca3cb4f6-015a-4751-a74c-b7063d3961bb",
"default": "False",
"board_only": False,
}
response = self.client.patch("/association_data_fields/ca3cb4f6-015a-4751-a74c-b7063d3961bb", data=data)
self.assertEqual(403, response.status_code) # 403 is because only the board of helios can perform changes
def test_post_student_union_other(self):
# Invalid type
......
......@@ -63,10 +63,152 @@ class GroupTestCase(APITestCase):
self.assertEqual([], group["permissions"], "Final permissions do not match")
def test_put_helios(self):
pass
data = {
"theme": None,
"board_group": True,
"edition": None,
"days_in_existence": 738737,
"archived": False,
"founding_date": "0001-01-01",
"description": "Tempora odio dolor mollitia placeat praesentium atque. Tempora occaecati delectus possimus rem totam itaque.\nVoluptate nisi dolor ipsam corrupti harum ea voluptas. Mollitia exercitationem eligendi.",
"permissions": [
"board"
],
"current_board": True,
"groupmemberships": [
{
"url": "http://127.0.0.1:8000/group_memberships/74c1ff41-3c0f-4037-a5cb-5230324adbae",
"full_name": "Myrthe Adriaensdr",
"slug": "74c1ff41-3c0f-4037-a5cb-5230324adbae",
"duty": "Chairman",
"description": "",
"date_joined": "2016-12-14",
"date_left": None,
"archived": False,
"email": None,
"order": 1,
"profile": "http://127.0.0.1:8000/profiles/60d23c87-9c65-4b73-8d0a-97cd168b3ac6"
},
{
"url": "http://127.0.0.1:8000/group_memberships/b95224c7-74d2-40b3-9b51-09cd7f7330a6",
"full_name": "Rik van den Velde",
"slug": "b95224c7-74d2-40b3-9b51-09cd7f7330a6",
"duty": "Secretary",
"description": "",
"date_joined": "2018-11-07",
"date_left": None,
"archived": False,
"email": None,
"order": 1,
"profile": "http://127.0.0.1:8000/profiles/c4d30249-1a58-47e2-bafc-7b0605972b9e"
},
{
"url": "http://127.0.0.1:8000/group_memberships/523cf33e-dc2e-41fa-9976-47270237ccd6",
"full_name": "Myrthe van der Sloot",
"slug": "523cf33e-dc2e-41fa-9976-47270237ccd6",
"duty": "Treasurer",
"description": "",
"date_joined": "2017-03-14",
"date_left": None,
"archived": False,
"email": None,
"order": 1,
"profile": "http://127.0.0.1:8000/profiles/18cd7edc-b2c5-4378-839a-ee8e3c618774"
}
],
"slug": "c2d3528a-46b3-4830-afa0-dc00831f040a",
"email": None,
"end_year": None,
"logo": None,
"url": "http://127.0.0.1:8000/groups/c2d3528a-46b3-4830-afa0-dc00831f040a",
"photo": None,
"number": 0,
"association": "http://127.0.0.1:8000/associations/rising-sun-alienship-helios",
"short_name": "Board of Helios",
"dissolution_date": None,
"parent_group": "http://127.0.0.1:8000/groups/2d9551a0-7e40-461e-aa49-e578eb608b65",
"start_year": None,
"alternate_name": "",
"creed": "",
"full_name": "board of Helios"
}
response = self.client.put('/groups/c2d3528a-46b3-4830-afa0-dc00831f040a', data=data)
self.assertEqual(403, response.status_code)
def test_put_student_union(self):
pass
data = {
"theme": None,
"board_group": True,
"edition": None,
"days_in_existence": 8801,
"archived": False,
"founding_date": "1999-07-02",
"description": "Similique repudiandae minus sit corrupti doloribus nemo. Possimus magni dolorem.\nUnde nemo suscipit iure officia. Unde eius atque itaque placeat eius sapiente.",
"permissions": [
"board"
],
"current_board": True,
"groupmemberships": [
{
"url": "http://127.0.0.1:8000/group_memberships/1c9ff3f7-b098-4cd5-aa00-48b762ad398b",
"full_name": "Femke Dries",
"slug": "1c9ff3f7-b098-4cd5-aa00-48b762ad398b",
"duty": "Chairman",
"description": "",
"date_joined": "2013-05-09",
"date_left": None,
"archived": False,
"email": None,
"order": 1,
"profile": "http://127.0.0.1:8000/profiles/67dc393a-73fa-4cbe-aa7c-fe59d37ce630"
},
{
"url": "http://127.0.0.1:8000/group_memberships/60127381-26e0-490f-ab89-816c573c17a2",
"full_name": "Max van Boven",
"slug": "60127381-26e0-490f-ab89-816c573c17a2",
"duty": "Secretary",
"description": "",
"date_joined": "2017-11-10",
"date_left": None,
"archived": False,
"email": None,
"order": 1,
"profile": "http://127.0.0.1:8000/profiles/a3709a0b-80dc-475a-9e9e-39b0239ffded"
},
{
"url": "http://127.0.0.1:8000/group_memberships/2252aaf8-aea1-4c7b-af89-f02b75636f1e",
"full_name": "Jonas Lorreijn",
"slug": "2252aaf8-aea1-4c7b-af89-f02b75636f1e",
"duty": "Treasurer",
"description": "",
"date_joined": "2019-02-16",
"date_left": None,
"archived": False,
"email": "odaaya@hotmail.com",
"order": 1,
"profile": "http://127.0.0.1:8000/profiles/75b5beed-97c2-4b43-bf3f-6c7ba85b3a5c"
}
],
"slug": "705f007c-dba5-4da6-9dd7-ba7c22af88bc",
"email": None,
"end_year": None,
"logo": None,
"url": "http://127.0.0.1:8000/groups/705f007c-dba5-4da6-9dd7-ba7c22af88bc",
"photo": None,
"number": 0,
"association": "http://127.0.0.1:8000/associations/student-union",
"short_name": "Board of SU",
"dissolution_date": None,
"parent_group": "http://127.0.0.1:8000/groups/dd0d1b61-e054-4495-b540-3a6c65a5f610",
"start_year": None,
"alternate_name": "College van Bestuur",
"creed": "",
"full_name": "board of Student Union"
}
response = self.client.put('/groups/705f007c-dba5-4da6-9dd7-ba7c22af88bc', data=data)
self.assertEqual(200, response.status_code)
def test_patch_helios(self):
response = self.client.get("/groups/c2d3528a-46b3-4830-afa0-dc00831f040a")
......
......@@ -14,23 +14,57 @@ class GroupMembershipTestCase(APITestCase):
self.client.force_authenticate(user=self.user)
def test_put_helios(self):
# data = {
# "group": "http://127.0.0.1:8000/groups/705f007c-dba5-4da6-9dd7-ba7c22af88bc",
# "order": 1,
# "archived": False,
# "profile": "http://127.0.0.1:8000/profiles/a3709a0b-80dc-475a-9e9e-39b0239ffded",
# "description": "",
# "date_joined": "2017-11-10",
# "duty": "Secretary",
# "slug": "60127381-26e0-490f-ab89-816c573c17a2",
# "email": None,
# "full_name": "Max van Boden",
# "url": "http://127.0.0.1:8000/group_memberships/60127381-26e0-490f-ab89-816c573c17a2",
# "association": "http://127.0.0.1:8000/associations/student-union",
# "date_left": None
# }
# response = self.client.put('/group_memberships/60127381-26e0-490f-ab89-816c573c17a2', data=data)
# self.assertEqual(200, response.status_code)
pass
def test_put_student_union(self):
pass
data = {
"group": "http://127.0.0.1:8000/groups/705f007c-dba5-4da6-9dd7-ba7c22af88bc",
"order": 1,
"archived": False,
"profile": "http://127.0.0.1:8000/profiles/67dc393a-73fa-4cbe-aa7c-fe59d37ce630",
"description": "",
"date_joined": "2013-05-09",
"duty": "Chairman",
"slug": "1c9ff3f7-b098-4cd5-aa00-48b762ad398b",
"email": None,
"full_name": "Femke Dries",
"url": "http://127.0.0.1:8000/group_memberships/1c9ff3f7-b098-4cd5-aa00-48b762ad398b",
"association": "http://127.0.0.1:8000/associations/student-union",
"date_left": None
}
response = self.client.put('/group_memberships/1c9ff3f7-b098-4cd5-aa00-48b762ad398b', data=data)
self.assertEqual(200, response.status_code)
pass
def test_patch_helios(self):
response = self.client.get("/group_memberships/74c1ff41-3c0f-4037-a5cb-5230324adbae")
self.assertEqual(404, response.status_code, response.data)
# group_membership = response.data
# self.assertEqual(group_membership["order"], 1)
# self.assertEqual(group_membership["duty"], "Chairman")
# data = {
# "order": 2,
# "duty": "President"
# }
# response = self.client.patch("/group_memberships/74c1ff41-3c0f-4037-a5cb-5230324adbae", data=data)
# self.assertEqual(403, response.status_code, response.data)
group_membership = response.data
self.assertEqual(group_membership["order"], 1)
self.assertEqual(group_membership["duty"], "Chairman")
data = {
"order": 2,
"duty": "President"
}
response = self.client.patch("/group_memberships/74c1ff41-3c0f-4037-a5cb-5230324adbae", data=data)
self.assertEqual(403, response.status_code, response.data)
def test_patch_student_union(self):
response = self.client.get("/group_memberships/1c9ff3f7-b098-4cd5-aa00-48b762ad398b")
......
......@@ -15,10 +15,68 @@ class ProfileTestCase(APITestCase):
self.client.force_authenticate(user=self.user)
def test_put_self(self):
pass
data = {
"url": "http://127.0.0.1:8000/profiles/75b5beed-97c2-4b43-bf3f-6c7ba85b3a5c",
"bank_account_name": "J. Lorrelijn",
"iban": "NL15RABO6359906732",
"bic": "RABONL2U",
"mine": True,
"phone_number": "+31701-845933",
"address": "Fienweg 212",
"zip_code": "4658 GW",
"city": "Winssen",
"country": "Netherlands",
"slug": "75b5beed-97c2-4b43-bf3f-6c7ba85b3a5c",
"last_modified": "2020-08-24T00:00:00Z",
"profilename": "Board Profile",
"photo": None,
"student_number": "s1234567",
"given_name": "Jonas",
"initials": "W",
"surname": "NotLorijn",
"email": "van-de-leemputlouise@zijlemans.com",
"dutch_speaking": True,
"gender": "Other",
"date_of_birth": "2004-07-22",
"phase": "Bachelor",
"read_and_agreed_to_privacy_policy": False,
"study": None
}
response = self.client.put('/profiles/75b5beed-97c2-4b43-bf3f-6c7ba85b3a5c', data=data)
self.assertEqual(200, response.status_code)
def test_put_other(self):
pass
data = {
"url": "http://127.0.0.1:8000/profiles/be3f26fb-97d1-4270-8367-3e8539b3484d",
"bank_account_name": "",
"iban": "NL70INGB1979747032",
"bic": "INGBNL2A",
"mine": False,
"phone_number": "(057)-8926448",
"address": "Dylanosingel 22",
"zip_code": "4505 YB",
"city": "Vlodrop",
"country": "Netherlands",
"slug": "be3f26fb-97d1-4270-8367-3e8539b3484d",
"last_modified": "2020-08-24T00:00:00Z",
"profilename": "Ordinary User Profile",
"photo": None,
"student_number": "s7654321",
"given_name": "Nikki",
"initials": "E",
"surname": "Romijn",
"email": "zlansink@cornelissen.com",
"dutch_speaking": True,
"gender": "Other",
"date_of_birth": "1994-02-05",
"phase": "Bachelor",
"read_and_agreed_to_privacy_policy": False,
"study": None
}
response = self.client.put('/profiles/be3f26fb-97d1-4270-8367-3e8539b3484d', data=data)
self.assertEqual(403, response.status_code)
def test_patch_self(self):
response = self.client.get('/profiles/75b5beed-97c2-4b43-bf3f-6c7ba85b3a5c')
......@@ -110,9 +168,6 @@ class ProfileTestCase(APITestCase):
profile_count_post_post = Profile.objects.filter(user=2).count()
self.assertEqual(profile_count_pre_post, profile_count_post_post, "Error: Number of profiles should not change")
def test_get_other(self):
pass
def test_list(self):
response = self.client.get('/profiles')
self.assertEqual(200, response.status_code, "Error: {}, Input: List of all profiles".format(response.data))
......
......@@ -13,15 +13,6 @@ class StudyTestCase(APITestCase):
self.client = APIClient()
self.client.force_authenticate(user=self.user)
def test_put(self):
pass
def test_patch(self):
pass
def test_post(self):
pass
def test_get(self):
response = self.client.get('/studies/89ac22dc-5a71-4fac-8af4-5844b7eb71a1')
self.assertEqual(200, response.status_code, "Error: {}, Input: study pk 1".format(response.data))
......
from rest_framework.test import APIClient
from rest_framework.test import APITestCase
from apps.MySU.models import StudyRecord
from apps.MySU.serializers import StudyRecordSerializer
from apps.MySU.models import User
from tests.tests import fixtures
......@@ -12,18 +14,12 @@ class StudyRecordsTestCase(APITestCase):
self.user = User.objects.get(username='s1234567')
self.client = APIClient()
self.client.force_authenticate(user=self.user)
StudyRecord.objects.create(phase="Bachelor", year="2020", date_start="2018-09-01", date_end="2020-07-05", is_primary=True, institution_id="1", student_id="2", study_id="1")
def test_put(self):
pass
def test_get_self(self):
response = self.client.get('/studyrecords/89ac22dc-5a71-4fac-8af4-5844b7eb71a1')
self.assertEqual(200,response.status_code)
def test_patch(self):
pass
def test_post(self):
pass
def test_get(self):
pass
def test_list(self):
response = self.client.get('/studyrecords')
......
......@@ -14,18 +14,14 @@ class UserTestCase(APITestCase):
self.client.force_authenticate(user=self.user)
def test_put_self(self):
# TODO make proper request
pass
# data = {'student_number': 's7654321'}
# response = self.client.put('/users/efc00c85-87a8-446d-ad71-2d2d07d4b588', data=data)
# self.assertEqual(400, response.status_code, "Error: {}, Input: Other student number".format(response.data))
data = {'student_number': 's7654321'}
response = self.client.put('/users/efc00c85-87a8-446d-ad71-2d2d07d4b588', data=data)
self.assertEqual(200, response.status_code, "Error: {}, Input: Other student number".format(response.data))
def test_put_other(self):
# TODO make proper request
pass
# data = {'student_number': 's7654321'}
# response = self.client.put('/users/5b5742e6-b52b-4133-8151-a49d7b186026')
# self.assertEqual(404, response.status_code, "Error: {}, Input: Other student number".format(response.data))
data = {'student_number': 's7654321'}
response = self.client.put('/users/5b5742e6-b52b-4133-8151-a49d7b186026', data=data)
self.assertEqual(404, response.status_code, "Error: {}, Input: Other student number".format(response.data))
def test_patch_self(self):
data = {
......@@ -43,9 +39,6 @@ class UserTestCase(APITestCase):
response = self.client.patch('/users/5b5742e6-b52b-4133-8151-a49d7b186026', data=data)
self.assertEqual(404, response.status_code, "Error: {}, Input: Other student number".format(response.data))
def test_post(self):
pass
def test_get_self(self):
response = self.client.get('/users/me')
self.assertEqual(200, response.status_code, "Error: {}, Input: user via user/me".format(response.data))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment