示例#1
0
    def test_validate_kwargs_wrong_data(self):
        kwargs = {"name": 67}

        # raises the validate content has an incorrect value
        with self.assertRaises(AsyncOrmFieldError) as exc:
            book = Book()
            book.validate_kwargs(kwargs)

        self.assertIn("is a wrong datatype for field", exc.exception.args[0])
示例#2
0
    def test_validate_kwargs_with_wrong_fieldname(self):
        kwargs = {"name": "name", "volume": 23}
        # raises the validate error because volume is not a correct attrib
        with self.assertRaises(AsyncOrmModelError) as exc:
            book = Book()
            book.validate_kwargs(kwargs)

        # its a list because we validate all kwargs
        self.assertEqual(exc.exception.args[0],
                         ['"volume" is not an attribute for Book'])
示例#3
0
    def test_validate_kwargs_with_forced_id(self):
        kwargs = {"id": 34, "name": "name"}

        # also raises AsyncOrmFieldError because you can not pre-set the object's id
        with self.assertRaises(AsyncOrmFieldError) as exc:
            book = Book()
            book.validate_kwargs(kwargs)

        self.assertEqual(exc.exception.args[0],
                         "Models can not be generated with forced id")
示例#4
0
    def test_validate_kwargs_no_error(self):
        kwargs = {"name": "name"}

        # now it correctly validates
        book = Book()
        self.assertEqual(book.validate_kwargs(kwargs), None)