Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
zesje
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Works on my machine
zesje
Commits
349d909d
Commit
349d909d
authored
5 years ago
by
Ruben Young On
Browse files
Options
Downloads
Patches
Plain Diff
Added PATCH call for multiple choice options
parent
80317831
No related branches found
Branches containing commit
No related tags found
1 merge request
!16
Add API tests, small fix for MultipleChoiceOption
Pipeline
#18156
passed
5 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/api/test_mc_option.py
+1
-1
1 addition, 1 deletion
tests/api/test_mc_option.py
zesje/api/mult_choice.py
+39
-34
39 additions, 34 deletions
zesje/api/mult_choice.py
with
40 additions
and
35 deletions
tests/api/test_mc_option.py
+
1
−
1
View file @
349d909d
...
@@ -108,7 +108,7 @@ def test_update_put(test_client, add_test_data):
...
@@ -108,7 +108,7 @@ def test_update_put(test_client, add_test_data):
'
name
'
:
'
test
'
'
name
'
:
'
test
'
}
}
result
=
test_client
.
p
ut
(
f
'
/api/mult-choice/
{
id
}
'
,
data
=
req2
)
result
=
test_client
.
p
atch
(
f
'
/api/mult-choice/
{
id
}
'
,
data
=
req2
)
data
=
json
.
loads
(
result
.
data
)
data
=
json
.
loads
(
result
.
data
)
assert
data
[
'
message
'
]
==
f
'
Multiple choice question with id
{
id
}
updated
'
assert
data
[
'
message
'
]
==
f
'
Multiple choice question with id
{
id
}
updated
'
...
...
This diff is collapsed.
Click to expand it.
zesje/api/mult_choice.py
+
39
−
34
View file @
349d909d
...
@@ -36,21 +36,13 @@ class MultipleChoice(Resource):
...
@@ -36,21 +36,13 @@ class MultipleChoice(Resource):
put_parser
.
add_argument
(
'
label
'
,
type
=
str
,
required
=
False
)
put_parser
.
add_argument
(
'
label
'
,
type
=
str
,
required
=
False
)
put_parser
.
add_argument
(
'
problem_id
'
,
type
=
int
,
required
=
True
)
# Used for FeedbackOption
put_parser
.
add_argument
(
'
problem_id
'
,
type
=
int
,
required
=
True
)
# Used for FeedbackOption
def
put
(
self
,
id
=
None
):
def
put
(
self
):
"""
Adds or updates a multiple choice option to the database
"""
Adds a multiple choice option to the database
If the parameter id is not present, a new multiple choice question
will be inserted with the data provided in the request body.
For each new multiple choice option, a feedback option that links to
For each new multiple choice option, a feedback option that links to
the multiple choice option is inserted into the database. The new
the multiple choice option is inserted into the database. The new
feedback option also refers to same problem as the MultipleChoiceOption
feedback option also refers to same problem as the MultipleChoiceOption
Parameters
----------
id: The id of the multiple choice option
"""
"""
args
=
self
.
put_parser
.
parse_args
()
args
=
self
.
put_parser
.
parse_args
()
# Get request arguments
# Get request arguments
...
@@ -60,36 +52,23 @@ class MultipleChoice(Resource):
...
@@ -60,36 +52,23 @@ class MultipleChoice(Resource):
label
=
args
[
'
label
'
]
label
=
args
[
'
label
'
]
problem_id
=
args
[
'
problem_id
'
]
problem_id
=
args
[
'
problem_id
'
]
# TODO: Set type here or add to request?
mc_type
=
'
mcq_widget
'
mc_type
=
'
mcq_widget
'
if
not
id
:
# Insert new empty feedback option that links to the same problem
# Insert new empty feedback option that links to the same problem
new_feedback_option
=
FeedbackOption
(
problem_id
=
problem_id
,
text
=
''
)
new_feedback_option
=
FeedbackOption
(
problem_id
=
problem_id
,
text
=
''
)
db
.
session
.
add
(
new_feedback_option
)
db
.
session
.
add
(
new_feedback_option
)
db
.
session
.
commit
()
db
.
session
.
commit
()
# Insert new entry into the database
mc_entry
=
MultipleChoiceOption
()
set_mc_data
(
mc_entry
,
name
,
x
,
y
,
mc_type
,
new_feedback_option
.
id
,
label
)
db
.
session
.
add
(
mc_entry
)
db
.
session
.
commit
()
return
dict
(
status
=
200
,
mult_choice_id
=
mc_entry
.
id
,
feedback_id
=
new_feedback_option
.
id
,
message
=
f
'
New multiple choice question with id
{
mc_entry
.
id
}
inserted.
'
+
f
'
New feedback option with id
{
new_feedback_option
.
id
}
inserted.
'
),
200
# Update existing entry otherwise
mc_entry
=
MultipleChoiceOption
.
query
.
get
(
id
)
if
not
mc_entry
:
# Insert new entry into the database
return
dict
(
status
=
404
,
message
=
f
"
Multiple choice question with id
{
id
}
does not exist
"
),
404
mc_entry
=
MultipleChoiceOption
()
set_mc_data
(
mc_entry
,
name
,
x
,
y
,
mc_type
,
new_feedback_option
.
id
,
label
)
set_mc_data
(
mc_entry
,
name
,
x
,
y
,
mc_type
,
mc_entry
.
feedback_id
,
label
)
db
.
session
.
add
(
mc_entry
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
dict
(
status
=
200
,
message
=
f
'
Multiple choice question with id
{
id
}
updated
'
),
200
return
dict
(
status
=
200
,
mult_choice_id
=
mc_entry
.
id
,
feedback_id
=
new_feedback_option
.
id
,
message
=
f
'
New multiple choice question with id
{
mc_entry
.
id
}
inserted.
'
+
f
'
New feedback option with id
{
new_feedback_option
.
id
}
inserted.
'
),
200
def
get
(
self
,
id
):
def
get
(
self
,
id
):
"""
Fetches multiple choice option from the database
"""
Fetches multiple choice option from the database
...
@@ -122,6 +101,32 @@ class MultipleChoice(Resource):
...
@@ -122,6 +101,32 @@ class MultipleChoice(Resource):
return
json
return
json
def
patch
(
self
,
id
):
"""
Updates a multiple choice option
Parameters
----------
id: The id of the multiple choice option in the database.s
"""
args
=
self
.
put_parser
.
parse_args
()
name
=
args
[
'
name
'
]
x
=
args
[
'
x
'
]
y
=
args
[
'
y
'
]
label
=
args
[
'
label
'
]
mc_type
=
'
mcq_widget
'
mc_entry
=
MultipleChoiceOption
.
query
.
get
(
id
)
if
not
mc_entry
:
return
dict
(
status
=
404
,
message
=
f
"
Multiple choice question with id
{
id
}
does not exist
"
),
404
set_mc_data
(
mc_entry
,
name
,
x
,
y
,
mc_type
,
mc_entry
.
feedback_id
,
label
)
db
.
session
.
commit
()
return
dict
(
status
=
200
,
message
=
f
'
Multiple choice question with id
{
id
}
updated
'
),
200
def
delete
(
self
,
id
):
def
delete
(
self
,
id
):
"""
Deletes a multiple choice option from the database.
"""
Deletes a multiple choice option from the database.
Also deletes the associated feedback option with this multiple choice option.
Also deletes the associated feedback option with this multiple choice option.
...
...
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