def test_optional_requirements_config_validation(self):
        class BaseRequirements(schema.Schema):
            driver = schema.StringItem(default="digitalocean", format="hidden")

        class SSHKeyFileSchema(schema.Schema):
            ssh_key_file = schema.StringItem(
                title="SSH Private Key",
                description=(
                    "The path to an SSH private key which will be used "
                    "to authenticate on the deployed VMs"
                ),
            )

        class SSHKeyNamesSchema(schema.Schema):
            ssh_key_names = schema.StringItem(
                title="SSH Key Names",
                description=(
                    "The names of an SSH key being managed on  "
                    "Digial Ocean account which will be used to "
                    "authenticate on the deployed VMs"
                ),
            )

        class Requirements(BaseRequirements):
            title = "DigitalOcean"
            description = "DigitalOcean Cloud VM configuration requirements."

            personal_access_token = schema.StringItem(
                title="Personal Access Token",
                description=(
                    "This is the API access token which can be generated "
                    "under the API/Application on your account"
                ),
                required=True,
            )

            requirements_definition = schema.AnyOfItem(
                items=(
                    SSHKeyFileSchema.as_requirements_item(),
                    SSHKeyNamesSchema.as_requirements_item(),
                ),
            )(flatten=True)
            ssh_key_file = SSHKeyFileSchema(flatten=True)
            ssh_key_names = SSHKeyNamesSchema(flatten=True)

        try:
            jsonschema.validate(
                {
                    "personal_access_token": "foo",
                    "ssh_key_names": "bar",
                    "ssh_key_file": "test",
                },
                Requirements.serialize(),
            )
        except jsonschema.exceptions.ValidationError as exc:
            self.fail("ValidationError raised: {}".format(exc))

        try:
            jsonschema.validate(
                {"personal_access_token": "foo", "ssh_key_names": "bar"},
                Requirements.serialize(),
            )
        except jsonschema.exceptions.ValidationError as exc:
            self.fail("ValidationError raised: {}".format(exc))

        try:
            jsonschema.validate(
                {"personal_access_token": "foo", "ssh_key_file": "test"},
                Requirements.serialize(),
            )
        except jsonschema.exceptions.ValidationError as exc:
            self.fail("ValidationError raised: {}".format(exc))

        with self.assertRaises(jsonschema.exceptions.ValidationError) as excinfo:
            jsonschema.validate(
                {"personal_access_token": "foo"}, Requirements.serialize()
            )
        if JSONSCHEMA_VERSION >= _LooseVersion("3.0.0"):
            self.assertIn(
                "'ssh_key_file' is a required property", excinfo.exception.message
            )
        else:
            self.assertIn(
                "is not valid under any of the given schemas", excinfo.exception.message
            )