Skip to content
Snippets Groups Projects
Commit 6e959063 authored by s2536528's avatar s2536528
Browse files

Merge branch '3-expand-tests' into develop

# Conflicts:
#	apps/MySU/models/association_specific_data.py
#	apps/calendar/viewsets/event.py
#	tests/MySU/association_specific_data.py
parents 1fcc4d36 be989dc3
Branches
No related tags found
No related merge requests found
import socket import socket
import debug_toolbar
hostname = socket.gethostname() hostname = socket.gethostname()
if hostname.startswith("runner"): if hostname.startswith("runner"):
......
...@@ -52,9 +52,11 @@ class AssociationSpecificData(models.Model): ...@@ -52,9 +52,11 @@ class AssociationSpecificData(models.Model):
if self.association != self.data_field.association: if self.association != self.data_field.association:
raise ValidationError({"data_field": "Association of data_field doesn't match the association."}) raise ValidationError({"data_field": "Association of data_field doesn't match the association."})
# # TODO: remove after django update to v3 # TODO: remove after django update to v3
# if len(self.data_field.type) > 1: if len(self.data_field.type[0]) > 1:
# raise ValidationError({"data_field": "Validation does not work currently for more than one type"}) 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 == "Boolean": if self.data_field.type == "Boolean":
if self.value not in ["true", "false"]: if self.value not in ["true", "false"]:
......
from django.db.models import Q from django.db.models import Q
from guardian.shortcuts import get_objects_for_user 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 BasePermission
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from url_filter import filtersets from url_filter import filtersets
from rest_framework.response import Response
from apps.MySU.models import Association from apps.MySU.models import Association
from apps.MySU.models import AssociationSpecificData from apps.MySU.models import AssociationSpecificData
...@@ -17,13 +19,15 @@ from apps.MySU.serializers.association_specific_data import AssociationSpecificD ...@@ -17,13 +19,15 @@ from apps.MySU.serializers.association_specific_data import AssociationSpecificD
GET: Everyone GET: Everyone
PUT/PATCH: Board PUT/PATCH: Board
POST: Board POST: Board
DELETE: Staff
""" """
class AssociationSpecificDataHttpPermissions(BasePermission): class AssociationSpecificDataHttpPermissions(BasePermission):
def has_object_permission(self, request, view, obj): def has_object_permission(self, request, view, obj):
if request.method == "PATCH" or request.method == "PUT": # HANDLES THE UPDATE 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 return True
def has_permission(self, request, view): def has_permission(self, request, view):
...@@ -31,6 +35,8 @@ class AssociationSpecificDataHttpPermissions(BasePermission): ...@@ -31,6 +35,8 @@ class AssociationSpecificDataHttpPermissions(BasePermission):
return True return True
if request.method == "POST": # HANDLES THE CREATION/INSERTION if request.method == "POST": # HANDLES THE CREATION/INSERTION
return True return True
if request.method == "DELETE":
return request.user.is_staff
return True return True
...@@ -44,14 +50,19 @@ class AssociationSpecificDataViewSet(viewsets.ModelViewSet): ...@@ -44,14 +50,19 @@ class AssociationSpecificDataViewSet(viewsets.ModelViewSet):
queryset = AssociationSpecificData.objects.none() queryset = AssociationSpecificData.objects.none()
lookup_field = 'slug' lookup_field = 'slug'
permission_classes = (IsAuthenticated, AssociationSpecificDataHttpPermissions,) 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 filter_class = AssociationSpecificDataFilterSet
def get_queryset(self): def get_queryset(self):
queryset = AssociationSpecificData.objects\ queryset = AssociationSpecificData.objects \
.filter( .filter(
Q(association__in=get_objects_for_user(self.request.user, 'board', Association)) | Q(association__in=get_objects_for_user(self.request.user, 'board', Association)) |
Q(membership__user=self.request.user))\ Q(membership__user=self.request.user)) \
.prefetch_related("association", "membership", "data_field")\ .prefetch_related("association", "membership", "data_field") \
.distinct() .distinct()
return queryset 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): ...@@ -56,3 +56,5 @@ class AssociationSpecificDataFieldsViewSet(viewsets.ModelViewSet):
data_field = self.get_object() data_field = self.get_object()
self.perform_destroy(data_field) self.perform_destroy(data_field)
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
from django.shortcuts import get_object_or_404
from django.utils import timezone from django.utils import timezone
from guardian.shortcuts import get_objects_for_user from guardian.shortcuts import get_objects_for_user
from guardian.shortcuts import Q from guardian.shortcuts import Q
...@@ -60,12 +59,6 @@ class EventViewSet(viewsets.ModelViewSet): ...@@ -60,12 +59,6 @@ class EventViewSet(viewsets.ModelViewSet):
def get_serializer_class(self): def get_serializer_class(self):
return EventSerializer return EventSerializer
def get_object(self):
obj = get_object_or_404(self.get_queryset(), pk=self.kwargs["id"])
print("method for retrieving the object was used ! [TEST]")
self.check_object_permissions(self.request, obj)
return obj
def get_queryset(self): def get_queryset(self):
associations = get_objects_for_user(self.request.user, 'board', klass=Association) associations = get_objects_for_user(self.request.user, 'board', klass=Association)
queryset = Event.objects.filter( queryset = Event.objects.filter(
......
...@@ -12,47 +12,94 @@ class AssociationSpecificDataTestCase(APITestCase): ...@@ -12,47 +12,94 @@ class AssociationSpecificDataTestCase(APITestCase):
def setUp(self): def setUp(self):
self.user = User.objects.get(username='s1234567') self.user = User.objects.get(username='s1234567')
self.user.is_staff = True
self.client = APIClient() self.client = APIClient()
self.client.force_authenticate(user=self.user) self.client.force_authenticate(user=self.user)
def test_put_helios(self): def test_put_helios(self):
response = self.client.get('/association_data_fields') 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) self.assertEqual(200, response.status_code)
def test_put_student_union(self): 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): 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): def test_patch_student_union(self):
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): #Only one answer can be given by each user
pass pass
def test_post_helios(self): def test_post_student_union(self): #Only one answer can be given by each user
pass pass
def test_post_student_union(self): def test_delete_helios(self):
data = { data = {
'value': '67', "name": "ERO",
'association': 'test_association', "membership": "/memberships/26ad699a-cb8a-4fcf-a709-437cc671a4e6",
'membership': 'test_membership', "slug": "04672188-e7e9-43d4-9b2c-6acb6241c19b",
'data_field': 'custom data' "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.post("/association_data/", data=data) response = self.client.delete('/association_data/04672188-e7e9-43d4-9b2c-6acb6241c19b', data=data)
self.assertEqual(201, response.status_code) self.assertEqual(204, response.status_code)
def test_delete_helios(self):
pass
def test_delete_student_union(self): 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): 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): 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): def test_list(self):
response = self.client.get('/association_data/?ordering=association') response = self.client.get('/association_data/?ordering=association')
......
...@@ -14,13 +14,95 @@ class AssociationSpecificDataFieldsTestCase(APITestCase): ...@@ -14,13 +14,95 @@ class AssociationSpecificDataFieldsTestCase(APITestCase):
self.client = APIClient() self.client = APIClient()
self.client.force_authenticate(user=self.user) self.client.force_authenticate(user=self.user)
def test_put(self): def test_put_Number(self):
# TODO 1 with Number, 1 String, 1 Choice, 1 Boolean data = {
pass "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): def test_put_String(self):
# TODO 1 with Number, 1 String, 1 Choice, 1 Boolean data = {
pass "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): def test_post_student_union_other(self):
# Invalid type # Invalid type
......
...@@ -63,10 +63,152 @@ class GroupTestCase(APITestCase): ...@@ -63,10 +63,152 @@ class GroupTestCase(APITestCase):
self.assertEqual([], group["permissions"], "Final permissions do not match") self.assertEqual([], group["permissions"], "Final permissions do not match")
def test_put_helios(self): 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): 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): def test_patch_helios(self):
response = self.client.get("/groups/c2d3528a-46b3-4830-afa0-dc00831f040a") response = self.client.get("/groups/c2d3528a-46b3-4830-afa0-dc00831f040a")
......
...@@ -14,23 +14,57 @@ class GroupMembershipTestCase(APITestCase): ...@@ -14,23 +14,57 @@ class GroupMembershipTestCase(APITestCase):
self.client.force_authenticate(user=self.user) self.client.force_authenticate(user=self.user)
def test_put_helios(self): 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 pass
def test_put_student_union(self): 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): def test_patch_helios(self):
response = self.client.get("/group_memberships/74c1ff41-3c0f-4037-a5cb-5230324adbae") response = self.client.get("/group_memberships/74c1ff41-3c0f-4037-a5cb-5230324adbae")
self.assertEqual(404, response.status_code, response.data) group_membership = response.data
# group_membership = response.data self.assertEqual(group_membership["order"], 1)
# self.assertEqual(group_membership["order"], 1) self.assertEqual(group_membership["duty"], "Chairman")
# self.assertEqual(group_membership["duty"], "Chairman") data = {
# data = { "order": 2,
# "order": 2, "duty": "President"
# "duty": "President" }
# } response = self.client.patch("/group_memberships/74c1ff41-3c0f-4037-a5cb-5230324adbae", data=data)
# response = self.client.patch("/group_memberships/74c1ff41-3c0f-4037-a5cb-5230324adbae", data=data) self.assertEqual(403, response.status_code, response.data)
# self.assertEqual(403, response.status_code, response.data)
def test_patch_student_union(self): def test_patch_student_union(self):
response = self.client.get("/group_memberships/1c9ff3f7-b098-4cd5-aa00-48b762ad398b") response = self.client.get("/group_memberships/1c9ff3f7-b098-4cd5-aa00-48b762ad398b")
......
...@@ -15,10 +15,68 @@ class ProfileTestCase(APITestCase): ...@@ -15,10 +15,68 @@ class ProfileTestCase(APITestCase):
self.client.force_authenticate(user=self.user) self.client.force_authenticate(user=self.user)
def test_put_self(self): 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): 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): def test_patch_self(self):
response = self.client.get('/profiles/75b5beed-97c2-4b43-bf3f-6c7ba85b3a5c') response = self.client.get('/profiles/75b5beed-97c2-4b43-bf3f-6c7ba85b3a5c')
...@@ -110,9 +168,6 @@ class ProfileTestCase(APITestCase): ...@@ -110,9 +168,6 @@ class ProfileTestCase(APITestCase):
profile_count_post_post = Profile.objects.filter(user=2).count() 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") 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): def test_list(self):
response = self.client.get('/profiles') response = self.client.get('/profiles')
self.assertEqual(200, response.status_code, "Error: {}, Input: List of all profiles".format(response.data)) self.assertEqual(200, response.status_code, "Error: {}, Input: List of all profiles".format(response.data))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment