def test_core_and_default_settings_validators_success(tmpdir): # Setup validator = Validator() valid_default_settings_file_name = "some-default-settings-file.json" valid_core_path = tmpdir.join("settings.json") valid_core_file_content = { 'version': 'alpha', 'schema': 'core', 'os': { 'name': 'macos', 'default_settings_file': valid_default_settings_file_name } } valid_core_path.write(json.dumps(valid_core_file_content)) valid_default_settings_path = tmpdir.join(valid_default_settings_file_name) valid_default_settings_content = { 'version': 'alpha', 'schema': 'default_settings', 'default_settings': [{ 'name': 'some valid minimal example', 'command': 'echo "some valid minimal example command"' }] } valid_default_settings_path.write( json.dumps(valid_default_settings_content)) # System under test validator.validate_directory(tmpdir.strpath)
def test_valid_schema_all(): # Setup validator = Validator() data = load_test_data("alpha.default_settings", "valid_schema_all.json") # System under test validator.validate_data(data)
def test_valid_schema_environments(): # Setup validator = Validator() data = load_test_data("alpha.core", "valid_schema_environments.json") # System under test validator.validate_data(data)
def test_valid_schema_all(): # Setup validator = Validator() data = load_test_data("alpha.developer_environments", "valid_schema_all.json") # System under test validator.validate_data(data)
def test_invalid_directory_none(): # Setup validator = Validator() # System under test with pytest.raises(ValidationError): validator.validate_directory(None)
def test_invalid_schema_action_no_files(): # Setup validator = Validator() data = load_test_data("alpha.core", "invalid_schema_actions_no_files.json") # System under test with pytest.raises(ValidationError): validator.validate_data(data)
def test_invalid_schema_virtual_environments_no_name(): # Setup validator = Validator() data = load_test_data("alpha.developer_environments", "invalid_schema_virtual_environments_no_name.json") # System under test with pytest.raises(ValidationError): validator.validate_data(data)
def test_invalid_file_name(): # Setup validator = Validator() invalid_file_name = str(uuid.uuid4()) # System under test with pytest.raises(ValidationError): validator.validate_file(invalid_file_name)
def test_invalid_schema_default_settings_null_end(): # Setup validator = Validator() data = load_test_data("alpha.default_settings", "invalid_schema_default_settings_null_end.json") # System under test with pytest.raises(ValidationError): validator.validate_data(data)
def test_valid_file(tmpdir): # Setup validator = Validator() valid_file = tmpdir.join("valid_json.json") valid_file_content = "{\"version\": \"alpha\", \"schema\": \"core\"}" valid_file.write(valid_file_content) # System under test validator.validate_file(valid_file.strpath)
def test_all_validators_fail_invalid_developer_environment_version_type( tmpdir): # Setup validator = Validator() valid_default_settings_file_name = "some-default-settings-file.json" valid_core_path = tmpdir.join("settings.json") valid_core_file_content = { 'version': 'alpha', 'schema': 'core', 'os': { 'name': 'macos', 'default_settings_file': valid_default_settings_file_name } } valid_core_path.write(json.dumps(valid_core_file_content)) valid_default_settings_path = tmpdir.join(valid_default_settings_file_name) valid_default_settings_content = { 'version': 'alpha', 'schema': 'default_settings', 'default_settings': [{ 'name': 'some valid minimal example', 'command': 'echo "some valid minimal example command"' }] } valid_default_settings_path.write( json.dumps(valid_default_settings_content)) valid_developer_environments_file_name = "some-default-settings-file.json" valid_developer_environments_path = tmpdir.join("settings.json") valid_developer_environments_file_content = { "version": "alpha", "schema": "developer_environments", "environments": [{ "language": 1, "versions": ["3.7.2", "3.6.8"] }, { "language": "python", "versions": ["3.7.2", "3.6.8"] }] } valid_developer_environments_path.write( json.dumps(valid_developer_environments_file_content)) # System under test with pytest.raises(ValidationError): validator.validate_directory(tmpdir.strpath)
def test_invalid_file_invalid_json(tmpdir): # Setup validator = Validator() invalid_file = tmpdir.join("invalid_json.json") invalid_file_content = "{\"version\": \"alpha,}" invalid_file.write(invalid_file_content) # System under test with pytest.raises(ValidationError): validator.validate_file(invalid_file.strpath)
def test_valid_directory_multiple_modules(tmpdir): # Setup validator = Validator() modules_settings_file_a = tmpdir.mkdir("a_directory").join("settings.json") modules_settings_file_a_content = "{\"version\": \"alpha\", \"schema\": \"core\"}" modules_settings_file_a.write(modules_settings_file_a_content) modules_settings_file_b = tmpdir.mkdir("b_directory").join("settings.yaml") modules_settings_file_b_content = "version: \"alpha\"\nschema: \"core\"" modules_settings_file_b.write(modules_settings_file_b_content) # System under test validator.validate_directory(tmpdir.strpath)
def test_core_and_default_settings_validators_fail_invalid_default_settings( tmpdir): # Setup validator = Validator() invalid_default_settings_file_name = "some-default-settings-file.json" valid_core_path = tmpdir.join("settings.json") valid_core_file_content = { 'version': 'alpha', 'schema': 'core', 'os': { 'name': 'macos', 'default_settings_file': invalid_default_settings_file_name } } valid_core_path.write(json.dumps(valid_core_file_content)) invalid_default_settings_path = tmpdir.join( invalid_default_settings_file_name) invalid_default_settings_content = { 'version': 'alpha', 'schema': 'default_settings', 'default_settings': [{ 'name': 'some valid minimal example', 'command': 'echo "some valid minimal example command"', 'start': 'some invalid start mac version' }] } invalid_default_settings_path.write( json.dumps(invalid_default_settings_content)) # System under test with pytest.raises(ValidationError): validator.validate_directory(tmpdir.strpath)