From 3027f203206976783ee59c57ff0539987b5bb86d Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Fri, 01 Nov 2013 14:12:21 +0000 Subject: Start tracking regressions against recent prod branch --- diff --git a/tests/__init__.py b/tests/__init__.py index f216936..a82b1f8 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -88,7 +88,7 @@ class Test(unittest.TestCase): node.files_root.value = None node.sync_layers.value = None node.stats_root.value = tmpdir + '/stats' - node.port.value = 8880 + node.port.value = 8888 db.index_write_queue.value = 10 client.local_root.value = tmpdir client.api_url.value = 'http://127.0.0.1:8888' diff --git a/tests/regression/__init__.py b/tests/regression/__init__.py new file mode 100644 index 0000000..ad1971a --- /dev/null +++ b/tests/regression/__init__.py @@ -0,0 +1,9 @@ +# sugar-lint: disable + +import sys +from os.path import dirname, join, abspath + +src_root = abspath(join(dirname(__file__), '..', '..')) +sys.path.insert(0, src_root) + +import tests diff --git a/tests/regression/__main__.py b/tests/regression/__main__.py new file mode 100644 index 0000000..734b919 --- /dev/null +++ b/tests/regression/__main__.py @@ -0,0 +1,8 @@ +# sugar-lint: disable + +from __init__ import tests + +from api import * + +if __name__ == '__main__': + tests.main() diff --git a/tests/regression/api.py b/tests/regression/api.py new file mode 100755 index 0000000..070d0dc --- /dev/null +++ b/tests/regression/api.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python +# sugar-lint: disable + +import os +import json +import signal +import shutil +import zipfile +from cStringIO import StringIO +from os.path import exists, join, dirname, abspath + +from __init__ import tests, src_root + +from sugar_network import toolkit, client, node +from sugar_network.toolkit import http, coroutine + + +PROD_ROOT = join(dirname(abspath(__file__)), 'production') + + +class Api(tests.Test): + + def setUp(self): + tests.Test.setUp(self) + + self.start_online_client() + ipc = client.IPCConnection() + + ipc.upload(['implementation'], StringIO( + self.zips( + ['TestActivity/activity/activity.info', [ + '[Activity]', + 'name = activity1', + 'bundle_id = context1', + 'exec = activity', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]], + ['TestActivity/bin/activity', [ + '#!/bin/sh', + 'echo 1 > $1', + ]], + )), + cmd='submit', initial=True) + ipc.upload(['implementation'], StringIO( + self.zips( + ['TestActivity/activity/activity.info', [ + '[Activity]', + 'name = activity1', + 'bundle_id = context1', + 'exec = activity', + 'icon = icon', + 'activity_version = 2', + 'license = Public Domain', + ]], + ['TestActivity/bin/activity', [ + '#!/bin/sh', + 'echo 2 > $1', + ]], + )), + cmd='submit') + + ipc.upload(['implementation'], StringIO( + self.zips( + ['TestActivity/activity/activity.info', [ + '[Activity]', + 'name = activity2', + 'bundle_id = context2', + 'exec = activity', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]], + ['TestActivity/bin/activity', [ + '#!/bin/sh', + 'echo 3 > $1', + ]], + )), + cmd='submit', initial=True) + ipc.upload(['implementation'], StringIO( + self.zips( + ['TestActivity/activity/activity.info', [ + '[Activity]', + 'name = activity2', + 'bundle_id = context2', + 'exec = activity', + 'icon = icon', + 'activity_version = 2', + 'license = Public Domain', + ]], + ['TestActivity/bin/activity', [ + '#!/bin/sh', + 'echo 4 > $1', + ]], + )), + cmd='submit') + + self.client.close() + client.ipc_port.value = 5001 + self.client_pid = self.popen([join(PROD_ROOT, 'sugar-network-client'), + '-DDDF', 'start', + '--local-root=client', '--mounts-root=mnt', '--cachedir=tmp', + '--ipc-port=%s' % client.ipc_port.value, '--api-url=%s' % client.api_url.value, + ]) + + def tearDown(self): + self.waitpid(self.client_pid, signal.SIGINT) + tests.Test.tearDown(self) + + def test_API(self): + ipc = http.Connection('http://127.0.0.1:%s' % client.ipc_port.value) + + self.assertEqual(True, ipc.get(cmd='inline')) + self.assertEqual({'total': 2, 'result': [ + {'guid': 'context1', 'title': 'activity1'}, + {'guid': 'context2', 'title': 'activity2'}, + ]}, + ipc.get(['context'], reply=['guid', 'title'], order_by='guid')) + + ipc.get(['context', 'context1'], cmd='launch', args=[tests.tmpdir + '/out']) + coroutine.sleep(1) + self.assertEqual('2\n', file('out').read()) + + ipc.put(['context', 'context2'], '1', 'cmd=clone') + self.node.stop() + + ipc.get(['context', 'context2'], cmd='launch', args=[tests.tmpdir + '/out']) + coroutine.sleep(1) + self.assertEqual('4\n', file('out').read()) + + +if __name__ == '__main__': + tests.main() diff --git a/tests/regression/production b/tests/regression/production -Subproject 48b0d50236254b2999794ac384e10ab7991de24 +Subproject aaa4b49902236921ce80ff062398778f320e92a -- cgit v0.9.1