Add unit tests for UUIDField
This commit is contained in:
		| @@ -1,9 +1,7 @@ | |||||||
| import unittest | import unittest | ||||||
| import datetime | import datetime | ||||||
| from decimal import Decimal | from decimal import Decimal | ||||||
|  | import uuid | ||||||
| import pymongo |  | ||||||
| import gridfs |  | ||||||
|  |  | ||||||
| from mongoengine import * | from mongoengine import * | ||||||
| from mongoengine.connection import _get_db | from mongoengine.connection import _get_db | ||||||
| @@ -175,6 +173,26 @@ class FieldTest(unittest.TestCase): | |||||||
|         person.admin = 'Yes' |         person.admin = 'Yes' | ||||||
|         self.assertRaises(ValidationError, person.validate) |         self.assertRaises(ValidationError, person.validate) | ||||||
|  |  | ||||||
|  |     def test_uuid_validation(self): | ||||||
|  |         """Ensure that invalid values cannot be assigned to UUID fields. | ||||||
|  |         """ | ||||||
|  |         class Person(Document): | ||||||
|  |             api_key = UUIDField() | ||||||
|  |  | ||||||
|  |         person = Person() | ||||||
|  |         # any uuid type is valid | ||||||
|  |         person.api_key = uuid.uuid4() | ||||||
|  |         person.validate() | ||||||
|  |         person.api_key = uuid.uuid1() | ||||||
|  |         person.validate() | ||||||
|  |  | ||||||
|  |         # last g cannot belong to an hex number | ||||||
|  |         person.api_key = '9d159858-549b-4975-9f98-dd2f987c113g' | ||||||
|  |         self.assertRaises(ValidationError, person.validate) | ||||||
|  |         # short strings don't validate | ||||||
|  |         person.api_key = '9d159858-549b-4975-9f98-dd2f987c113' | ||||||
|  |         self.assertRaises(ValidationError, person.validate) | ||||||
|  |  | ||||||
|     def test_datetime_validation(self): |     def test_datetime_validation(self): | ||||||
|         """Ensure that invalid values cannot be assigned to datetime fields. |         """Ensure that invalid values cannot be assigned to datetime fields. | ||||||
|         """ |         """ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user