Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Backend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
swp-unisport
team-warumkeinrust
Backend
Commits
69008fa9
Commit
69008fa9
authored
3 years ago
by
borzechof99
Browse files
Options
Downloads
Patches
Plain Diff
Add some Testing
parent
ebe2e3dd
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
unisportomat/quiz/serializers.py
+1
-1
1 addition, 1 deletion
unisportomat/quiz/serializers.py
unisportomat/quiz/tests.py
+106
-0
106 additions, 0 deletions
unisportomat/quiz/tests.py
unisportomat/quiz/views.py
+6
-3
6 additions, 3 deletions
unisportomat/quiz/views.py
with
113 additions
and
4 deletions
unisportomat/quiz/serializers.py
+
1
−
1
View file @
69008fa9
...
...
@@ -318,7 +318,7 @@ class SnackTivityListSerializer(serializers.BaseSerializer):
{
"
id
"
:
obj
.
pk
,
"
text_de
"
:
obj
.
text_de
,
"
text_en
"
:
obj
.
text_en
,
"
text_en
"
:
obj
.
text_en
or
""
,
"
has_image
"
:
has_image
,
}
)
...
...
This diff is collapsed.
Click to expand it.
unisportomat/quiz/tests.py
+
106
−
0
View file @
69008fa9
...
...
@@ -3,6 +3,7 @@
import
os
import
shutil
import
tempfile
import
shutil
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
django.core.management
import
call_command
...
...
@@ -392,8 +393,13 @@ class APITest(APITestCase):
"
criteria.json
"
,
"
criterion_ratings.json
"
,
"
questions.json
"
,
"
knowledge_snacks.json
"
,
"
calls_to_move.json
"
,
]
shutil
.
copy
(
"
quiz/fixtures/images/logo.png
"
,
"
media/
"
)
shutil
.
copy
(
"
quiz/fixtures/images/test_image.png
"
,
"
media/
"
)
def
test_get_sport_returns_correct_data
(
self
):
"""
Test the API endpoint /sport/{id}
"""
response
=
self
.
client
.
get
(
reverse
(
"
small-sport-list-detail
"
,
kwargs
=
{
"
pk
"
:
1
}))
...
...
@@ -635,6 +641,106 @@ class APITest(APITestCase):
self
.
assertEqual
(
response
.
data
[
"
results
"
],
[])
def
test_snack_get
(
self
):
"""
Test GET of Snack
"""
response
=
self
.
client
.
get
(
reverse
(
"
snack-list
"
),
format
=
"
json
"
)
self
.
assertEqual
(
len
(
response
.
data
[
"
results
"
]),
1
)
self
.
assertEqual
(
response
.
data
[
"
results
"
][
0
][
"
text_de
"
],
"
Dass Treppensteigen fast 5x so viele Kalorien verbrennt, als die Nutzung des Aufzuges?
"
,
)
self
.
assertEqual
(
response
.
data
[
"
results
"
][
0
][
"
text_en
"
],
""
)
self
.
assertEqual
(
response
.
data
[
"
results
"
][
0
][
"
has_image
"
],
True
)
# Test Detail GET as well
response
=
self
.
client
.
get
(
reverse
(
"
snack-detail
"
,
kwargs
=
{
"
pk
"
:
1
}),
format
=
"
json
"
)
self
.
assertEqual
(
response
.
data
[
"
text_de
"
],
"
Dass Treppensteigen fast 5x so viele Kalorien verbrennt, als die Nutzung des Aufzuges?
"
,
)
self
.
assertEqual
(
response
.
data
[
"
text_en
"
],
""
)
self
.
assertEqual
(
response
.
data
[
"
has_image
"
],
True
)
self
.
assertNotEqual
(
response
.
data
[
"
image
"
],
""
)
def
test_snack_remove_image
(
self
):
"""
Test whether the image of snack can be deleted
"""
response
=
self
.
client
.
get
(
reverse
(
"
snack-detail
"
,
kwargs
=
{
"
pk
"
:
1
}),
format
=
"
json
"
)
self
.
assertNotEqual
(
response
.
data
[
"
image
"
],
""
)
self
.
client
.
patch
(
reverse
(
"
snack-detail
"
,
kwargs
=
{
"
pk
"
:
1
}),
format
=
"
json
"
,
data
=
{
"
image
"
:
""
,
"
image_type
"
:
""
},
)
response
=
self
.
client
.
get
(
reverse
(
"
snack-detail
"
,
kwargs
=
{
"
pk
"
:
1
}),
format
=
"
json
"
)
self
.
assertEqual
(
response
.
data
[
"
image
"
],
""
)
def
test_activity_get
(
self
):
"""
Test GET of activity
"""
response
=
self
.
client
.
get
(
reverse
(
"
activity-list
"
),
format
=
"
json
"
)
self
.
assertEqual
(
len
(
response
.
data
[
"
results
"
]),
1
)
self
.
assertEqual
(
response
.
data
[
"
results
"
][
0
][
"
text_de
"
],
"
Kreise deine Arme vor der nächsten Frage 3x nach hinten
"
,
)
self
.
assertEqual
(
response
.
data
[
"
results
"
][
0
][
"
text_en
"
],
""
)
self
.
assertEqual
(
response
.
data
[
"
results
"
][
0
][
"
has_image
"
],
True
)
# Test Detail GET as well
response
=
self
.
client
.
get
(
reverse
(
"
activity-detail
"
,
kwargs
=
{
"
pk
"
:
1
}),
format
=
"
json
"
)
self
.
assertEqual
(
response
.
data
[
"
text_de
"
],
"
Kreise deine Arme vor der nächsten Frage 3x nach hinten
"
,
)
self
.
assertEqual
(
response
.
data
[
"
text_en
"
],
""
)
self
.
assertEqual
(
response
.
data
[
"
has_image
"
],
True
)
self
.
assertNotEqual
(
response
.
data
[
"
image
"
],
""
)
def
test_activity_remove_image
(
self
):
"""
Test whether the image of activity can be deleted
"""
response
=
self
.
client
.
get
(
reverse
(
"
activity-detail
"
,
kwargs
=
{
"
pk
"
:
1
}),
format
=
"
json
"
)
self
.
assertNotEqual
(
response
.
data
[
"
image
"
],
""
)
self
.
client
.
patch
(
reverse
(
"
activity-detail
"
,
kwargs
=
{
"
pk
"
:
1
}),
format
=
"
json
"
,
data
=
{
"
image
"
:
""
,
"
image_type
"
:
""
},
)
response
=
self
.
client
.
get
(
reverse
(
"
activity-detail
"
,
kwargs
=
{
"
pk
"
:
1
}),
format
=
"
json
"
)
self
.
assertEqual
(
response
.
data
[
"
image
"
],
""
)
class
QuestionOrderEntry_Test
(
TestCase
):
"""
...
...
This diff is collapsed.
Click to expand it.
unisportomat/quiz/views.py
+
6
−
3
View file @
69008fa9
...
...
@@ -99,11 +99,14 @@ class SmallSportListView(viewsets.ViewSet):
"
is_filled
"
:
"
pk
"
,
"
-is_filled
"
:
"
-pk
"
,
}
order_by
=
"
pk
"
if
"
ordering
"
in
request
.
query_params
.
keys
():
order_by
=
order_by_dict
[
request
.
query_params
.
get
(
"
ordering
"
)]
# TODO: Maybe care for is_filled ordering
sports
=
Sport
.
objects
.
all
().
order_by
(
order_by_dict
[
request
.
query_params
.
get
(
"
ordering
"
)]
)
sports
=
Sport
.
objects
.
all
().
order_by
(
order_by
)
sports
=
paginator
.
paginate_queryset
(
sports
,
request
)
is_filled_tuples
=
[]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment