Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add test for #2 + catch RequireFieldError in addition to StructureError

  • Loading branch information...
commit 09128d05b5b960c65e01929ee496cb517cb2b057 1 parent e1f140a
Éric Araujo merwok authored Pior Bastida committed
6 example/model/message.py
View
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+import datetime
from bson.objectid import ObjectId
@@ -16,6 +17,11 @@ class Message(Document):
'content': unicode,
'application_id': ObjectId,
'user_id': ObjectId,
+ 'created': datetime.datetime,
+ }
+
+ default_values = {
+ 'created': datetime.datetime.utcnow,
}
required_fields = ['from', 'content', 'application_id', 'user_id']
4 pyramid_rest/mongo.py
View
@@ -137,9 +137,9 @@ def create(self, **identifiers):
document[k] = v
try:
document.save()
- except mongokit.StructureError:
+ except (mongokit.StructureError, mongokit.RequireFieldError):
log.exception(
- 'StructureError creating %s, POST: %s, ids: %s',
+ 'error while creating %s, POST: %s, ids: %s',
self.context.resource,
self.request.POST,
identifiers,
5 pyramid_rest/tests/functional/test_mongo.py
View
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
-from bson.objectid import ObjectId
+import datetime
+from bson.objectid import ObjectId
from pyramid.httpexceptions import HTTPBadRequest
from pyramid_rest.tests.functional import TestExampleController
@@ -73,6 +74,7 @@ def test_update(self):
'user_id': ObjectId(self.user_id),
'from': u'Peter Tosh',
'content': u'yo man',
+ 'created': datetime.datetime.utcnow(),
})
message.save()
@@ -84,7 +86,6 @@ def test_update(self):
)
result = self.mongo_db.Message.find_one({'_id': message._id})
-
self.assertEqual(u'yo man 2', result.content)
def test_delete(self):
Please sign in to comment.
Something went wrong with that request. Please try again.