Beispiel #1
0
 def setUp(self):
     self.fields = [
         api.ArgumentsField(False, False),
         api.ArgumentsField(False, True),
         api.ArgumentsField(True, False),
         api.ArgumentsField(True, True)
     ]
Beispiel #2
0
    def test_validate_on_correct_content(self):
        for f in self.fields:
            for val in self.valid_values:
                self.assertIsNone(f.validate(val),
                                  msg=" on content %s (type %s)" %
                                  (val, type(val)))
        # unreqired fields
        for f in (api.ArgumentsField(False,
                                     False), api.ArgumentsField(False, True)):
            self.assertIsNone(f.validate(None), msg="on None")

        # could be empty fields
        for f in (api.ArgumentsField(False,
                                     True), api.ArgumentsField(True, True)):
            for val in self.null_values:
                self.assertIsNone(f.validate(val), msg="on empty(null) values")
Beispiel #3
0
    def test_validate_on_incorrect_content(self):
        for f in self.fields:
            for val in self.invalid_values:
                with self.assertRaises(api.ValidationError,
                                       msg=" on content %s (type %s)" %
                                       (val, type(val))):
                    f.validate(val)

        # required fields
        for f in (api.ArgumentsField(True,
                                     False), api.ArgumentsField(True, True)):
            with self.assertRaises(api.ValidationError, msg=" on None"):
                f.validate(None)

        # empty fields
        for f in (api.ArgumentsField(False,
                                     False), api.ArgumentsField(True, False)):
            for val in self.null_values:
                with self.assertRaises(api.ValidationError,
                                       msg=" on empty content"):
                    f.validate(val)
 class TestRequest(api.Request):
     f = api.ArgumentsField(required=False, nullable=False)
 class TestRequest(api.Request):
     f = api.ArgumentsField(required=True, nullable=True)