Skip to content
Snippets Groups Projects
Commit 13deb847 authored by Remco Tukker's avatar Remco Tukker
Browse files

testcases and linter fixes

parent 32718825
Branches
Tags
1 merge request!71Create a preview mode for publishing survey data
...@@ -180,7 +180,7 @@ def _cli(app): ...@@ -180,7 +180,7 @@ def _cli(app):
survey_year=2022, survey_year=2022,
survey=survey, survey=survey,
answers=survey_dict, answers=survey_dict,
status=ResponseStatus.checked status=ResponseStatus.completed
) )
db.session.add(response) db.session.add(response)
......
...@@ -18,7 +18,8 @@ depends_on = None ...@@ -18,7 +18,8 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('preview_year', op.create_table(
'preview_year',
sa.Column('year', sa.Integer(), nullable=False), sa.Column('year', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('year', name=op.f('pk_preview_year')) sa.PrimaryKeyConstraint('year', name=op.f('pk_preview_year'))
) )
...@@ -38,7 +39,6 @@ def upgrade(): ...@@ -38,7 +39,6 @@ def upgrade():
op.execute("DROP TYPE surveystatus_old") op.execute("DROP TYPE surveystatus_old")
op.execute("DROP TYPE responsestatus_old") op.execute("DROP TYPE responsestatus_old")
# ### end Alembic commands ### # ### end Alembic commands ###
......
...@@ -167,7 +167,7 @@ def test_survey_data(app): ...@@ -167,7 +167,7 @@ def test_survey_data(app):
nren=nren_dict['nren1'], nren=nren_dict['nren1'],
survey=survey2022, survey=survey2022,
answers={}, answers={},
status=survey_model.ResponseStatus.checked status=survey_model.ResponseStatus.completed
)) ))
db.session.commit() db.session.commit()
......
import json import json
import jsonschema import jsonschema
from compendium_v2 import db
from compendium_v2.db.model import PreviewYear
from compendium_v2.routes.budget import BUDGET_RESPONSE_SCHEMA from compendium_v2.routes.budget import BUDGET_RESPONSE_SCHEMA
...@@ -11,3 +13,33 @@ def test_budget_response(client, test_budget_data): ...@@ -11,3 +13,33 @@ def test_budget_response(client, test_budget_data):
result = json.loads(rv.data.decode('utf-8')) result = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(result, BUDGET_RESPONSE_SCHEMA) jsonschema.validate(result, BUDGET_RESPONSE_SCHEMA)
assert result assert result
def test_budget_response_preview(app, client, test_budget_data):
rv = client.get(
'/api/budget/',
headers={'Accept': ['application/json']})
assert rv.status_code == 200
result = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(result, BUDGET_RESPONSE_SCHEMA)
assert any([datapoint['year'] == 2021 for datapoint in result])
with app.app_context():
db.session.add(PreviewYear(year=2021))
db.session.commit()
rv = client.get(
'/api/budget/?preview',
headers={'Accept': ['application/json']})
assert rv.status_code == 200
result = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(result, BUDGET_RESPONSE_SCHEMA)
assert any([datapoint['year'] == 2021 for datapoint in result])
rv = client.get(
'/api/budget/',
headers={'Accept': ['application/json']})
assert rv.status_code == 200
result = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(result, BUDGET_RESPONSE_SCHEMA)
assert all([datapoint['year'] != 2021 for datapoint in result])
...@@ -88,6 +88,27 @@ def test_survey_route_open_close(app, client, test_survey_data, mocked_user): ...@@ -88,6 +88,27 @@ def test_survey_route_open_close(app, client, test_survey_data, mocked_user):
assert rv.status_code != 200 assert rv.status_code != 200
def test_survey_route_preview(app, client, test_survey_data, mocked_admin_user):
rv = client.post(
'/api/survey/preview/2022',
headers={'Accept': ['application/json']})
assert rv.status_code == 400
result = json.loads(rv.data.decode('utf-8'))
assert not result.get('success')
with app.app_context():
survey = db.session.query(Survey).filter(Survey.year == 2022).first()
survey.status = SurveyStatus.closed
db.session.commit()
rv = client.post(
'/api/survey/preview/2022',
headers={'Accept': ['application/json']})
assert rv.status_code == 200
result = json.loads(rv.data.decode('utf-8'))
assert result.get('success')
def test_survey_route_publish(app, client, test_survey_data, mocked_admin_user): def test_survey_route_publish(app, client, test_survey_data, mocked_admin_user):
rv = client.post( rv = client.post(
'/api/survey/publish/2022', '/api/survey/publish/2022',
...@@ -98,7 +119,7 @@ def test_survey_route_publish(app, client, test_survey_data, mocked_admin_user): ...@@ -98,7 +119,7 @@ def test_survey_route_publish(app, client, test_survey_data, mocked_admin_user):
with app.app_context(): with app.app_context():
survey = db.session.query(Survey).filter(Survey.year == 2022).first() survey = db.session.query(Survey).filter(Survey.year == 2022).first()
survey.status = SurveyStatus.closed survey.status = SurveyStatus.preview
db.session.commit() db.session.commit()
rv = client.post( rv = client.post(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment