Skip to content
Snippets Groups Projects
Commit 88e5fa71 authored by Vegard Murvold Sporstøl's avatar Vegard Murvold Sporstøl
Browse files

work on tests

parent 7d1fc7e0
No related branches found
No related tags found
1 merge request!7Task3
Pipeline #113681 failed
import json
from django.contrib.auth.models import User
from django.urls import reverse
from rest_framework import status
from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase
from users.serializers import UserSerializer
from users.models import User
from django.test import TestCase
# Tests new registration, boundary values and 2-way domain
class RegistrationTestCase(APITestCase):
def test_registration(self):
data = {"username": "testcase", "email": "test@test.no",
"password": "strong_pwd", "password1": "strong_pwd",
"phone_number": "95080764", "country": "Norway",
"city": "Trondheim", "street_address": "Tors Veg 11C"}
def test_boundaryValuesOfRegistrationInvalid(self):
data = {"username": "test", "email": "",
"password": "", "password1": "",
"phone_number": "", "country": "",
"city": "", "street_address": ""}
response = self.client.post("/api/users/", data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) #should fail at blank pwd
data = {"username": "", "email": "",
"password": "1", "password1": "1",
"phone_number": "", "country": "",
"city": "", "street_address": ""}
response = self.client.post("/api/users/", data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) #should fail at blank username
# Seem to be no upper value and no restrictions to the other fields
def test_boundaryValuesOfRegistration(self):
"Test boudary values of signup"
def test_boundaryValuesOfRegistrationValid(self):
data = {"username": "t", "email": "",
"password": "1", "password1": "1",
"phone_number": "", "country": "",
"city": "", "street_address": ""}
response = self.client.post("/api/users/", data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED) #should work at one char pwd and username
def test_domainRegistration(self):
"2-way domain tests to test the register page"
# Tests new functionality in UC-2
class Statistics(APITestCase):
def test_renderStatistics(self):
......
......@@ -7,18 +7,35 @@ from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase
from users.serializers import UserSerializer
from users.models import User
from workouts.serializers import WorkoutSerializer
from workouts.models import Workout
from django.test import TestCase
# Tests new workout and boundary values
class NewWorkoutTestCase(APITestCase):
# Følger denne: https://www.youtube.com/watch?v=1FqxfnlQPi8&ab_channel=pymike00
# men skjønner ikke helt feilmeldinga som kommer nå, setup funker ikke
def setUp(self):
self.user = User.objects.create_user(username="test",
password="strong_pwd")
self.token = Token.object.create(user=self.user)
self.api_authentication()
def api_authentication(self):
self.client.credentials(HTTP_AUTHORIZATION="Token " + self.token.key)
def test_newWorkoutRegistration(self):
"Test registering a new workout"
data = {"name": "test", "date": "2019-09-25 06:00",
"notes": "test", "owner": "",
"visibility": "Public"}
response = self.client.post("/api/workouts/", data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED) #should work
def test_boundaryValuesOfNewWorkout(self):
"test boundary values of new workout"
# Tests FR5
class WorkoutDetails(APITestCase):
def test_viewDetails(self):
"Test that user can view all details"
......@@ -29,7 +46,7 @@ class WorkoutDetails(APITestCase):
def test_viewComments(self):
"Test that user can view all comments"
# Tests new functionality in UC-3 and UC-4
class Categories(APITestCase):
def test_categorizeExercise(self):
"test that categorizing exercise works"
......@@ -37,7 +54,7 @@ class Categories(APITestCase):
def test_sortExercise(self):
"test that sorting exercise works"
# Tests new functionality in UC-1
class NewWorkoutAsCoach(APITestCase):
def test_createWorkoutAsCoach(self):
"Check that a workout can be created as a coach"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment