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
4f47dfe1
Commit
4f47dfe1
authored
5 years ago
by
Ruben Young On
Browse files
Options
Downloads
Patches
Plain Diff
Added tests
parent
5a4b707d
No related branches found
Branches containing commit
No related tags found
1 merge request
!16
Add API tests, small fix for MultipleChoiceOption
Pipeline
#17772
passed
5 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_api_mult_choice.py
+148
-0
148 additions, 0 deletions
tests/test_api_mult_choice.py
zesje/api/mult_choice.py
+1
-1
1 addition, 1 deletion
zesje/api/mult_choice.py
with
149 additions
and
1 deletion
tests/test_api_mult_choice.py
0 → 100644
+
148
−
0
View file @
4f47dfe1
import
pytest
from
flask
import
Flask
,
json
from
zesje.api
import
api_bp
from
zesje.database
import
db
,
Exam
,
Problem
def
mco_json
():
return
{
'
x
'
:
100
,
'
y
'
:
40
,
'
problem_id
'
:
1
,
'
page
'
:
1
,
'
label
'
:
'
a
'
,
'
name
'
:
'
test
'
}
def
add_exam
(
db
,
finalized
=
False
):
# Exam with id 1
exam
=
Exam
(
name
=
'
exam
'
,
finalized
=
finalized
)
db
.
session
.
add
(
exam
)
db
.
session
.
commit
()
return
exam
def
add_problem
(
db
,
exam_id
=
1
):
problem
=
Problem
(
name
=
'
problem
'
,
exam_id
=
exam_id
)
db
.
session
.
add
(
problem
)
db
.
session
.
commit
()
return
problem
@pytest.fixture
(
scope
=
"
module
"
)
def
app
():
app
=
Flask
(
__name__
,
static_folder
=
None
)
app
.
config
.
update
(
SQLALCHEMY_DATABASE_URI
=
'
sqlite:///:memory:
'
,
SQLALCHEMY_TRACK_MODIFICATIONS
=
False
# Suppress future deprecation warning
)
db
.
init_app
(
app
)
with
app
.
app_context
():
db
.
create_all
()
add_problem
(
db
)
add_exam
(
db
)
app
.
register_blueprint
(
api_bp
,
url_prefix
=
'
/api
'
)
return
app
@pytest.fixture
def
client
(
app
):
client
=
app
.
test_client
()
yield
client
def
test_get_no_exam
(
client
):
result
=
client
.
get
(
'
/api/mult-choice/1
'
)
data
=
json
.
loads
(
result
.
data
)
assert
data
[
'
message
'
]
==
"
Multiple choice question with id 1 does not exist.
"
def
test_add_exam
(
client
):
req
=
mco_json
()
response
=
client
.
put
(
'
/api/mult-choice/
'
,
data
=
req
)
data
=
json
.
loads
(
response
.
data
)
assert
data
[
'
message
'
]
==
'
New multiple choice question with id 1 inserted.
'
\
+
'
New feedback option with id 1 inserted.
'
assert
data
[
'
mult_choice_id
'
]
==
1
assert
data
[
'
status
'
]
==
200
def
test_add_get
(
client
):
req
=
mco_json
()
response
=
client
.
put
(
'
/api/mult-choice/
'
,
data
=
req
)
data
=
json
.
loads
(
response
.
data
)
id
=
data
[
'
mult_choice_id
'
]
result
=
client
.
get
(
f
'
/api/mult-choice/
{
id
}
'
)
data
=
json
.
loads
(
result
.
data
)
exp_resp
=
{
'
id
'
:
2
,
'
name
'
:
'
test
'
,
'
x
'
:
100
,
'
y
'
:
40
,
'
type
'
:
'
mcq_widget
'
,
'
feedback_id
'
:
2
,
'
label
'
:
'
a
'
,
}
assert
exp_resp
==
data
def
test_update_put
(
client
):
req
=
mco_json
()
response
=
client
.
put
(
'
/api/mult-choice/
'
,
data
=
req
)
data
=
json
.
loads
(
response
.
data
)
id
=
data
[
'
mult_choice_id
'
]
req2
=
{
'
x
'
:
120
,
'
y
'
:
50
,
'
problem_id
'
:
4
,
'
page
'
:
1
,
'
label
'
:
'
b
'
,
'
name
'
:
'
test
'
}
result
=
client
.
put
(
f
'
/api/mult-choice/
{
id
}
'
,
data
=
req2
)
data
=
json
.
loads
(
result
.
data
)
assert
data
[
'
message
'
]
==
f
'
Multiple choice question with id
{
id
}
updated
'
def
test_delete
(
client
):
req
=
mco_json
()
response
=
client
.
put
(
'
/api/mult-choice/
'
,
data
=
req
)
data
=
json
.
loads
(
response
.
data
)
id
=
data
[
'
mult_choice_id
'
]
response
=
client
.
delete
(
f
'
/api/mult-choice/
{
id
}
'
)
data
=
json
.
loads
(
response
.
data
)
assert
data
[
'
status
'
]
==
200
def
test_delete_not_present
(
client
):
id
=
5
response
=
client
.
delete
(
f
'
/api/mult-choice/
{
id
}
'
)
data
=
json
.
loads
(
response
.
data
)
assert
data
[
'
message
'
]
==
f
'
Multiple choice question with id
{
id
}
does not exist.
'
This diff is collapsed.
Click to expand it.
zesje/api/mult_choice.py
+
1
−
1
View file @
4f47dfe1
...
...
@@ -86,7 +86,7 @@ class MultipleChoice(Resource):
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
,
label
)
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
...
...
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