Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
geant-swd
compendium-v2
Commits
61c62414
Commit
61c62414
authored
2 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
add test & test data for /api/staff endpoint
parent
34163d9a
No related branches found
No related tags found
1 merge request
!6
Feature/comp 125 staffing graph
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/conftest.py
+46
-0
46 additions, 0 deletions
test/conftest.py
test/test_staff.py
+13
-0
13 additions, 0 deletions
test/test_staff.py
with
59 additions
and
0 deletions
test/conftest.py
+
46
−
0
View file @
61c62414
import
json
import
os
import
tempfile
import
random
import
pytest
import
compendium_v2
...
...
@@ -146,6 +147,51 @@ def test_funding_source_data():
)
@pytest.fixture
def
test_staff_data
():
# generate generator of random data that ensures a given nren only shows up once a year
def
_generate_rows
():
for
nren
in
[
"
nren
"
+
str
(
i
)
for
i
in
range
(
1
,
100
)]:
# 100 nrens
for
year
in
range
(
2016
,
2021
):
# 5 years
yield
{
"
nren
"
:
nren
,
"
year
"
:
year
,
"
permanent_fte
"
:
random
.
randint
(
0
,
100
),
"
subcontracted_fte
"
:
random
.
randint
(
0
,
100
),
"
technical_fte
"
:
random
.
randint
(
0
,
100
),
"
non_technical_fte
"
:
random
.
randint
(
0
,
100
)
}
with
db
.
session_scope
()
as
session
:
data
=
list
(
_generate_rows
())
nren_dict
=
{
nren_name
:
model
.
NREN
(
name
=
nren_name
)
for
nren_name
in
[
d
[
'
nren
'
]
for
d
in
data
]}
session
.
add_all
(
nren_dict
.
values
())
for
row
in
data
:
nren
=
nren_dict
[
row
[
"
nren
"
]]
year
=
row
[
"
year
"
]
permanent_fte
=
row
[
"
permanent_fte
"
]
subcontracted_fte
=
row
[
"
subcontracted_fte
"
]
technical_fte
=
row
[
"
technical_fte
"
]
non_technical_fte
=
row
[
"
non_technical_fte
"
]
session
.
add
(
model
.
NrenStaff
(
nren
=
nren
,
year
=
year
,
permanent_fte
=
permanent_fte
,
subcontracted_fte
=
subcontracted_fte
,
technical_fte
=
technical_fte
,
non_technical_fte
=
non_technical_fte
)
)
@pytest.fixture
def
data_config_filename
(
dummy_config
):
with
tempfile
.
NamedTemporaryFile
()
as
f
:
...
...
This diff is collapsed.
Click to expand it.
test/test_staff.py
0 → 100644
+
13
−
0
View file @
61c62414
import
json
import
jsonschema
from
compendium_v2.routes.staff
import
STAFF_RESPONSE_SCHEMA
def
test_staff_response
(
client
,
test_staff_data
):
rv
=
client
.
get
(
'
/api/staff/
'
,
headers
=
{
'
Accept
'
:
[
'
application/json
'
]})
assert
rv
.
status_code
==
200
result
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
result
,
STAFF_RESPONSE_SCHEMA
)
assert
result
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