Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pvk-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
amiv
pvk-tool
Commits
715c829c
Commit
715c829c
authored
Dec 05, 2017
by
Alexander Dietmüller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug: Signups for one course don't influence other course anymore
parent
19a1d6d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
13 deletions
+43
-13
Backend/signups.py
Backend/signups.py
+9
-10
Backend/tests/test_signups.py
Backend/tests/test_signups.py
+34
-3
No files found.
Backend/signups.py
View file @
715c829c
...
...
@@ -13,6 +13,7 @@ import json
from
functools
import
wraps
from
itertools
import
chain
from
bson
import
ObjectId
from
flask
import
current_app
,
abort
from
eve.methods.get
import
getitem_internal
from
eve.methods.patch
import
patch_internal
...
...
@@ -94,7 +95,10 @@ def update_signups(course):
# Next, count current signups not on waiting list
collection
=
current_app
.
data
.
driver
.
db
[
'signups'
]
taken_spots
=
collection
.
count
({
'status'
:
{
'$ne'
:
'waiting'
}})
taken_spots
=
collection
.
count
({
'course'
:
ObjectId
(
str
(
course
)),
'status'
:
{
'$ne'
:
'waiting'
}
})
available_spots
=
total_spots
-
taken_spots
...
...
@@ -108,17 +112,12 @@ def update_signups(course):
sort
=
[(
'_updated'
,
1
),
(
'nethz'
,
1
)],
limit
=
available_spots
)
signups_to_update
=
[
str
(
item
[
'_id'
])
for
item
in
signups
if
item
[
'status'
]
==
'waiting'
]
signup_ids
=
[
item
[
'_id'
]
for
item
in
signups
]
for
signup_id
in
signups_to_update
:
patch_internal
(
'signups'
,
_id
=
signup_id
,
payload
=
{
'status'
:
'reserved'
},
concurrency_check
=
False
,
skip_validation
=
True
)
collection
.
update_many
({
'_id'
:
{
'$in'
:
signup_ids
}},
{
'$set'
:
{
'status'
:
'reserved'
}})
return
signups_to_update
return
[
str
(
item
)
for
item
in
signup_ids
]
def
mark_as_paid
(
payments
):
...
...
Backend/tests/test_signups.py
View file @
715c829c
...
...
@@ -15,12 +15,14 @@ from signups import update_signups
def
test_success
(
app
):
"""If there are enough spots, the status will be 'reserved'."""
with
app
.
admin
():
# Admin so we don't need to care about nethz
# Create fake courses to sign up to
# Create fake courses to sign up to
with
app
.
admin
():
course_id
=
str
(
app
.
data
.
driver
.
db
[
'courses'
].
insert
({
'spots'
:
10
}))
# Sign up as user
with
app
.
user
(
nethz
=
'nethz'
):
signup
=
{
'nethz'
:
'
Something
'
,
'nethz'
:
'
nethz
'
,
'course'
:
course_id
,
}
...
...
@@ -96,6 +98,35 @@ def test_not_enough_spots(app):
assert
second_response
[
'status'
]
==
'waiting'
def
test_course_independence
(
app
):
"""Test that signups of one course don't influence another.
There was a bug in the code that lead to counting any signup for any
course. This test should ensure it doesn't happen again.
"""
with
app
.
admin
():
# Course with a free spot
main_course
=
app
.
data
.
driver
.
db
[
'courses'
].
insert
({
'spots'
:
1
})
# Other course that will get signups
other_course
=
app
.
data
.
driver
.
db
[
'courses'
].
insert
({
'spots'
:
5
})
for
_
in
range
(
5
):
app
.
data
.
driver
.
db
[
'signups'
].
insert
({
'course'
:
other_course
})
# Sign up to course
signup
=
{
'nethz'
:
'Something'
,
'course'
:
str
(
main_course
),
}
response
=
app
.
client
.
post
(
'/signups'
,
data
=
signup
,
assert_status
=
201
)
# The other signups should have no influence
assert
response
[
'status'
]
==
'reserved'
def
test_update_spots
(
app
):
"""Test the main update function.
...
...
Write
Preview
Markdown
is supported
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