Exemple #1
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")
Exemple #3
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')
    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')