Exemplo n.º 1
0
 def __init__(self, **kwargs):
     self._errors = Errors()
     for field in self.fields:
         set_field_attr(self, field, kwargs.get(field))
     for k, v in kwargs.iteritems():
         if k not in self.fields:
             msg = "Ignoring unknown field for %s: %s = '%s'"
             logging.warn(msg, self.__class__.__name__, repr(k), repr(v))
     self.changed_fields = set()
Exemplo n.º 2
0
 class Target(Document):
     f = fields.DateTimeField("my_datetime", required=True)
     errors = Errors()
Exemplo n.º 3
0
 class Order(object):
     f = fields.ListField("orderlines", OrderLine)
     errors = Errors()
Exemplo n.º 4
0
 class Target(Document):
     f = fields.EmbeddedField("address", Address)
     errors = Errors()
Exemplo n.º 5
0
 class Target(Document):
     errors = Errors()
Exemplo n.º 6
0
 class Target(Document):
     f = fields.StringField("my_field", choices=["type_a", "type_b"])
     errors = Errors()
Exemplo n.º 7
0
 class Target(Document):
     f = fields.StringField("my_field", pattern="^This")
     errors = Errors()
Exemplo n.º 8
0
 class Target(Document):
     f = fields.ObjectIdField("my_field", required=True)
     errors = Errors()
Exemplo n.º 9
0
class ErrorsTest(unittest.TestCase):
    def setUp(self):
        super(ErrorsTest, self).setUp()
        self.errors = Errors()

    def test_add_error(self):
        self.errors.add("email", "is required")
        self.assertEqual(["is required"], self.errors.get("email"))

    def test_add_errors_to_one_field(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")
        self.assertEqual(
            ["is required", "must be valid"],
            self.errors.get("email")
        )

    def test_clear(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")

        self.errors.clear("email")
        self.assertEqual(0, len(self.errors.get("email")))

    def test_count(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")
        self.errors.add("first_name", "is required")
        self.assertEqual(3, self.errors.count)

    def test_full_messages_for(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")
        self.errors.add("first_name", "is required")

        expected = [
            "Email is required",
            "Email must be valid"
        ]

        self.assertEqual(expected, self.errors.full_messages_for("email"))

    def test_full_messages(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")
        self.errors.add("first_name", "is required")

        self.assertTrue("Email is required" in self.errors.full_messages)
        self.assertTrue("Email must be valid" in self.errors.full_messages)
        self.assertTrue("First Name is required" in self.errors.full_messages)
Exemplo n.º 10
0
 def setUp(self):
     super(ErrorsTest, self).setUp()
     self.errors = Errors()
Exemplo n.º 11
0
class ErrorsTest(unittest.TestCase):
    def setUp(self):
        super(ErrorsTest, self).setUp()
        self.errors = Errors()

    def test_add_error(self):
        self.errors.add("email", "is required")
        self.assertEqual(["is required"], self.errors.get("email"))

    def test_add_errors_to_one_field(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")
        self.assertEqual(["is required", "must be valid"],
                         self.errors.get("email"))

    def test_clear(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")

        self.errors.clear("email")
        self.assertEqual(0, len(self.errors.get("email")))

    def test_count(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")
        self.errors.add("first_name", "is required")
        self.assertEqual(3, self.errors.count)

    def test_full_messages_for(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")
        self.errors.add("first_name", "is required")

        expected = ["Email is required", "Email must be valid"]

        self.assertEqual(expected, self.errors.full_messages_for("email"))

    def test_full_messages(self):
        self.errors.add("email", "is required")
        self.errors.add("email", "must be valid")
        self.errors.add("first_name", "is required")

        self.assertTrue("Email is required" in self.errors.full_messages)
        self.assertTrue("Email must be valid" in self.errors.full_messages)
        self.assertTrue("First Name is required" in self.errors.full_messages)
Exemplo n.º 12
0
 class Target(object):
     f = BaseField("my_field", default=1, required=True)
     errors = Errors()
Exemplo n.º 13
0
 class Target(object):
     afield = TestField("afield", default=-1)
     errors = Errors()
Exemplo n.º 14
0
 class Target(object):
     f = BaseField("my_field", persist=False)
     errors = Errors()
Exemplo n.º 15
0
 class Target(object):
     f = BaseField("my_field", choices=['type_a', 'type_b'])
     errors = Errors()
Exemplo n.º 16
0
 class Target(object):
     f = BaseField("my_field", default=1)
     errors = Errors()
Exemplo n.º 17
0
 class Target(Document):
     f = fields.ObjectIdField("my_field")
     errors = Errors()
Exemplo n.º 18
0
 def setUp(self):
     super(ErrorsTest, self).setUp()
     self.errors = Errors()
Exemplo n.º 19
0
 class Target(Document):
     f = fields.StringField("my_field", max_length=10)
     errors = Errors()
Exemplo n.º 20
0
 class Target(Document):
     f = fields.FloatField("my_float")
     errors = Errors()
Exemplo n.º 21
0
 class Target(Document):
     f = fields.StringField("my_field", required=True, min_length=10)
     errors = Errors()
Exemplo n.º 22
0
 class Target(Document):
     f = fields.FloatField("my_float", max_value=0)
     errors = Errors()
Exemplo n.º 23
0
 class Target(Document):
     f = fields.StringField("my_field")
     errors = Errors()
Exemplo n.º 24
0
 class Target(Document):
     f = fields.FloatField("my_float", required=True, min_value=10)
     errors = Errors()
Exemplo n.º 25
0
 class Target(object):
     f = fields.EmbeddedField("address", Address)
     errors = Errors()
Exemplo n.º 26
0
 class Target(Document):
     f = fields.IntegerField("my_integer")
     errors = Errors()
Exemplo n.º 27
0
 class Target(Document):
     f = fields.BooleanField("my_boolean", default=True, required=True)
     errors = Errors()
Exemplo n.º 28
0
 class Target(Document):
     f = fields.IntegerField("my_integer", max_value=0)
     errors = Errors()
Exemplo n.º 29
0
 class Target(Document):
     f = fields.DateTimeField("my_datetime")
     errors = Errors()
Exemplo n.º 30
0
 class Target(Document):
     f = fields.IntegerField("my_integer", required=True, min_value=10)
     errors = Errors()
Exemplo n.º 31
0
 class Target(Document):
     f = fields.BooleanField("my_boolean", required=False)
     errors = Errors()
Exemplo n.º 32
0
 class Target(Document):
     f = fields.ArrayField("violence", validate_item=validate)
     errors = Errors()