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

added unittests for conversion

parent f5deacac
No related branches found
No related tags found
1 merge request!47Feature/comp 218 migrating 2022 data
from sqlalchemy import select
from compendium_v2.db import db
from compendium_v2.db.model import NREN
from compendium_v2.db.survey_model import Survey, SurveyResponse
from compendium_v2.conversion.conversion import _cli, convert_answers
def mock_convert_answers(_):
return {"data": {}}
def mock_query_nren(_):
return {16455: "answer1"}
def test_queries(app_with_survey_db, mocker):
with app_with_survey_db.app_context():
db.session.add(NREN(name='Restena', country='country'))
db.session.commit()
mocker.patch('compendium_v2.conversion.conversion.convert_answers', mock_convert_answers)
mocker.patch('compendium_v2.conversion.conversion.query_nren', mock_query_nren)
_cli(app_with_survey_db)
with app_with_survey_db.app_context():
surveys = db.session.scalars(select(Survey)).all()
assert len(surveys) == 1
assert surveys[0].year == 2022
responses = db.session.scalars(select(SurveyResponse).order_by(SurveyResponse.nren_id)).all()
assert len(responses) == 1
assert responses[0].answers == {"data": {}}
def test_conversion():
answers = {
16455: '"full nren name"',
16453: '["ec project1", "ec project2"]',
16632: '"3434"',
16432: '"suborg name 3"',
16410: '"We use a combination of flat fee and usage-based fee"',
16474: '"Yes"',
16476: '"No"',
16491: '["Universities", "Further education"]',
16492: '["Research institutes", "Universities"]'
}
converted_answers = convert_answers(answers)
assert converted_answers == {
'data': {
'charging_mechanism': 'combination',
'suborganization_details': [{}, {}, {}, {'suborganization_name': 'suborg name 3'}],
'ec_project_names': [{'ec_project_name': 'ec project1'}, {'ec_project_name': 'ec project2'}],
'full_name_english': 'full nren name',
'policies': {'connectivity_policy': {'available': ['yes']}, 'acceptable_use_policy': {}},
'traffic_load': {'iros': {'peak_to_institutions_from_network': '3434'}},
'service_matrix': {
'universities': {'service_types': ['security', 'isp_support']},
'further_education': {'service_types': ['security']},
'institutes': {'service_types': ['isp_support']}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment