def test_invalid_directory_none():
    # Setup
    validator = Validator()

    # System under test
    with pytest.raises(ValidationError):
        validator.validate_directory(None)
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_invalid_directory_name():
    # Setup
    validator = Validator()
    invalid_directory_name = str(uuid.uuid4())

    # System under test
    with pytest.raises(ValidationError):
        validator.validate_directory(invalid_directory_name)
def test_valid_directory(tmpdir):
    # Setup
    validator = Validator()
    valid_file = tmpdir.join("settings.json")
    valid_file_content = "{\"version\": \"alpha\", \"schema\": \"core\"}"
    valid_file.write(valid_file_content)

    # System under test
    validator.validate_directory(tmpdir.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_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)