Example #1
0
    def constrain (self, entity):
        if not hasattr(self, '_pending_constraints'):
            self._pending_constraints = []

            for constraint in list_constraints():
                if constraint.argument() in self._kwargs:
                    self._pending_constraints.append([
                            constraint,
                            self._kwargs.get(constraint.argument()),
                            entity,
                            self.name])

        for constraint, value, entity, name in self._pending_constraints:
            try:
                self._field.add_constraint(constraint(value, entity=entity,
                        field_name=name))
            except EnvironmentError:
                pass
            else:
                self._pending_constraints.remove([constraint, value,
                                                  entity, name])
Example #2
0
 def is_constrained (self):
     return self.is_primary_key or any(x.argument() in self._kwargs for \
                                                 x in list_constraints())
Example #3
0
    def test_list_constraints (self):
        self.assertEqual(tesql.types.constraints.ALL_CONSTRAINTS, [])

        list_constraints()

        self.assertNotEqual(tesql.types.constraints.ALL_CONSTRAINTS, [])