Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AKPlanning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
KIF
AKPlanning
Commits
7c148274
Commit
7c148274
authored
2 years ago
by
Benjamin Hättasch
Browse files
Options
Downloads
Patches
Plain Diff
Add test for interest counter API endpoint
Fix issue detected while creating test
parent
dfd48ae0
No related branches found
Branches containing commit
No related tags found
1 merge request
!141
Add view tests
Pipeline
#126994
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
AKSubmission/api.py
+4
-3
4 additions, 3 deletions
AKSubmission/api.py
AKSubmission/tests.py
+37
-1
37 additions, 1 deletion
AKSubmission/tests.py
with
41 additions
and
4 deletions
AKSubmission/api.py
+
4
−
3
View file @
7c148274
...
...
@@ -26,8 +26,8 @@ def increment_interest_counter(request, event_slug, pk, **kwargs):
"""
Increment interest counter for AK
"""
ak
=
AK
.
objects
.
get
(
pk
=
pk
)
if
ak
:
try
:
ak
=
AK
.
objects
.
get
(
pk
=
pk
)
# Check whether interest indication is currently allowed
current_timestamp
=
datetime
.
now
().
astimezone
(
ak
.
event
.
timezone
)
if
ak_interest_indication_active
(
ak
.
event
,
current_timestamp
):
...
...
@@ -35,4 +35,5 @@ def increment_interest_counter(request, event_slug, pk, **kwargs):
ak
.
save
()
return
Response
({
'
interest_counter
'
:
ak
.
interest_counter
},
status
=
status
.
HTTP_200_OK
)
return
Response
(
status
=
status
.
HTTP_403_FORBIDDEN
)
return
Response
(
status
=
status
.
HTTP_404_NOT_FOUND
)
except
AK
.
DoesNotExist
:
return
Response
(
status
=
status
.
HTTP_404_NOT_FOUND
)
This diff is collapsed.
Click to expand it.
AKSubmission/tests.py
+
37
−
1
View file @
7c148274
from
datetime
import
timedelta
from
django.test
import
TestCase
from
django.urls
import
reverse_lazy
from
django.utils.datetime_safe
import
datetime
from
AKModel.models
import
AK
,
AKSlot
from
AKModel.models
import
AK
,
AKSlot
,
Event
from
AKModel.tests
import
BasicViewTests
...
...
@@ -124,3 +127,36 @@ class ModelViewTests(BasicViewTests, TestCase):
self
.
_assert_message
(
response
,
"
Message to organizers successfully saved
"
)
self
.
assertEqual
(
AK
.
objects
.
get
(
pk
=
1
).
akorgamessage_set
.
count
(),
count_messages
+
1
,
msg
=
"
Message was not correctly saved
"
)
def
test_interest_api
(
self
):
interest_api_url
=
"
/kif42/api/ak/1/indicate-interest/
"
ak
=
AK
.
objects
.
get
(
pk
=
1
)
event
=
Event
.
objects
.
get
(
slug
=
'
kif42
'
)
ak_interest_counter
=
ak
.
interest_counter
response
=
self
.
client
.
get
(
interest_api_url
)
self
.
assertEqual
(
response
.
status_code
,
405
,
"
Should not be accessible via GET
"
)
event
.
interest_start
=
datetime
.
now
().
astimezone
(
event
.
timezone
)
+
timedelta
(
minutes
=-
10
)
event
.
interest_end
=
datetime
.
now
().
astimezone
(
event
.
timezone
)
+
timedelta
(
minutes
=+
10
)
event
.
save
()
response
=
self
.
client
.
post
(
interest_api_url
)
self
.
assertEqual
(
response
.
status_code
,
200
,
f
"
API end point not working (
{
interest_api_url
}
)
"
)
self
.
assertEqual
(
AK
.
objects
.
get
(
pk
=
1
).
interest_counter
,
ak_interest_counter
+
1
,
"
Counter was not increased
"
)
event
.
interest_end
=
datetime
.
now
().
astimezone
(
event
.
timezone
)
+
timedelta
(
minutes
=-
2
)
event
.
save
()
response
=
self
.
client
.
post
(
interest_api_url
)
self
.
assertEqual
(
response
.
status_code
,
403
,
"
API end point still reachable even though interest indication window ended ({interest_api_url})
"
)
self
.
assertEqual
(
AK
.
objects
.
get
(
pk
=
1
).
interest_counter
,
ak_interest_counter
+
1
,
"
Counter was increased even though interest indication window ended
"
)
invalid_interest_api_url
=
"
/kif42/api/ak/-1/indicate-interest/
"
response
=
self
.
client
.
post
(
invalid_interest_api_url
)
self
.
assertEqual
(
response
.
status_code
,
404
,
f
"
Invalid URL reachable (
{
interest_api_url
}
)
"
)
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