Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Håvard Farestveit
tdt4242-base
Commits
4acf62ce
Commit
4acf62ce
authored
Apr 19, 2021
by
olavhdi
Browse files
move workouts tests, add workoutserializer tests
parent
4ff469bb
Pipeline
#129344
passed with stage
in 31 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/secfit/workouts/tests/__init__.py
0 → 100644
View file @
4acf62ce
from
workouts.tests.workouts_serializer
import
WorkoutSerializerTestCase
from
workouts.tests.test
import
IsOwnerTestCase
,
IsOwnerOfWorkoutTestCase
,
IsCoachAndVisibleToCoachTestCase
,
IsCoachOfWorkoutAndVisibleToCoachTestCase
,
IsPublicTestCase
,
IsWorkoutPublicTestCase
,
IsReadOnlyTestCase
\ No newline at end of file
backend/secfit/workouts/tests.py
→
backend/secfit/workouts/tests
/test
.py
View file @
4acf62ce
File moved
backend/secfit/workouts/tests/test_data.py
0 → 100644
View file @
4acf62ce
test_data
=
{
"name"
:
"testCreate"
,
"date"
:
"2021-03-20"
,
"owner_id"
:
"1"
,
"pk"
:
"1"
,
"exercise_instances"
:
{},
}
test_data1
=
{
"name"
:
"testCreate"
,
"date"
:
"2021-03-20"
,
"owner_id"
:
"1"
,
"pk"
:
"1"
,
"exercise_instances"
:
{},
}
test_exercise
=
{
"id"
:
"1"
,
"name"
:
"walk"
,
"description"
:
"hard"
,
"unit"
:
"1"
,
"instances"
:
{}
}
backend/secfit/workouts/tests/workouts_serializer.py
0 → 100644
View file @
4acf62ce
from
django.test
import
TestCase
from
django.contrib.auth
import
get_user_model
from
workouts.serializers
import
WorkoutSerializer
,
ExerciseSerializer
from
workouts.models
import
Workout
,
Exercise
,
ExerciseInstance
from
workouts.tests.test_data
import
test_data
,
test_data1
,
test_exercise
class
WorkoutSerializerTestCase
(
TestCase
):
"""WorkoutSerializer test class"""
def
setUp
(
self
):
self
.
owner_model
=
get_user_model
()
owner
=
self
.
owner_model
(
username
=
"test"
,
email
=
"test@test.com"
,
phone_number
=
"12345678"
,
country
=
"Norway"
,
city
=
"Oslo"
,
street_address
=
"address 10"
)
password
=
"password"
owner
.
set_password
(
password
)
owner
.
save
()
self
.
workout
=
Workout
(
name
=
"testCreate"
,
date
=
"2021-03-20"
,
owner
=
owner
,
owner_id
=
"1"
,
pk
=
1
,
)
self
.
exercise
=
Exercise
(
name
=
"walk"
,
description
=
"hard"
,
unit
=
"1"
,
)
self
.
instance
=
ExerciseInstance
(
workout
=
self
.
workout
,
exercise
=
self
.
exercise
,
sets
=
10
,
number
=
10
,
id
=
1
,
exercise_id
=
1
,
)
def
test_create
(
self
):
workout_create
=
WorkoutSerializer
.
create
(
WorkoutSerializer
(),
validated_data
=
test_data
)
self
.
assertEqual
(
workout_create
,
self
.
workout
)
def
test_update
(
self
):
"""
Compare mocked exercise and workout to serialized versions respectively
"""
e
=
test_data1
.
copy
()
e
[
"exercise_instances"
]
=
{
0
:
{
"sets"
:
"10"
,
"number"
:
"10"
,
"exercise_id"
:
"1"
,
}}
ExerciseSerializer
.
create
(
ExerciseSerializer
(),
validated_data
=
test_exercise
)
workout_create
=
WorkoutSerializer
.
create
(
WorkoutSerializer
(),
validated_data
=
test_data1
.
copy
())
# Adds the exercise instance to the workout
workout_updated
=
WorkoutSerializer
.
update
(
WorkoutSerializer
(),
instance
=
workout_create
,
validated_data
=
e
)
# Remove state identifier from the objects
delattr
(
workout_updated
,
"_state"
)
delattr
(
self
.
workout
,
"_state"
)
real_exercise
=
ExerciseInstance
.
objects
.
all
()[
0
]
delattr
(
real_exercise
,
"_state"
)
mock_exercise
=
self
.
instance
delattr
(
mock_exercise
,
"_state"
)
# Compare the fields in the objects directly using vars()
self
.
assertEqual
(
vars
(
workout_updated
),
vars
(
self
.
workout
))
self
.
assertEqual
(
vars
(
real_exercise
),
vars
(
mock_exercise
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment