Esempio n. 1
0
def test_recurse_check_structure_valid():
    sample = dict(string="Foobar",
                  list=["Foo", "Bar"],
                  dict={'foo': "Bar"},
                  none=None,
                  true=True,
                  false=False)
    to_check = dict(string="Foobar",
                    list=["Foo", "Bar", "Bas"],
                    dict={'foo': "Bar"},
                    none=None,
                    true=True,
                    false=False)
    recurse_check_structure(sample, to_check)
Esempio n. 2
0
def test_recurse_check_structure_missingitem():
    sample = dict(string="Foobar",
                  list=["Foo", "Bar"],
                  dict={'foo': "Bar"},
                  none=None,
                  true=True,
                  false=False)
    to_check = dict(string="Foobar",
                    list=["Foo", "Bar"],
                    dict={'foo': "Bar"},
                    none=None,
                    true=True)
    with pytest.raises(ValidationException):
        recurse_check_structure(sample, to_check)
    def check_configuration(self, configuration: 'typing.Mapping') -> None:
        """Allow for the `projects` key to have a variable number of definitions."""
        # Remove the `projects` key from both the template and the configuration and then test them separately
        try:
            config_template = self.get_configuration_template().copy()
            projects_template = config_template.pop('projects')
            projects_config = configuration.pop('projects')  # Might fail
        except KeyError:
            raise ValidationException(
                'Your configuration must include a projects key with at least one project configured.'
            )

        recurse_check_structure(config_template, configuration)

        # Check that each project configuration matches the template
        for k, v in projects_config.items():
            recurse_check_structure(projects_template['some-project'], v)

        configuration.update({'projects': projects_config})
Esempio n. 4
0
def test_recurse_check_structure_wrongtype_1():
    sample = dict(
        string="Foobar",
        list=["Foo", "Bar"],
        dict={"foo": "Bar"},
        none=None,
        true=True,
        false=False,
    )
    to_check = dict(
        string=None,
        list=["Foo", "Bar"],
        dict={"foo": "Bar"},
        none=None,
        true=True,
        false=False,
    )
    with pytest.raises(ValidationException):
        recurse_check_structure(sample, to_check)
Esempio n. 5
0
def test_recurse_check_structure_valid():
    sample = dict(string="Foobar", list=["Foo", "Bar"], dict={'foo': "Bar"}, none=None, true=True, false=False)
    to_check = dict(string="Foobar", list=["Foo", "Bar", "Bas"], dict={'foo': "Bar"}, none=None, true=True,
                    false=False)
    recurse_check_structure(sample, to_check)
Esempio n. 6
0
def test_recurse_check_structure_wrongtype_3():
    sample = dict(string="Foobar", list=["Foo", "Bar"], dict={'foo': "Bar"}, none=None, true=True, false=False)
    to_check = dict(string="Foobar", list=["Foo", "Bar"], dict=["Foo", "Bar"], none=None, true=True, false=False)
    with pytest.raises(ValidationException):
        recurse_check_structure(sample, to_check)