This commit is contained in:
Marvin Buss 2020-04-27 21:58:12 +02:00
Родитель 7aa0b06f2b
Коммит f7e44bf364
3 изменённых файлов: 69 добавлений и 11 удалений

Просмотреть файл

@ -12,12 +12,6 @@ def mask_parameter(parameter):
def load_json(file_path):
paths = []
for root, dirs, files in os.walk("code"):
for filename in files:
paths.append(filename)
print(f"Path List: {paths}")
with open(file_path) as f:
json_object = json.load(f)
return json_object

35
tests/test_main.py Normal file
Просмотреть файл

@ -0,0 +1,35 @@
import os
import sys
import pytest
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(myPath, "..", "code"))
from main import main
from utils import AMLConfigurationException
def test_main_no_input():
"""
Unit test to check the main function with no inputs
"""
with pytest.raises(AMLConfigurationException):
assert main()
def test_main_invalid_azure_credentials():
os.environ["INPUT_AZURE_CREDENTIALS"] = ""
with pytest.raises(AMLConfigurationException):
assert main()
def test_main_invalid_parameters_file():
os.environ["INPUT_AZURE_CREDENTIALS"] = """{
'clientId': 'test',
'clientSecret': 'test',
'subscriptionId': 'test',
'tenantId': 'test'
}"""
os.environ["INPUT_PARAMETERS_FILE"] = "wrongfile.json"
with pytest.raises(AMLConfigurationException):
assert main()

Просмотреть файл

@ -29,15 +29,30 @@ def test_load_json_invalid_input():
)
def test_validate_json():
def test_validate_json_valid_inputs():
"""
Unit test to check the validate_json function
Unit test to check the validate_json function with valid inputs
"""
json_path = os.path.join(".cloud", ".azure", "workspace.json")
json_object = {}
schema_path = os.path.join("code", "schemas", "workspace_schema.json")
json_object = load_json(
file_path=json_path
schema_object = load_json(
file_path=schema_path
)
validate_json(
data=json_object,
schema=schema_object,
input_name="PARAMETERS_FILE"
)
def test_validate_json_invalid_json():
"""
Unit test to check the validate_json function with invalid json_object inputs
"""
json_object = {
"sku": ""
}
schema_path = os.path.join("code", "schemas", "workspace_schema.json")
schema_object = load_json(
file_path=schema_path
)
@ -47,3 +62,17 @@ def test_validate_json():
schema=schema_object,
input_name="PARAMETERS_FILE"
)
def test_validate_json_invalid_schema():
"""
Unit test to check the validate_json function with invalid schema inputs
"""
json_object = {}
schema_object = {}
with pytest.raises(Exception):
assert validate_json(
data=json_object,
schema=schema_object,
input_name="PARAMETERS_FILE"
)