Пример #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()
Пример #2
0
 class Target(Document):
     f = fields.DateTimeField("my_datetime", required=True)
     errors = Errors()
Пример #3
0
 class Order(object):
     f = fields.ListField("orderlines", OrderLine)
     errors = Errors()
Пример #4
0
 class Target(Document):
     f = fields.EmbeddedField("address", Address)
     errors = Errors()
Пример #5
0
 class Target(Document):
     errors = Errors()
Пример #6
0
 class Target(Document):
     f = fields.StringField("my_field", choices=["type_a", "type_b"])
     errors = Errors()
Пример #7
0
 class Target(Document):
     f = fields.StringField("my_field", pattern="^This")
     errors = Errors()
Пример #8
0
 class Target(Document):
     f = fields.ObjectIdField("my_field", required=True)
     errors = Errors()
Пример #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)
Пример #10
0
 def setUp(self):
     super(ErrorsTest, self).setUp()
     self.errors = Errors()
Пример #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)
Пример #12
0
 class Target(object):
     f = BaseField("my_field", default=1, required=True)
     errors = Errors()
Пример #13
0
 class Target(object):
     afield = TestField("afield", default=-1)
     errors = Errors()
Пример #14
0
 class Target(object):
     f = BaseField("my_field", persist=False)
     errors = Errors()
Пример #15
0
 class Target(object):
     f = BaseField("my_field", choices=['type_a', 'type_b'])
     errors = Errors()
Пример #16
0
 class Target(object):
     f = BaseField("my_field", default=1)
     errors = Errors()
Пример #17
0
 class Target(Document):
     f = fields.ObjectIdField("my_field")
     errors = Errors()
Пример #18
0
 def setUp(self):
     super(ErrorsTest, self).setUp()
     self.errors = Errors()
Пример #19
0
 class Target(Document):
     f = fields.StringField("my_field", max_length=10)
     errors = Errors()
Пример #20
0
 class Target(Document):
     f = fields.FloatField("my_float")
     errors = Errors()
Пример #21
0
 class Target(Document):
     f = fields.StringField("my_field", required=True, min_length=10)
     errors = Errors()
Пример #22
0
 class Target(Document):
     f = fields.FloatField("my_float", max_value=0)
     errors = Errors()
Пример #23
0
 class Target(Document):
     f = fields.StringField("my_field")
     errors = Errors()
Пример #24
0
 class Target(Document):
     f = fields.FloatField("my_float", required=True, min_value=10)
     errors = Errors()
Пример #25
0
 class Target(object):
     f = fields.EmbeddedField("address", Address)
     errors = Errors()
Пример #26
0
 class Target(Document):
     f = fields.IntegerField("my_integer")
     errors = Errors()
Пример #27
0
 class Target(Document):
     f = fields.BooleanField("my_boolean", default=True, required=True)
     errors = Errors()
Пример #28
0
 class Target(Document):
     f = fields.IntegerField("my_integer", max_value=0)
     errors = Errors()
Пример #29
0
 class Target(Document):
     f = fields.DateTimeField("my_datetime")
     errors = Errors()
Пример #30
0
 class Target(Document):
     f = fields.IntegerField("my_integer", required=True, min_value=10)
     errors = Errors()
Пример #31
0
 class Target(Document):
     f = fields.BooleanField("my_boolean", required=False)
     errors = Errors()
Пример #32
0
 class Target(Document):
     f = fields.ArrayField("violence", validate_item=validate)
     errors = Errors()