Esempio n. 1
0
    def test_expand_restriction_format(self):
        string_restriction = 'settings.some_attribute.value != true'
        dict_restriction_long_format = {
            'condition': 'settings.some_attribute.value != true',
            'message': 'Another attribute required'
        }
        dict_restriction_short_format = {
            'settings.some_attribute.value != true':
            'Another attribute required'
        }
        result = {
            'action': 'disable',
            'condition': 'settings.some_attribute.value != true',
        }
        invalid_format = ['some_condition']

        # check string format
        self.assertDictEqual(
            RestrictionBase._expand_restriction(
                string_restriction), result)
        result['message'] = 'Another attribute required'
        # check long format
        self.assertDictEqual(
            RestrictionBase._expand_restriction(
                dict_restriction_long_format), result)
        # check short format
        self.assertDictEqual(
            RestrictionBase._expand_restriction(
                dict_restriction_short_format), result)
        # check invalid format
        self.assertRaises(
            errors.InvalidData,
            RestrictionBase._expand_restriction,
            invalid_format)
Esempio n. 2
0
    def test_expand_restriction_format(self):
        string_restriction = 'settings.some_attribute.value != true'
        dict_restriction_long_format = {
            'condition': 'settings.some_attribute.value != true',
            'message': 'Another attribute required'
        }
        dict_restriction_short_format = {
            'settings.some_attribute.value != true':
            'Another attribute required'
        }
        result = {
            'action': 'disable',
            'condition': 'settings.some_attribute.value != true',
        }
        invalid_format = ['some_condition']

        # check string format
        self.assertDictEqual(
            RestrictionBase._expand_restriction(
                string_restriction), result)
        result['message'] = 'Another attribute required'
        # check long format
        self.assertDictEqual(
            RestrictionBase._expand_restriction(
                dict_restriction_long_format), result)
        # check short format
        self.assertDictEqual(
            RestrictionBase._expand_restriction(
                dict_restriction_short_format), result)
        # check invalid format
        self.assertRaises(
            errors.InvalidData,
            RestrictionBase._expand_restriction,
            invalid_format)
    def test_expand_restriction_format(self):
        string_restriction = "settings.some_attribute.value != true"
        dict_restriction_long_format = {
            "condition": "settings.some_attribute.value != true",
            "message": "Another attribute required",
        }
        dict_restriction_short_format = {"settings.some_attribute.value != true": "Another attribute required"}
        result = {"action": "disable", "condition": "settings.some_attribute.value != true"}
        invalid_format = ["some_condition"]

        # check string format
        self.assertDictEqual(RestrictionBase._expand_restriction(string_restriction), result)
        result["message"] = "Another attribute required"
        # check long format
        self.assertDictEqual(RestrictionBase._expand_restriction(dict_restriction_long_format), result)
        # check short format
        self.assertDictEqual(RestrictionBase._expand_restriction(dict_restriction_short_format), result)
        # check invalid format
        self.assertRaises(errors.InvalidData, RestrictionBase._expand_restriction, invalid_format)
Esempio n. 4
0
 def check_roles_requirement(cls, roles, roles_metadata, models):
     for role in roles:
         if "restrictions" in roles_metadata[role]:
             result = RestrictionBase.check_restrictions(
                 models, roles_metadata[role]['restrictions']
             )
             if result['result']:
                 raise errors.InvalidNodeRole(
                     "Role '{}' restrictions mismatch: {}"
                     .format(role, result['message'])
                 )
    def test_check_restrictions(self):
        attributes = self.data.get("attributes")

        for gkey, gvalue in six.iteritems(attributes):
            for key, value in six.iteritems(gvalue):
                result = RestrictionBase.check_restrictions(
                    models={"settings": attributes}, restrictions=value.get("restrictions", [])
                )
                # check when couple restrictions true for some item
                if key == "attribute_1":
                    self.assertTrue(result.get("result"))
                    self.assertEqual(
                        result.get("message"),
                        "Only one of attributes 1 and 2 allowed. " + "Only one of attributes 1 and 3 allowed",
                    )
                # check when different values uses in restriction
                if key == "attribute_3":
                    self.assertTrue(result.get("result"))
                    self.assertEqual(result.get("message"), "Only one of attributes 3 and 4 allowed")
Esempio n. 6
0
    def test_check_restrictions(self):
        attributes = self.data.get('attributes')

        for gkey, gvalue in six.iteritems(attributes):
            for key, value in six.iteritems(gvalue):
                result = RestrictionBase.check_restrictions(
                    models={'settings': attributes},
                    restrictions=value.get('restrictions', []))
                # check when couple restrictions true for some item
                if key == 'attribute_1':
                    self.assertTrue(result.get('result'))
                    self.assertEqual(
                        result.get('message'),
                        'Only one of attributes 1 and 2 allowed. ' +
                        'Only one of attributes 1 and 3 allowed')
                # check when different values uses in restriction
                if key == 'attribute_3':
                    self.assertTrue(result.get('result'))
                    self.assertEqual(result.get('message'),
                                     'Only one of attributes 3 and 4 allowed')
Esempio n. 7
0
    def test_check_restrictions(self):
        attributes = self.data.get('attributes')

        for gkey, gvalue in six.iteritems(attributes):
            for key, value in six.iteritems(gvalue):
                result = RestrictionBase.check_restrictions(
                    models={'settings': attributes},
                    restrictions=value.get('restrictions', []))
                # check when couple restrictions true for some item
                if key == 'attribute_1':
                    self.assertTrue(result.get('result'))
                    self.assertEqual(
                        result.get('message'),
                        'Only one of attributes 1 and 2 allowed. ' +
                        'Only one of attributes 1 and 3 allowed')
                # check when different values uses in restriction
                if key == 'attribute_3':
                    self.assertTrue(result.get('result'))
                    self.assertEqual(
                        result.get('message'),
                        'Only one of attributes 3 and 4 allowed')