Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/units/client/server_routes.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/client/server_routes.py')
-rwxr-xr-xtests/units/client/server_routes.py182
1 files changed, 129 insertions, 53 deletions
diff --git a/tests/units/client/server_routes.py b/tests/units/client/server_routes.py
index d1ffda0..6b36061 100755
--- a/tests/units/client/server_routes.py
+++ b/tests/units/client/server_routes.py
@@ -15,53 +15,7 @@ from sugar_network.toolkit.router import Router
from sugar_network.toolkit import mountpoints, coroutine
-class ServerCommandsTest(tests.Test):
-
- def start_node(self):
- os.makedirs('disk/sugar-network')
- self.node_volume = Volume('db', model.RESOURCES)
- cp = ClientRoutes(self.node_volume)
- trigger = self.wait_for_events(cp, event='inline', state='online')
- coroutine.spawn(mountpoints.monitor, tests.tmpdir)
- trigger.wait()
- server = coroutine.WSGIServer(('127.0.0.1', client.ipc_port.value), Router(cp))
- coroutine.spawn(server.serve_forever)
- coroutine.dispatch()
- return cp
-
- def test_PopulateNode(self):
- os.makedirs('disk/sugar-network')
- volume = Volume('db', model.RESOURCES)
- cp = ClientRoutes(volume)
-
- assert not cp.inline()
- trigger = self.wait_for_events(cp, event='inline', state='online')
- mountpoints.populate('.')
- assert trigger.value is not None
- assert cp.inline()
-
- def test_MountNode(self):
- volume = Volume('db', model.RESOURCES)
- cp = ClientRoutes(volume)
-
- trigger = self.wait_for_events(cp, event='inline', state='online')
- mountpoints.populate('.')
- assert not cp.inline()
- assert trigger.value is None
-
- coroutine.spawn(mountpoints.monitor, '.')
- coroutine.dispatch()
- os.makedirs('disk/sugar-network')
- trigger.wait()
- assert cp.inline()
-
- def test_UnmountNode(self):
- cp = self.start_node()
- assert cp.inline()
- trigger = self.wait_for_events(cp, event='inline', state='offline')
- shutil.rmtree('disk')
- trigger.wait()
- assert not cp.inline()
+class ServerRoutesTest(tests.Test):
def test_whoami(self):
self.start_node()
@@ -71,7 +25,7 @@ class ServerCommandsTest(tests.Test):
{'guid': tests.UID, 'roles': []},
ipc.get(cmd='whoami'))
- def test_subscribe(self):
+ def test_Events(self):
self.start_node()
ipc = IPCConnection()
events = []
@@ -79,7 +33,7 @@ class ServerCommandsTest(tests.Test):
def read_events():
for event in ipc.subscribe(event='!commit'):
events.append(event)
- job = coroutine.spawn(read_events)
+ coroutine.spawn(read_events)
coroutine.dispatch()
guid = ipc.post(['context'], {
@@ -88,19 +42,93 @@ class ServerCommandsTest(tests.Test):
'summary': 'summary',
'description': 'description',
})
- coroutine.dispatch()
ipc.put(['context', guid], {
'title': 'title_2',
})
- coroutine.dispatch()
- coroutine.sleep(.5)
- job.kill()
+ coroutine.sleep(.1)
+ ipc.delete(['context', guid])
+ coroutine.sleep(.1)
+
+ self.assertEqual([
+ {'guid': guid, 'resource': 'context', 'event': 'create'},
+ {'guid': guid, 'resource': 'context', 'event': 'update'},
+ {'guid': guid, 'event': 'delete', 'resource': 'context'},
+ ],
+ events)
+ del events[:]
+
+ guid = self.node_volume['context'].create({
+ 'type': 'activity',
+ 'title': 'title',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+ self.node_volume['context'].update(guid, {
+ 'title': 'title_2',
+ })
+ coroutine.sleep(.1)
+ self.node_volume['context'].delete(guid)
+ coroutine.sleep(.1)
+
+ self.assertEqual([
+ {'guid': guid, 'resource': 'context', 'event': 'create'},
+ {'guid': guid, 'resource': 'context', 'event': 'update'},
+ {'guid': guid, 'event': 'delete', 'resource': 'context'},
+ ],
+ events)
+ del events[:]
+
+ guid = self.home_volume['context'].create({
+ 'type': 'activity',
+ 'title': 'title',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+ self.home_volume['context'].update(guid, {
+ 'title': 'title_2',
+ })
+ coroutine.sleep(.1)
+ self.home_volume['context'].delete(guid)
+ coroutine.sleep(.1)
+
+ self.assertEqual([], events)
+ return
+
+ self.node.stop()
+ coroutine.sleep(.1)
+ del events[:]
+
+ guid = self.home_volume['context'].create({
+ 'type': 'activity',
+ 'title': 'title',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+ self.home_volume['context'].update(guid, {
+ 'title': 'title_2',
+ })
+ coroutine.sleep(.1)
+ self.home_volume['context'].delete(guid)
+ coroutine.sleep(.1)
self.assertEqual([
{'guid': guid, 'resource': 'context', 'event': 'create'},
{'guid': guid, 'resource': 'context', 'event': 'update'},
+ {'guid': guid, 'event': 'delete', 'resource': 'context'},
],
events)
+ del events[:]
+
+
+
+
+
+
+
+
+
+
+
def test_BLOBs(self):
self.start_node()
@@ -134,6 +162,54 @@ class ServerCommandsTest(tests.Test):
[{'icon': 'http://127.0.0.1:5555/static/images/missing.png'}],
ipc.get(['context'], reply=['icon'])['result'])
+ def test_PopulateNode(self):
+ os.makedirs('disk/sugar-network')
+ volume = Volume('db', model.RESOURCES)
+ cp = ClientRoutes(volume)
+
+ assert not cp.inline()
+ trigger = self.wait_for_events(cp, event='inline', state='online')
+ mountpoints.populate('.')
+ coroutine.dispatch()
+ assert trigger.value is not None
+ assert cp.inline()
+
+ def test_MountNode(self):
+ volume = Volume('db', model.RESOURCES)
+ cp = ClientRoutes(volume)
+
+ trigger = self.wait_for_events(cp, event='inline', state='online')
+ mountpoints.populate('.')
+ assert not cp.inline()
+ assert trigger.value is None
+
+ coroutine.spawn(mountpoints.monitor, '.')
+ coroutine.dispatch()
+ os.makedirs('disk/sugar-network')
+ trigger.wait()
+ assert cp.inline()
+
+ def test_UnmountNode(self):
+ cp = self.start_node()
+ assert cp.inline()
+ trigger = self.wait_for_events(cp, event='inline', state='offline')
+ shutil.rmtree('disk')
+ trigger.wait()
+ assert not cp.inline()
+
+ def start_node(self):
+ os.makedirs('disk/sugar-network')
+ self.home_volume = Volume('db', model.RESOURCES)
+ cp = ClientRoutes(self.home_volume)
+ trigger = self.wait_for_events(cp, event='inline', state='online')
+ coroutine.spawn(mountpoints.monitor, tests.tmpdir)
+ trigger.wait()
+ self.node_volume = cp._node.volume
+ server = coroutine.WSGIServer(('127.0.0.1', client.ipc_port.value), Router(cp))
+ coroutine.spawn(server.serve_forever)
+ coroutine.dispatch()
+ return cp
+
if __name__ == '__main__':
tests.main()