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
d764be89
Commit
d764be89
authored
5 years ago
by
Ruben Young On
Browse files
Options
Downloads
Patches
Plain Diff
Changed fixture location
parent
55d8d521
No related branches found
Branches containing commit
No related tags found
1 merge request
!16
Add API tests, small fix for MultipleChoiceOption
Pipeline
#17831
failed
5 years ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/api/test_exams.py
+0
-52
0 additions, 52 deletions
tests/api/test_exams.py
tests/api/test_mult_choice.py
+4
-62
4 additions, 62 deletions
tests/api/test_mult_choice.py
tests/conftest.py
+55
-0
55 additions, 0 deletions
tests/conftest.py
with
59 additions
and
114 deletions
tests/api/test_exams.py
+
0
−
52
View file @
d764be89
import
pytest
from
flask
import
json
from
flask
import
Flask
from
zesje.api
import
api_bp
from
zesje.database
import
db
,
Exam
,
Problem
,
ProblemWidget
@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_test_data
()
app
.
register_blueprint
(
api_bp
,
url_prefix
=
'
/api
'
)
return
app
@pytest.fixture
()
def
test_client
(
app
):
client
=
app
.
test_client
()
yield
client
def
mco_json
():
...
...
@@ -44,26 +12,6 @@ def mco_json():
}
def
add_test_data
():
exam1
=
Exam
(
id
=
3
,
name
=
'
exam 1
'
,
finalized
=
False
)
db
.
session
.
add
(
exam1
)
db
.
session
.
commit
()
problem1
=
Problem
(
id
=
3
,
name
=
'
Problem 1
'
,
exam_id
=
3
)
db
.
session
.
add
(
problem1
)
db
.
session
.
commit
()
problem_widget_1
=
ProblemWidget
(
id
=
3
,
name
=
'
problem widget
'
,
problem_id
=
3
,
page
=
2
,
width
=
100
,
height
=
150
,
x
=
40
,
y
=
200
,
type
=
'
problem_widget
'
)
db
.
session
.
add
(
problem_widget_1
)
db
.
session
.
commit
()
#####################
# Actual test #
#####################
def
test_get_exams
(
test_client
):
mc_option_1
=
{
'
x
'
:
100
,
...
...
This diff is collapsed.
Click to expand it.
tests/api/test_mult_choice.py
+
4
−
62
View file @
d764be89
import
pytest
from
flask
import
json
from
flask
import
Flask
from
zesje.api
import
api_bp
from
zesje.database
import
db
,
Exam
,
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_test_data
()
app
.
register_blueprint
(
api_bp
,
url_prefix
=
'
/api
'
)
return
app
@pytest.fixture
()
def
test_client
(
app
):
client
=
app
.
test_client
()
yield
client
def
add_test_data
():
exam1
=
Exam
(
id
=
1
,
name
=
'
exam 1
'
,
finalized
=
False
)
exam2
=
Exam
(
id
=
2
,
name
=
'
exam 2
'
,
finalized
=
True
)
db
.
session
.
add
(
exam1
)
db
.
session
.
add
(
exam2
)
db
.
session
.
commit
()
problem1
=
Problem
(
id
=
1
,
name
=
'
Problem 1
'
,
exam_id
=
1
)
problem2
=
Problem
(
id
=
2
,
name
=
'
Problem 2
'
,
exam_id
=
2
)
db
.
session
.
add
(
problem1
)
db
.
session
.
add
(
problem2
)
db
.
session
.
commit
()
def
mco_json
():
...
...
@@ -59,17 +12,6 @@ def mco_json():
}
@pytest.fixture
def
mock_exam_finalized
(
monkeypatch
):
monkeypatch
.
setattr
(
db
.
exam
,
'
finalized
'
,
True
)
monkeypatch
.
setattr
(
db
.
mult_choice
.
feedback
.
problem
,
'
exam
'
,
None
)
###################
# Actual tests #
###################
def
test_get_no_exam
(
test_client
):
result
=
test_client
.
get
(
'
/api/mult-choice/1
'
)
data
=
json
.
loads
(
result
.
data
)
...
...
@@ -83,10 +25,10 @@ def test_add_exam(test_client):
data
=
json
.
loads
(
response
.
data
)
assert
data
[
'
message
'
]
==
'
New multiple choice question with id
1
inserted.
'
\
assert
data
[
'
message
'
]
==
'
New multiple choice question with id
4
inserted.
'
\
+
'
New feedback option with id 1 inserted.
'
assert
data
[
'
mult_choice_id
'
]
==
1
assert
data
[
'
mult_choice_id
'
]
==
4
assert
data
[
'
status
'
]
==
200
...
...
@@ -102,7 +44,7 @@ def test_add_get(test_client):
data
=
json
.
loads
(
result
.
data
)
exp_resp
=
{
'
id
'
:
2
,
'
id
'
:
5
,
'
name
'
:
'
test
'
,
'
x
'
:
100
,
'
y
'
:
40
,
...
...
@@ -150,7 +92,7 @@ def test_delete(test_client):
def
test_delete_not_present
(
test_client
):
id
=
5
id
=
100
response
=
test_client
.
delete
(
f
'
/api/mult-choice/
{
id
}
'
)
data
=
json
.
loads
(
response
.
data
)
...
...
This diff is collapsed.
Click to expand it.
tests/conftest.py
+
55
−
0
View file @
d764be89
...
...
@@ -2,8 +2,63 @@ import os
import
pytest
from
zesje.api
import
api_bp
from
zesje.database
import
db
,
Exam
,
Problem
,
ProblemWidget
from
flask
import
Flask
# Adapted from https://stackoverflow.com/a/46062148/1062698
@pytest.fixture
def
datadir
():
return
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'
data
'
)
def
add_test_data
():
exam1
=
Exam
(
id
=
1
,
name
=
'
exam 1
'
,
finalized
=
False
)
exam2
=
Exam
(
id
=
2
,
name
=
'
exam 2
'
,
finalized
=
True
)
exam3
=
Exam
(
id
=
3
,
name
=
'
exam 1
'
,
finalized
=
False
)
db
.
session
.
add
(
exam1
)
db
.
session
.
add
(
exam2
)
db
.
session
.
add
(
exam3
)
db
.
session
.
commit
()
problem1
=
Problem
(
id
=
1
,
name
=
'
Problem 1
'
,
exam_id
=
1
)
problem2
=
Problem
(
id
=
2
,
name
=
'
Problem 2
'
,
exam_id
=
2
)
problem3
=
Problem
(
id
=
3
,
name
=
'
Problem 1
'
,
exam_id
=
3
)
db
.
session
.
add
(
problem1
)
db
.
session
.
add
(
problem2
)
db
.
session
.
add
(
problem3
)
db
.
session
.
commit
()
problem_widget_1
=
ProblemWidget
(
id
=
3
,
name
=
'
problem widget
'
,
problem_id
=
3
,
page
=
2
,
width
=
100
,
height
=
150
,
x
=
40
,
y
=
200
,
type
=
'
problem_widget
'
)
db
.
session
.
add
(
problem_widget_1
)
db
.
session
.
commit
()
@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_test_data
()
app
.
register_blueprint
(
api_bp
,
url_prefix
=
'
/api
'
)
return
app
@pytest.fixture
()
def
test_client
(
app
):
client
=
app
.
test_client
()
yield
client
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