Exemplo n.º 1
0
    def test_validate_settings_invalid_json_schema(self):

        self.db.require_schema = True
        self.db.schema = {
            '$schema': 'http://json-schema.org/draft-04/schema#',
            'type': 'object',
            'properties': {
                'host': {
                    'type': 'string'
                },
                'port': {
                    'type': 'integer'
                },
                'user': {
                    'type': 'string'
                },
                'password': {
                    'type': 'string'
                },
                'database': {
                    'type': 'string'
                }
            },
            'required': [
                'host',
                'port',
                'user',
                'password',
                'database',
            ]
        }
        self.db.save()

        update_settings(environment=self.base,
                        component=self.hosts,
                        data={'db': {
                            'host': 'mysql-db',
                            'port': '3567'
                        }})

        with pytest.raises(InvalidSettingsError) as exc_info:
            validate_settings(environment=self.base,
                              component=self.db,
                              data={
                                  'host': '${hosts.db.host}',
                                  'port': '${hosts.db.port}',
                                  'user': '******',
                                  'password': '',
                                  'database': ''
                              })

        assert exc_info.value.message == 'Invalid settings schema: \'3567\' is not of type \'integer\'.'
Exemplo n.º 2
0
    def clean_settings(self):

        data = self.cleaned_data['settings']

        try:
            validate_settings(
                environment=self.environment,
                component=self.component,
                data=data,
            )
        except InvalidSettingsError as exc:
            raise ValidationError(str(exc.message))

        return data
Exemplo n.º 3
0
    def test_validate_settings_invalid_key(self):

        with pytest.raises(InvalidSettingsError) as exc_info:

            validate_settings(environment=self.base,
                              component=self.db,
                              data={
                                  'host': '${hosts.db}',
                                  'port': 3567,
                                  'user': '******',
                                  'password': '',
                                  'database': ''
                              })

        assert exc_info.value.message == 'Injected key `hosts.db` does not exist.'
Exemplo n.º 4
0
    def test_validate_settings_invalid_key_reference(self):

        update_settings(environment=self.base,
                        component=self.hosts,
                        data={'db': 'localhost'})

        update_settings(environment=self.base,
                        component=self.db,
                        data={
                            'host': '${hosts.db}',
                            'port': 3567,
                            'user': '******',
                            'password': '',
                            'database': ''
                        })

        with pytest.raises(InvalidSettingsError) as exc_info:
            validate_settings(environment=self.base,
                              component=self.hosts,
                              data={'db1': 'mysql-base'})

        assert exc_info.value.message == 'Component `db` refers to changed key `hosts.db`.'
Exemplo n.º 5
0
    def test_validate_settings_invalid_remove_key(self):

        self.db.require_schema = False
        self.db.strict_keys = True
        self.db.save()

        update_settings(environment=self.base,
                        component=self.db,
                        data={
                            'host': 'localhost',
                            'port': 3567,
                        })

        with pytest.raises(InvalidSettingsError) as exc_info:
            validate_settings(environment=self.dev,
                              component=self.db,
                              data={
                                  'host': 'mysql-dev',
                              })

        assert exc_info.value.message == (
            'Cannot remove keys from environment configuration. Removed key(s): <b>port</b>.'
        )
Exemplo n.º 6
0
    def test_validate_settings_invalid_add_key(self):

        self.db.require_schema = False
        self.db.strict_keys = True
        self.db.save()

        update_settings(environment=self.base,
                        component=self.db,
                        data={
                            'host': 'localhost',
                            'port': 3567,
                        })

        with pytest.raises(InvalidSettingsError) as exc_info:
            validate_settings(environment=self.dev,
                              component=self.db,
                              data={
                                  'host': 'mysql-dev',
                                  'port': 3567,
                                  'test': '123123'
                              })

        assert exc_info.value.message == 'Cannot add new keys to environment configuration. New key(s): <b>test</b>.'