Skip to content
Snippets Groups Projects
Commit 1a4ceaf2 authored by Saket Agrahari's avatar Saket Agrahari
Browse files

adding test cases for snp standards

parent ddf4bc86
Branches
Tags
No related merge requests found
......@@ -6,6 +6,67 @@ from flask import Blueprint, jsonify
routes = Blueprint('standards-and-policies', __name__)
STANDARDS_RESPONSE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'standards': {
'type': 'object',
'properties': {
'nren': {'type': 'string'},
'nren_country': {'type': 'string'},
'year': {'type': 'integer'},
'audits': {'type': 'string'},
'audit_specifics': {'type': 'string'},
'business_continuity_plans': {'type': 'string'},
'business_continuity_plans_specifics': {'type': 'string'},
'crisis_management_procedure': {'type': 'string'}
},
'required': ['nren', 'nren_country', 'year'],
'additionalProperties': False
}
},
'type': 'array',
'items': {'$ref': '#/definitions/standards'}
}
CRISIS_EXERCISES_RESPONSE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'crisis_exercises': {
'type': 'object',
'properties': {
'nren': {'type': 'string'},
'nren_country': {'type': 'string'},
'year': {'type': 'integer'},
'exercise_descriptions': {'type': 'array', 'items': {'type': 'string'}}
},
'required': ['nren', 'nren_country', 'year'],
'additionalProperties': False
}
},
'type': 'array',
'items': {'$ref': '#/definitions/crisis_exercises'}
}
SECURITY_CONTROLS_RESPONSE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'security_controls': {
'type': 'object',
'properties': {
'nren': {'type': 'string'},
'nren_country': {'type': 'string'},
'year': {'type': 'integer'},
'security_control_descriptions': {'type': 'array', 'items': {'type': 'string'}}
},
'required': ['nren', 'nren_country', 'year'],
'additionalProperties': False
}
},
'type': 'array',
'items': {'$ref': '#/definitions/security_controls'}
}
def standards_extract_data(standards: Standards) -> dict:
return {
......
This diff is collapsed.
......@@ -700,6 +700,79 @@ def test_dark_fibre_lease_data(app):
db.session.commit()
@pytest.fixture
def test_standards_data(app):
with app.app_context():
nrens_and_years = [('nren1', 2019), ('nren1', 2020), ('nren1', 2021), ('nren2', 2019), ('nren2', 2021)]
nren_names = set(ny[0] for ny in nrens_and_years)
nren_dict = {nren_name: presentation_models.NREN(name=nren_name, country='country') for nren_name in nren_names}
db.session.add_all(nren_dict.values())
for (nren_name, year) in nrens_and_years:
nren = nren_dict[nren_name]
db.session.add(presentation_models.Standards(
nren=nren,
year=year,
audit_specifics="ISO27001 certification programme started in Q3 2022",
audits=True,
business_continuity_plans=True,
business_continuity_plans_specifics="We do not yet comply with specific international ",
crisis_management_procedure=True,
))
db.session.commit()
@pytest.fixture
def test_crisis_exercises_data(app):
with app.app_context():
nrens_and_years = [('nren1', 2019), ('nren1', 2020), ('nren1', 2021), ('nren2', 2019), ('nren2', 2021)]
nren_names = set(ny[0] for ny in nrens_and_years)
nren_dict = {nren_name: presentation_models.NREN(name=nren_name, country='country') for nren_name in nren_names}
db.session.add_all(nren_dict.values())
for (nren_name, year) in nrens_and_years:
nren = nren_dict[nren_name]
db.session.add(presentation_models.CrisisExercises(
nren=nren,
year=year,
exercise_descriptions=[
"We participate in GEANT Crisis workshops such as CLAW",
"We participated in National crisis exercises "
],
))
db.session.commit()
@pytest.fixture
def test_security_controls_data(app):
with app.app_context():
nrens_and_years = [('nren1', 2019), ('nren1', 2020), ('nren1', 2021), ('nren2', 2019), ('nren2', 2021)]
nren_names = set(ny[0] for ny in nrens_and_years)
nren_dict = {nren_name: presentation_models.NREN(name=nren_name, country='country') for nren_name in nren_names}
db.session.add_all(nren_dict.values())
for (nren_name, year) in nrens_and_years:
nren = nren_dict[nren_name]
db.session.add(presentation_models.SecurityControls(
nren=nren,
year=year,
security_control_descriptions=[
"Firewall",
"DDoS mitigation",
"Network monitoring",
"ACL"
],
))
db.session.commit()
@pytest.fixture
def test_traffic_data(app):
with app.app_context():
......
import json
import jsonschema
from compendium_v2.routes.standards_and_policies import SECURITY_CONTROLS_RESPONSE_SCHEMA, \
CRISIS_EXERCISES_RESPONSE_SCHEMA, STANDARDS_RESPONSE_SCHEMA
def test_standards_response(client, test_standards_data):
rv = client.get(
'/api/standards-and-policies/standards',
headers={'Accept': ['application/json']})
assert rv.status_code == 200
result = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(result, STANDARDS_RESPONSE_SCHEMA)
assert result
def test_crisis_exercises_response(client, test_crisis_exercises_data):
rv = client.get(
'/api/standards-and-policies/crisis-exercises',
headers={'Accept': ['application/json']})
assert rv.status_code == 200
result = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(result, CRISIS_EXERCISES_RESPONSE_SCHEMA)
assert result
def test_security_controls_response(client, test_security_controls_data):
rv = client.get(
'/api/standards-and-policies/security-controls',
headers={'Accept': ['application/json']})
assert rv.status_code == 200
result = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(result, SECURITY_CONTROLS_RESPONSE_SCHEMA)
assert result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment