Skip to content
Snippets Groups Projects
Select Git revision
  • 8d530f4d83243b35b5763669de9d40cdc332599e
  • develop default
  • master protected
  • feature/frontend-tests
  • 0.99
  • 0.98
  • 0.97
  • 0.96
  • 0.95
  • 0.94
  • 0.93
  • 0.92
  • 0.91
  • 0.90
  • 0.89
  • 0.88
  • 0.87
  • 0.86
  • 0.85
  • 0.84
  • 0.83
  • 0.82
  • 0.81
  • 0.80
24 results

test_conversion.py

Blame
  • test_conversion.py 3.41 KiB
    from sqlalchemy import select
    from sqlalchemy.orm import lazyload
    
    from compendium_v2.db import db
    from compendium_v2.db.presentation_models import NREN
    from compendium_v2.db.survey_models import Survey, SurveyResponse, SurveyStatus
    from compendium_v2.conversion.conversion import _cli, convert_answers, load_service_data
    
    
    def mock_convert_answers(_):
        return {"data": {}}
    
    
    def mock_query_nren(_):
        return {16455: "answer1"}
    
    
    def mock_load_service_data():
        return {}
    
    
    def test_queries(app_with_survey_db, mocker):
    
        with app_with_survey_db.app_context():
            db.session.add(Survey(year=2022, status=SurveyStatus.closed, survey={}))
            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)
        mocker.patch('compendium_v2.conversion.conversion.load_service_data', mock_load_service_data)
    
        _cli(app_with_survey_db)
    
        with app_with_survey_db.app_context():
    
            responses = db.session.scalars(
                select(SurveyResponse).options(lazyload("*")).order_by(SurveyResponse.nren_id)
            ).all()
            assert len(responses) == 1
            assert responses[0].answers == {"data": {}, "page": 0, "verification_status": {}}
    
    
    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']}
                }
            }
        }
    
    
    def test_load_service_data():
        service_data_dict = load_service_data()
        assert len(service_data_dict.keys()) == 42
        assert len(service_data_dict['ARNES'].keys()) == 8
        assert len(service_data_dict['ARNES']['services_identity']) == 3
        assert len(service_data_dict['SURF'].keys()) == 7
        assert len(service_data_dict['SURF']['services_network']) == 10
        assert service_data_dict['SURF']['services_security']['security-audit'] == {
            'offered': ['yes'],
            'name': 'SURFaudit',
            'additional_information': 'The Standard for Information Security in Higher Education is the basis of '
                                      'SURFaudit’s self-assessment.\n\nSURFaudit Security Standard for Higher '
                                      'Education is derived from the ISO/IEC 27002:2013 standard'
        }