Commit 881f6de9 authored by Vegard Murvold Sporstøl's avatar Vegard Murvold Sporstøl
Browse files

added tests for rememberme and workout files

parent 35836b8a
Pipeline #128047 passed with stages
in 2 minutes and 41 seconds
from users.tests.registration import * from users.tests.registration import *
from users.tests.userserializer import * from users.tests.userserializer import *
from users.tests.twowaydomain import * from users.tests.twowaydomain import *
\ No newline at end of file from users.tests.rememberme import *
\ No newline at end of file
import json import json
from django.test import TestCase, RequestFactory, Client from django.test import TestCase, RequestFactory, Client
from users.serializers import UserSerializer
from users.models import User from users.models import User
url = "/api/users/" url = "/api/users/"
......
import json
from django.test import TestCase, RequestFactory, Client
from rest_framework.test import APIRequestFactory, APIClient
from users.serializers import UserSerializer
from users.models import User
from workouts.views import RememberMe
url = '/api/remember_me/'
class RemembermeTestCase(TestCase):
"""Django test for the rememberme functionality
tests:
set_up: Set up everything needed for the test
test_rememberme: Tests creation of rememberme for authenticated user
"""
def setUp(self):
self.client = APIClient()
self.user = User.objects.create(username="user",password="test")
self.client.force_authenticate(user=self.user)
def test_rememberme(self):
data = {"username": "user", "password": "test"}
response = self.client.get(url, data)
self.assertEqual(response.status_code, 200)
\ No newline at end of file
from workouts.tests.permissions import * from workouts.tests.permissions import *
from workouts.tests.workouts import * from workouts.tests.workouts import *
from workouts.tests.visibility import * from workouts.tests.visibility import *
from workouts.tests.features import * from workouts.tests.features import *
\ No newline at end of file from workouts.tests.workoutfiles import *
import json
from django.test import TestCase, RequestFactory, Client
from rest_framework.test import APIRequestFactory, APIClient
from workouts.models import Workout, Exercise, ExerciseInstance, WorkoutFile
from workouts.serializers import WorkoutSerializer
from users.models import User
class WorkoutFilesTestCase(TestCase):
"""Django test for perserving the functionality of workout-files
tests:
set_up: Set up everything needed for the test
"""
def setUp(self):
self.user = User.objects.create(username="user")
self.workout = Workout.objects.create(name="workout", date="2021-03-06T18:00:00Z", notes="note", owner=self.user, visibility="PU")
self.exercise = Exercise.objects.create(name="exercise", description="test", unit="test")
def test_workout_files(self):
data = {'name': 'workout', 'notes': 'note', 'visibility': 'PU',
'date': '2021-03-06T18:00:00.000Z',
'exercise_instances': [{'exercise': self.exercise, 'sets':12, 'number':12}],
'files': [{'owner': self.user, 'file':'workouts/1/document.pdf'}]
}
WorkoutSerializer(data).update(self.workout, data)
instance = ExerciseInstance.objects.filter(workout=self.workout).first()
self.assertEqual(instance.exercise, self.exercise)
files = WorkoutFile.objects.filter(workout=self.workout).first()
self.assertEqual(files.owner, self.user)
self.assertEqual(files.file, 'workouts/1/document.pdf')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment