Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/units/db/db_routes.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/db/db_routes.py')
-rwxr-xr-xtests/units/db/db_routes.py49
1 files changed, 48 insertions, 1 deletions
diff --git a/tests/units/db/db_routes.py b/tests/units/db/db_routes.py
index e9f3b28..86c699c 100755
--- a/tests/units/db/db_routes.py
+++ b/tests/units/db/db_routes.py
@@ -19,7 +19,7 @@ from __init__ import tests
from sugar_network import db, toolkit
from sugar_network.db import routes as db_routes
from sugar_network.model.user import User
-from sugar_network.toolkit.router import Router, Request, Response, fallbackroute, ACL, File
+from sugar_network.toolkit.router import Router, Request, Response, fallbackroute, ACL, File, postroute
from sugar_network.toolkit.coroutine import this
from sugar_network.toolkit import coroutine, http, i18n
@@ -1851,6 +1851,53 @@ class DbRoutesTest(tests.Test):
[{'event': 'delete', 'resource': 'document', 'guid': guid}],
events)
+ def test_ThisResourceInPostrouteOnCreation(self):
+
+ class Document(db.Resource):
+
+ @db.stored_property()
+ def prop(self, value):
+ return value
+
+ class Routes(db.Routes):
+
+ @postroute
+ def postroute(self, result, exception):
+ return this.resource.properties(['guid', 'prop'])
+
+ volume = db.Volume(tests.tmpdir, [Document])
+ router = Router(Routes(volume))
+
+ self.assertEqual({
+ 'guid': 'guid',
+ 'prop': 'probe',
+ },
+ this.call(method='POST', path=['document'], content={'guid': 'guid', 'prop': 'probe'}))
+
+ def test_ThisResourceInPostrouteOnDeletion(self):
+
+ class Document(db.Resource):
+
+ @db.stored_property()
+ def prop(self, value):
+ return value
+
+ class Routes(db.Routes):
+
+ @postroute
+ def postroute(self, result, exception):
+ return this.resource.properties(['guid', 'prop'])
+
+ volume = db.Volume(tests.tmpdir, [Document])
+ router = Router(Routes(volume))
+
+ this.call(method='POST', path=['document'], content={'guid': 'guid', 'prop': 'probe'})
+ self.assertEqual({
+ 'guid': 'guid',
+ 'prop': 'probe',
+ },
+ this.call(method='DELETE', path=['document', 'guid']))
+
if __name__ == '__main__':
tests.main()