def test_and_single_depth(self): cs = ConditionSet({ 'and': [ {'attr': 'a', 'value': 1, 'op': 'eq'}, {'attr': 'b', 'value': 1, 'op': 'eq', 'negate': True}, ] }) self.assertTrue(cs.eval({'a': 1, 'b': 2})) self.assertFalse(cs.eval({'a': 1, 'b': 1}))
def test_mixed_and(self): cs = ConditionSet({ 'and': [ {'attr': 'a', 'value': 1, 'op': 'eq'}, {'or': [ {'attr': 'b', 'value': 2, 'op': 'eq'}, {'attr': 'c', 'value': 3, 'op': 'eq'}, ]} ] }) self.assertTrue(cs.eval({'a': 1, 'b': 2, 'c': 9})) self.assertTrue(cs.eval({'a': 1, 'b': 9, 'c': 3})) self.assertFalse(cs.eval({'a': 1, 'b': 9, 'c': 9})) self.assertFalse(cs.eval({'a': 9, 'b': 2, 'c': 3}))
def clean(self): super().clean() # At least one action type must be selected if not self.type_create and not self.type_delete and not self.type_update: raise ValidationError( "At least one type must be selected: create, update, and/or delete." ) if self.conditions: try: ConditionSet(self.conditions) except ValueError as e: raise ValidationError({'conditions': e}) # CA file path requires SSL verification enabled if not self.ssl_verification and self.ca_file_path: raise ValidationError({ 'ca_file_path': 'Do not specify a CA certificate file if SSL verification is disabled.' })
def test_invalid_logic(self): with self.assertRaises(ValueError): ConditionSet({'foo': []})
def test_empty(self): with self.assertRaises(ValueError): ConditionSet({})