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
431ea61e
Commit
431ea61e
authored
1 year ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Fix dump_survey_model test
parent
fc154dbe
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compendium_v2/migrations/dump_survey_model.py
+8
-4
8 additions, 4 deletions
compendium_v2/migrations/dump_survey_model.py
test/test_dump_survey_model.py
+9
-5
9 additions, 5 deletions
test/test_dump_survey_model.py
with
17 additions
and
9 deletions
compendium_v2/migrations/dump_survey_model.py
+
8
−
4
View file @
431ea61e
...
@@ -24,13 +24,19 @@ import compendium_v2
...
@@ -24,13 +24,19 @@ import compendium_v2
from
compendium_v2.environment
import
setup_logging
from
compendium_v2.environment
import
setup_logging
from
compendium_v2.db
import
db
from
compendium_v2.db
import
db
from
compendium_v2.config
import
load
from
compendium_v2.config
import
load
from
compendium_v2.db.survey_model
import
Survey
,
SurveyStatus
from
compendium_v2.db.survey_model
import
Survey
setup_logging
()
setup_logging
()
logger
=
logging
.
getLogger
(
'
dump_survey_model
'
)
logger
=
logging
.
getLogger
(
'
dump_survey_model
'
)
def
_write_survey_model
(
survey
,
filename
):
with
open
(
filename
,
"
w
"
)
as
out
:
json
.
dump
(
survey
.
survey
,
out
,
indent
=
1
)
print
(
f
"
Dumped survey model to
{
filename
}
"
)
def
_cli
(
app
,
year
):
def
_cli
(
app
,
year
):
query
=
select
(
Survey
).
where
(
Survey
.
year
==
year
)
if
year
else
select
(
Survey
).
order_by
(
Survey
.
year
.
desc
()).
limit
(
1
)
query
=
select
(
Survey
).
where
(
Survey
.
year
==
year
)
if
year
else
select
(
Survey
).
order_by
(
Survey
.
year
.
desc
()).
limit
(
1
)
...
@@ -42,9 +48,7 @@ def _cli(app, year):
...
@@ -42,9 +48,7 @@ def _cli(app, year):
filename
=
"
survey_model_
"
+
str
(
survey
.
year
)
+
"
.json
"
filename
=
"
survey_model_
"
+
str
(
survey
.
year
)
+
"
.json
"
dump_file
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
surveymodels
'
,
filename
)
dump_file
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
surveymodels
'
,
filename
)
with
open
(
dump_file
,
"
w
"
)
as
out
:
_write_survey_model
(
survey
,
dump_file
)
json
.
dump
(
survey
.
survey
,
out
,
indent
=
1
)
print
(
f
"
Dumped survey model to
{
dump_file
}
"
)
@click.command
()
@click.command
()
...
...
This diff is collapsed.
Click to expand it.
test/test_dump_survey_model.py
+
9
−
5
View file @
431ea61e
import
pytest
from
compendium_v2.db
import
db
from
compendium_v2.db
import
db
from
compendium_v2.db.survey_model
import
Survey
,
SurveyStatus
from
compendium_v2.db.survey_model
import
Survey
,
SurveyStatus
from
compendium_v2.migrations.dump_survey_model
import
_cli
from
compendium_v2.migrations.dump_survey_model
import
_cli
def
test_dump_status_check
(
app_with_survey_db
):
def
test_dump_status_check
(
app_with_survey_db
,
mocker
):
with
app_with_survey_db
.
app_context
():
with
app_with_survey_db
.
app_context
():
db
.
session
.
add
(
Survey
(
year
=
2021
,
status
=
SurveyStatus
.
published
,
survey
=
{}))
db
.
session
.
add
(
Survey
(
year
=
2022
,
status
=
SurveyStatus
.
published
,
survey
=
{}))
db
.
session
.
add
(
Survey
(
year
=
2022
,
status
=
SurveyStatus
.
published
,
survey
=
{}))
db
.
session
.
commit
()
db
.
session
.
commit
()
with
pytest
.
raises
(
Exception
,
match
=
r
'
^Make sure the survey has status closed
'
):
def
_write_survey_model
(
survey
,
output_dir
):
_cli
(
app_with_survey_db
,
None
)
assert
survey
.
status
==
SurveyStatus
.
published
assert
survey
.
year
==
2022
mocker
.
patch
(
'
compendium_v2.migrations.dump_survey_model._write_survey_model
'
,
_write_survey_model
)
_cli
(
app_with_survey_db
,
None
)
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