diff options
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/client/__main__.py | 5 | ||||
-rwxr-xr-x | tests/units/client/cache.py | 319 | ||||
-rwxr-xr-x | tests/units/client/injector.py | 968 | ||||
-rwxr-xr-x | tests/units/client/packagekit.py | 25 | ||||
-rwxr-xr-x | tests/units/client/releases.py | 502 | ||||
-rwxr-xr-x | tests/units/client/solver.py | 277 | ||||
-rwxr-xr-x | tests/units/model/context.py | 1 | ||||
-rwxr-xr-x | tests/units/node/model.py | 90 | ||||
-rwxr-xr-x | tests/units/node/node.py | 6 | ||||
-rwxr-xr-x | tests/units/node/slave.py | 8 | ||||
-rwxr-xr-x | tests/units/toolkit/router.py | 27 |
11 files changed, 1066 insertions, 1162 deletions
diff --git a/tests/units/client/__main__.py b/tests/units/client/__main__.py index 849cf0b..5d48161 100644 --- a/tests/units/client/__main__.py +++ b/tests/units/client/__main__.py @@ -3,13 +3,12 @@ from __init__ import tests from journal import * -from solver import * from routes import * from offline_routes import * from online_routes import * from server_routes import * -from cache import * -from releases import * +from injector import * +from packagekit import * if __name__ == '__main__': tests.main() diff --git a/tests/units/client/cache.py b/tests/units/client/cache.py deleted file mode 100755 index 51245ee..0000000 --- a/tests/units/client/cache.py +++ /dev/null @@ -1,319 +0,0 @@ -#!/usr/bin/env python -# sugar-lint: disable - -import os -import time -import json -import shutil -from cStringIO import StringIO -from os.path import exists - -from __init__ import tests - -from sugar_network import db -from sugar_network.model.context import Context -from sugar_network.client import cache_limit, cache_limit_percent, cache_lifetime, IPCConnection -from sugar_network.client.cache import Cache -from sugar_network.toolkit import http - - -class CacheTest(tests.Test): - - def setUp(self): - tests.Test.setUp(self) - - class statvfs(object): - f_blocks = 100 - f_bfree = 100 - f_frsize = 1 - - self.statvfs = statvfs - self.override(os, 'statvfs', lambda *args: statvfs()) - - def test_open(self): - volume = db.Volume('db', [Context]) - - volume['release'].create({ - 'guid': '1', - 'context': 'context', - 'license': ['GPL'], - 'version': '1', - 'stability': 'stable', - 'data': {'blob_size': 1}, - }) - os.utime('db/release/1/1', (1, 1)) - volume['release'].create({ - 'guid': '5', - 'context': 'context', - 'license': ['GPL'], - 'version': '5', - 'stability': 'stable', - 'data': {'blob_size': 5}, - }) - os.utime('db/release/5/5', (5, 5)) - volume['release'].create({ - 'guid': '2', - 'context': 'context', - 'license': ['GPL'], - 'version': '2', - 'stability': 'stable', - 'data': {}, - }) - os.utime('db/release/2/2', (2, 2)) - volume['release'].create({ - 'guid': '3', - 'context': 'context', - 'license': ['GPL'], - 'version': '3', - 'stability': 'stable', - }) - os.utime('db/release/3/3', (3, 3)) - volume['release'].create({ - 'guid': '4', - 'context': 'context', - 'license': ['GPL'], - 'version': '4', - 'stability': 'stable', - 'data': {'blob_size': 4, 'unpack_size': 44}, - }) - os.utime('db/release/4/4', (4, 4)) - - cache = Cache(volume) - self.assertEqual(['5', '4', '1'], [i for i in cache]) - - def test_open_IgnoreClones(self): - volume = db.Volume('db', [Context]) - - volume['context'].create({ - 'guid': 'context', - 'type': 'activity', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) - volume['release'].create({ - 'guid': 'impl', - 'context': 'context', - 'license': ['GPL'], - 'version': '1', - 'stability': 'stable', - 'data': {'blob_size': 1}, - }) - - cache = Cache(volume) - self.assertEqual(['impl'], [i for i in cache]) - - os.symlink('../../../release/im/impl', 'db/context/co/context/.clone') - cache = Cache(volume) - self.assertEqual([], [i for i in cache]) - - def test_ensure_AfterOpen(self): - volume = db.Volume('db', [Context]) - - volume['release'].create({'data': {'blob_size': 1}, 'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/release/1/1', (1, 1)) - volume['release'].create({'data': {'blob_size': 2}, 'guid': '2', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/release/2/2', (2, 2)) - volume['release'].create({'data': {'blob_size': 3}, 'guid': '3', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/release/3/3', (3, 3)) - cache = Cache(volume) - cache_limit.value = 10 - self.statvfs.f_bfree = 11 - - self.assertRaises(RuntimeError, cache.ensure, 100, 0) - assert volume['release'].exists('1') - assert volume['release'].exists('2') - assert volume['release'].exists('3') - - cache.ensure(1, 0) - assert volume['release'].exists('1') - assert volume['release'].exists('2') - assert volume['release'].exists('3') - - cache.ensure(2, 0) - assert not volume['release'].exists('1') - assert volume['release'].exists('2') - assert volume['release'].exists('3') - - cache.ensure(4, 0) - assert not volume['release'].exists('2') - assert not volume['release'].exists('3') - - self.assertRaises(RuntimeError, cache.ensure, 2, 0) - - def test_ensure_Live(self): - volume = db.Volume('db', [Context]) - - cache = Cache(volume) - # To initiate the cache - cache.ensure(0, 0) - - volume['release'].create({'data': {'blob_size': 1}, 'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - cache.checkin('1', 1) - - cache_limit.value = 10 - self.statvfs.f_bfree = 10 - cache.ensure(1, 0) - assert not volume['release'].exists('1') - self.assertRaises(RuntimeError, cache.ensure, 1, 0) - - def test_ensure_ConsiderTmpSize(self): - volume = db.Volume('db', [Context]) - volume['release'].create({'data': {'blob_size': 1}, 'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - - cache = Cache(volume) - cache_limit.value = 10 - self.statvfs.f_bfree = 10 - - self.assertRaises(RuntimeError, cache.ensure, 1, 11) - assert volume['release'].exists('1') - - cache.ensure(1, 10) - assert not volume['release'].exists('1') - - def test_recycle(self): - ts = time.time() - - volume = db.Volume('db', [Context]) - volume['release'].create({'data': {'blob_size': 1}, 'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/release/1/1', (ts - 1.5 * 86400, ts - 1.5 * 86400)) - volume['release'].create({'data': {'blob_size': 1}, 'guid': '2', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/release/2/2', (ts - 2.5 * 86400, ts - 2.5 * 86400)) - volume['release'].create({'data': {'blob_size': 1}, 'guid': '3', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/release/3/3', (ts - 3.5 * 86400, ts - 3.5 * 86400)) - cache = Cache(volume) - - cache_lifetime.value = 4 - cache.recycle() - assert volume['release'].exists('1') - assert volume['release'].exists('2') - assert volume['release'].exists('3') - - cache_lifetime.value = 3 - cache.recycle() - assert volume['release'].exists('1') - assert volume['release'].exists('2') - assert not volume['release'].exists('3') - - cache_lifetime.value = 1 - cache.recycle() - assert not volume['release'].exists('1') - assert not volume['release'].exists('2') - assert not volume['release'].exists('3') - - cache.recycle() - - def test_checkin(self): - volume = db.Volume('db', [Context]) - cache = Cache(volume) - - volume['release'].create({'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - volume['release'].create({'guid': '2', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - volume['release'].create({'guid': '3', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - - cache.checkin('1', 1) - self.assertEqual(['1'], [i for i in cache]) - self.assertEqual(1, cache.du) - - cache.checkin('2', 2) - self.assertEqual(['2', '1'], [i for i in cache]) - self.assertEqual(3, cache.du) - - cache.checkin('3', 3) - self.assertEqual(['3', '2', '1'], [i for i in cache]) - self.assertEqual(6, cache.du) - - def test_checkout(self): - local_volume = self.start_online_client() - conn = IPCConnection() - self.statvfs.f_blocks = 0 - - bundle = self.zips(['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = context', - 'exec = true', - 'icon = icon', - 'activity_version = 1', - 'license = Public Domain', - 'stability = stable', - ]]) - impl1 = conn.upload(['release'], StringIO(bundle), cmd='submit', initial=True) - print self.blobs[str(hash(bundle))] - conn.put(['context', 'context'], True, cmd='clone') - print self.blobs[str(hash(bundle))] - return - self.assertEqual([], [i for i in self.client_routes._cache]) - assert local_volume['release'].exists(impl1) - - conn.put(['context', 'context'], False, cmd='clone') - self.assertEqual([impl1], [i for i in self.client_routes._cache]) - assert local_volume['release'].exists(impl1) - - impl2 = conn.upload(['release'], StringIO(self.zips(['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = context', - 'exec = true', - 'icon = icon', - 'activity_version = 2', - 'license = Public Domain', - 'stability = stable', - ]])), cmd='submit', initial=True) - - shutil.rmtree('solutions') - conn.put(['context', 'context'], True, cmd='clone') - self.assertEqual([impl1], [i for i in self.client_routes._cache]) - assert local_volume['release'].exists(impl1) - assert local_volume['release'].exists(impl2) - - conn.put(['context', 'context'], False, cmd='clone') - self.assertEqual([impl2, impl1], [i for i in self.client_routes._cache]) - assert local_volume['release'].exists(impl1) - assert local_volume['release'].exists(impl2) - - def test_Acquiring(self): - volume = db.Volume('db', [Context]) - cache = Cache(volume) - - volume['release'].create({'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - volume['release'].create({'guid': '2', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - volume['release'].create({'guid': '3', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - - cache.checkin('1', 1) - self.assertEqual(['1'], [i for i in cache]) - self.assertEqual(1, cache.du) - - cache.acquire('1', 2) - self.assertEqual([], [i for i in cache]) - self.assertEqual(0, cache.du) - cache.acquire('1', 3) - self.assertEqual([], [i for i in cache]) - self.assertEqual(0, cache.du) - cache.acquire('2', 1) - self.assertEqual([], [i for i in cache]) - self.assertEqual(0, cache.du) - cache.acquire('2', 2) - self.assertEqual([], [i for i in cache]) - self.assertEqual(0, cache.du) - cache.acquire('2', 3) - self.assertEqual([], [i for i in cache]) - self.assertEqual(0, cache.du) - - cache.release('1', '2') - self.assertEqual([], [i for i in cache]) - self.assertEqual(0, cache.du) - cache.release('1', '2') - self.assertEqual(['1'], [i for i in cache]) - self.assertEqual(2, cache.du) - cache.release('2') - self.assertEqual(['2', '1'], [i for i in cache]) - self.assertEqual(3, cache.du) - - cache.release('1', '2') - self.assertEqual(['2', '1'], [i for i in cache]) - self.assertEqual(3, cache.du) - - -if __name__ == '__main__': - tests.main() diff --git a/tests/units/client/injector.py b/tests/units/client/injector.py new file mode 100755 index 0000000..4b12fe2 --- /dev/null +++ b/tests/units/client/injector.py @@ -0,0 +1,968 @@ +#!/usr/bin/env python +# sugar-lint: disable + +import os +import time +import json +import shutil +import hashlib +from cStringIO import StringIO +from os.path import exists, join, basename + +from __init__ import tests + +from sugar_network import db, client +from sugar_network.client import Connection, keyfile, api, packagekit, injector as injector_ +from sugar_network.client.injector import _PreemptivePool, Injector +from sugar_network.toolkit import http, lsb_release + + +class InjectorTest(tests.Test): + + def setUp(self): + tests.Test.setUp(self) + + class statvfs(object): + f_blocks = 100 + f_bfree = 999999999 + f_frsize = 1 + + self.statvfs = statvfs + self.override(os, 'statvfs', lambda *args: statvfs()) + + def test_PreemptivePool_push(self): + cache = _PreemptivePool('releases', None, None, None) + + self.touch(('releases/1', '1')) + self.utime('releases/1', 1) + self.touch(('releases/2', '2')) + self.utime('releases/2', 2) + self.touch(('releases/3', '3')) + self.utime('releases/3', 3) + + cache.push([{'blob': '1', 'size': 11}]) + cache.push([{'blob': '2', 'size': 1000, 'unpack_size': 22}]) + cache.push([{'size': 2000}]) + self.assertEqual([ + ('1', (11, 1)), + ('2', (22, 2)), + ], + [i for i in cache]) + self.assertEqual(33, cache._du) + + cache.push([{'size': 3000}]) + cache.push([{'blob': '3', 'size': 1000, 'unpack_size': 33}]) + self.assertEqual([ + ('1', (11, 1)), + ('2', (22, 2)), + ('3', (33, 3)), + ], + [i for i in cache]) + self.assertEqual(66, cache._du) + + def test_PreemptivePool_pop(self): + cache = _PreemptivePool('releases', None, None, None) + + self.touch(('releases/1', '1')) + self.utime('releases/1', 1) + self.touch(('releases/2', '2')) + self.utime('releases/2', 2) + self.touch(('releases/3', '3')) + self.utime('releases/3', 3) + + cache.push([{'blob': '1', 'size': 1}]) + cache.push([{'blob': '2', 'size': 2}]) + cache.push([{'blob': '3', 'size': 3}]) + self.assertEqual( + [('1', (1, 1)), ('2', (2, 2)), ('3', (3, 3))], + [i for i in cache]) + self.assertEqual(6, cache._du) + + assert not cache.pop([{'blob': 'fake'}]) + self.assertEqual( + [('1', (1, 1)), ('2', (2, 2)), ('3', (3, 3))], + [i for i in cache]) + self.assertEqual(6, cache._du) + assert exists('releases/1') + assert exists('releases/2') + assert exists('releases/3') + + assert cache.pop([{'blob': '2'}]) + self.assertEqual( + [('1', (1, 1)), ('3', (3, 3))], + [i for i in cache]) + self.assertEqual(4, cache._du) + assert exists('releases/1') + assert exists('releases/2') + assert exists('releases/3') + + assert cache.pop([{'blob': '1'}]) + self.assertEqual( + [('3', (3, 3))], + [i for i in cache]) + self.assertEqual(3, cache._du) + assert exists('releases/1') + assert exists('releases/2') + assert exists('releases/3') + + assert cache.pop([{'blob': '3'}]) + self.assertEqual( + [], + [i for i in cache]) + self.assertEqual(0, cache._du) + assert exists('releases/1') + assert exists('releases/2') + assert exists('releases/3') + + def test_PreemptivePool_RestoreAfterClosing(self): + cache = _PreemptivePool('./releases', None, None, None) + + self.touch(('releases/1', '1')) + self.utime('releases/1', 1) + cache.push([{'blob': '1', 'size': 1}]) + + self.assertEqual( + [('1', (1, 1))], + [i for i in cache]) + self.assertEqual(1, cache._du) + + assert not exists('releases.index') + cache.close() + assert exists('releases.index') + + cache2 = _PreemptivePool('./releases', None, None, None) + self.assertEqual( + [('1', [1, 1])], + [i for i in cache2]) + self.assertEqual(1, cache2._du) + + def test_PreemptivePool_EnsureLimitInBytes(self): + cache = _PreemptivePool('./releases', None, 10, None) + self.statvfs.f_bfree = 11 + + self.touch(('releases/1', '1')) + self.utime('releases/1', 1) + cache.push([{'blob': '1', 'size': 5}]) + + self.touch(('releases/2', '2')) + self.utime('releases/2', 2) + cache.push([{'blob': '2', 'size': 5}]) + + self.assertRaises(RuntimeError, cache.ensure, 12, 0) + self.assertEqual( + [('1', (5, 1)), ('2', (5, 2))], + [i for i in cache]) + self.assertEqual(10, cache._du) + assert exists('releases/1') + assert exists('releases/2') + + cache.ensure(1, 0) + self.assertEqual( + [('1', (5, 1)), ('2', (5, 2))], + [i for i in cache]) + self.assertEqual(10, cache._du) + assert exists('releases/1') + assert exists('releases/2') + + cache.ensure(2, 0) + self.assertEqual( + [('2', (5, 2))], + [i for i in cache]) + self.assertEqual(5, cache._du) + assert not exists('releases/1') + assert exists('releases/2') + + cache.ensure(1, 0) + self.assertEqual( + [('2', (5, 2))], + [i for i in cache]) + self.assertEqual(5, cache._du) + assert not exists('releases/1') + assert exists('releases/2') + + self.assertRaises(RuntimeError, cache.ensure, 7, 0) + self.assertEqual( + [('2', (5, 2))], + [i for i in cache]) + self.assertEqual(5, cache._du) + assert not exists('releases/1') + assert exists('releases/2') + + cache.ensure(6, 0) + self.assertEqual( + [], + [i for i in cache]) + self.assertEqual(0, cache._du) + assert not exists('releases/1') + assert not exists('releases/2') + + def test_PreemptivePool_EnsureLimitInPercents(self): + cache = _PreemptivePool('./releases', None, None, 10) + self.statvfs.f_bfree = 11 + + self.touch(('releases/1', '1')) + self.utime('releases/1', 1) + cache.push([{'blob': '1', 'size': 5}]) + + self.touch(('releases/2', '2')) + self.utime('releases/2', 2) + cache.push([{'blob': '2', 'size': 5}]) + + self.assertRaises(RuntimeError, cache.ensure, 12, 0) + self.assertEqual( + [('1', (5, 1)), ('2', (5, 2))], + [i for i in cache]) + self.assertEqual(10, cache._du) + assert exists('releases/1') + assert exists('releases/2') + + cache.ensure(1, 0) + self.assertEqual( + [('1', (5, 1)), ('2', (5, 2))], + [i for i in cache]) + self.assertEqual(10, cache._du) + assert exists('releases/1') + assert exists('releases/2') + + cache.ensure(2, 0) + self.assertEqual( + [('2', (5, 2))], + [i for i in cache]) + self.assertEqual(5, cache._du) + assert not exists('releases/1') + assert exists('releases/2') + + cache.ensure(1, 0) + self.assertEqual( + [('2', (5, 2))], + [i for i in cache]) + self.assertEqual(5, cache._du) + assert not exists('releases/1') + assert exists('releases/2') + + self.assertRaises(RuntimeError, cache.ensure, 7, 0) + self.assertEqual( + [('2', (5, 2))], + [i for i in cache]) + self.assertEqual(5, cache._du) + assert not exists('releases/1') + assert exists('releases/2') + + cache.ensure(6, 0) + self.assertEqual( + [], + [i for i in cache]) + self.assertEqual(0, cache._du) + assert not exists('releases/1') + assert not exists('releases/2') + + def test_PreemptivePool_EnsureWithTmpSize(self): + cache = _PreemptivePool('./releases', None, 10, None) + self.statvfs.f_bfree = 11 + + self.touch(('releases/1', '1')) + self.utime('releases/1', 1) + cache.push([{'blob': '1', 'size': 5}]) + + self.assertRaises(RuntimeError, cache.ensure, 7, 0) + self.assertEqual( + [('1', (5, 1))], + [i for i in cache]) + self.assertEqual(5, cache._du) + assert exists('releases/1') + + cache.ensure(6, 0) + self.assertEqual( + [], + [i for i in cache]) + self.assertEqual(0, cache._du) + assert not exists('releases/1') + + self.touch(('releases/1', '1')) + self.utime('releases/1', 1) + cache.push([{'blob': '1', 'size': 5}]) + + cache.ensure(6, 10) + self.assertEqual( + [], + [i for i in cache]) + self.assertEqual(0, cache._du) + assert not exists('releases/1') + + self.touch(('releases/1', '1')) + self.utime('releases/1', 1) + cache.push([{'blob': '1', 'size': 5}]) + + self.assertRaises(RuntimeError, cache.ensure, 6, 11) + self.assertEqual( + [('1', (5, 1))], + [i for i in cache]) + self.assertEqual(5, cache._du) + assert exists('releases/1') + + def test_PreemptivePool_RecycleByLifetime(self): + cache = _PreemptivePool('./releases', 1, None, None) + + self.touch(('releases/1', '1')) + self.utime('releases/1', 0) + cache.push([{'blob': '1', 'size': 1}]) + self.touch(('releases/2', '2')) + self.utime('releases/2', 86400) + cache.push([{'blob': '2', 'size': 1}]) + + self.override(time, 'time', lambda: 86400) + cache.recycle() + self.assertEqual( + [('1', (1, 0)), ('2', (1, 86400))], + [i for i in cache]) + self.assertEqual(2, cache._du) + assert exists('releases/1') + assert exists('releases/2') + + self.override(time, 'time', lambda: 86400 * 1.5) + cache.recycle() + self.assertEqual( + [('2', (1, 86400))], + [i for i in cache]) + self.assertEqual(1, cache._du) + assert not exists('releases/1') + assert exists('releases/2') + + self.override(time, 'time', lambda: 86400 * 1.5) + cache.recycle() + self.assertEqual( + [('2', (1, 86400))], + [i for i in cache]) + self.assertEqual(1, cache._du) + assert not exists('releases/1') + assert exists('releases/2') + + self.override(time, 'time', lambda: 86400 * 2.5) + cache.recycle() + self.assertEqual( + [], + [i for i in cache]) + self.assertEqual(0, cache._du) + assert not exists('releases/1') + assert not exists('releases/2') + + def test_solve(self): + self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + activity_info = '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]) + activity_bundle = self.zips(('topdir/activity/activity.info', activity_info)) + release = conn.upload(['context'], activity_bundle, cmd='submit', initial=True) + + solution = { + 'context': { + 'blob': release, + 'command': ['activity', 'true'], + 'content-type': 'application/vnd.olpc-sugar', + 'size': len(activity_bundle), + 'title': 'Activity', + 'unpack_size': len(activity_info), + 'version': [[1], 0], + }, + } + self.assertEqual(solution, injector._solve('context', 'stable')) + self.assertEqual([client.api.value, 'stable', 0, solution], json.load(file('client/solutions/context'))) + + def test_solve_FailInOffline(self): + self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = None + injector.seqno = 0 + + activity_info = '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]) + activity_bundle = self.zips(('topdir/activity/activity.info', activity_info)) + release = conn.upload(['context'], activity_bundle, cmd='submit', initial=True) + + self.assertRaises(RuntimeError, injector._solve, 'context', 'stable') + + def test_solve_ReuseCachedSolution(self): + volume = self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]))), cmd='submit', initial=True) + + assert 'context' in injector._solve('context', 'stable') + volume['context'].delete('context') + assert 'context' in injector._solve('context', 'stable') + os.unlink('client/solutions/context') + self.assertRaises(http.NotFound, injector._solve, 'context', 'stable') + + def test_solve_InvalidateCachedSolution(self): + volume = self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = 'http://127.0.0.1:7777' + injector.seqno = 1 + + conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]))), cmd='submit', initial=True) + self.assertEqual([[1], 0], injector._solve('context', 'stable')['context']['version']) + self.assertEqual(['http://127.0.0.1:7777', 'stable', 1], json.load(file('client/solutions/context'))[:-1]) + + conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 2', + 'license = Public Domain', + ]))), cmd='submit') + self.assertEqual([[1], 0], injector._solve('context', 'stable')['context']['version']) + self.assertEqual(['http://127.0.0.1:7777', 'stable', 1], json.load(file('client/solutions/context'))[:-1]) + injector.seqno = 2 + self.assertEqual([[2], 0], injector._solve('context', 'stable')['context']['version']) + self.assertEqual(['http://127.0.0.1:7777', 'stable', 2], json.load(file('client/solutions/context'))[:-1]) + + conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 0', + 'license = Public Domain', + 'stability = testing', + ]))), cmd='submit') + self.assertEqual([[2], 0], injector._solve('context', 'stable')['context']['version']) + self.assertEqual(['http://127.0.0.1:7777', 'stable', 2], json.load(file('client/solutions/context'))[:-1]) + self.assertEqual([[0], 0], injector._solve('context', 'testing')['context']['version']) + self.assertEqual(['http://127.0.0.1:7777', 'testing', 2], json.load(file('client/solutions/context'))[:-1]) + + self.assertEqual([[2], 0], injector._solve('context', 'stable')['context']['version']) + self.assertEqual(['http://127.0.0.1:7777', 'stable', 2], json.load(file('client/solutions/context'))[:-1]) + conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 3', + 'license = Public Domain', + ]))), cmd='submit') + self.assertEqual([[2], 0], injector._solve('context', 'stable')['context']['version']) + self.assertEqual(['http://127.0.0.1:7777', 'stable', 2], json.load(file('client/solutions/context'))[:-1]) + injector.api = 'http://localhost:7777' + self.assertEqual([[3], 0], injector._solve('context', 'stable')['context']['version']) + self.assertEqual(['http://localhost:7777', 'stable', 2], json.load(file('client/solutions/context'))[:-1]) + + def test_solve_ForceUsingStaleCachedSolutionInOffline(self): + volume = self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]))), cmd='submit', initial=True) + self.assertEqual([[1], 0], injector._solve('context', 'stable')['context']['version']) + self.assertEqual([client.api.value, 'stable', 0], json.load(file('client/solutions/context'))[:-1]) + + injector.api = None + injector.seqno = 1 + self.assertEqual([[1], 0], injector._solve('context', 'stable')['context']['version']) + self.assertEqual([client.api.value, 'stable', 0], json.load(file('client/solutions/context'))[:-1]) + + os.unlink('client/solutions/context') + self.assertRaises(RuntimeError, injector._solve, 'context', 'stable') + + def test_download_SetExecPermissions(self): + volume = self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + release = conn.upload(['context'], self.zips( + ('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ])), + 'topdir/activity/foo', + 'topdir/bin/bar', + 'topdir/bin/probe', + 'topdir/file1', + 'topdir/test/file2', + ), cmd='submit', initial=True) + for __ in injector.checkin('context'): + pass + + path = 'client/releases/%s/' % release + assert os.access(path + 'activity/foo', os.X_OK) + assert os.access(path + 'bin/bar', os.X_OK) + assert os.access(path + 'bin/probe', os.X_OK) + assert not os.access(path + 'file1', os.X_OK) + assert not os.access(path + 'test/file2', os.X_OK) + + def test_checkin(self): + self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + activity_info = '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]) + activity_bundle = self.zips(('topdir/activity/activity.info', activity_info)) + release = conn.upload(['context'], activity_bundle, cmd='submit', initial=True) + + self.assertEqual([ + {'event': 'checkin', 'state': 'solve'}, + {'event': 'checkin', 'state': 'download'}, + {'event': 'checkin', 'state': 'ready'}, + ], + [i for i in injector.checkin('context')]) + + self.assertEqual(activity_info, file(join('client', 'releases', release, 'activity', 'activity.info')).read()) + self.assertEqual([client.api.value, 'stable', 0, { + 'context': { + 'title': 'Activity', + 'unpack_size': len(activity_info), + 'version': [[1], 0], + 'command': ['activity', 'true'], + 'blob': release, + 'size': len(activity_bundle), + 'content-type': 'application/vnd.olpc-sugar', + }}], + json.load(file('client/solutions/context'))) + self.assertEqual({ + 'context': [client.api.value, 'stable', 0], + }, + json.load(file('client/checkins'))) + self.assertEqual(0, injector._pool._du) + + self.assertEqual([ + {'event': 'checkin', 'state': 'solve'}, + {'event': 'checkin', 'state': 'ready'}, + ], + [i for i in injector.checkin('context')]) + + def test_checkin_PreemptivePool(self): + self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + activity_info = '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]) + activity_bundle = self.zips(('topdir/activity/activity.info', activity_info)) + release = conn.upload(['context'], activity_bundle, cmd='submit', initial=True) + + for __ in injector.checkin('context'): + pass + assert exists(join('client', 'releases', release)) + self.assertEqual({ + 'context': [client.api.value, 'stable', 0], + }, + json.load(file('client/checkins'))) + self.assertEqual(0, injector._pool._du) + + assert injector.checkout('context') + assert exists(join('client', 'releases', release)) + self.assertEqual({ + }, + json.load(file('client/checkins'))) + self.assertEqual(len(activity_info), injector._pool._du) + + for __ in injector.checkin('context'): + pass + assert exists(join('client', 'releases', release)) + self.assertEqual({ + 'context': [client.api.value, 'stable', 0], + }, + json.load(file('client/checkins'))) + self.assertEqual(0, injector._pool._du) + + assert injector.checkout('context') + assert not injector.checkout('context') + + assert exists(join('client', 'releases', release)) + self.assertEqual({ + }, + json.load(file('client/checkins'))) + self.assertEqual(len(activity_info), injector._pool._du) + + def test_checkin_Refresh(self): + volume = self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + release1 = conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]))), cmd='submit', initial=True) + for __ in injector.checkin('context'): + pass + assert exists('client/releases/%s' % release1) + + release2 = conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 2', + 'license = Public Domain', + ]))), cmd='submit') + injector.seqno = 1 + for __ in injector.checkin('context'): + pass + assert exists('client/releases/%s' % release2) + + def test_launch(self): + self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + activity_info = '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]) + activity_bundle = self.zips(('topdir/activity/activity.info', activity_info)) + release = conn.upload(['context'], activity_bundle, cmd='submit', initial=True) + + self.assertEqual([ + {'activity_id': 'activity_id'}, + {'event': 'launch', 'state': 'init'}, + {'event': 'launch', 'state': 'solve'}, + {'event': 'launch', 'state': 'download'}, + {'event': 'launch', 'state': 'exec'}, + {'context': 'context', + 'solution': { + 'context': { + 'title': 'Activity', + 'command': ['activity', 'true'], + 'content-type': 'application/vnd.olpc-sugar', + 'blob': hashlib.sha1(activity_bundle).hexdigest(), + 'size': len(activity_bundle), + 'unpack_size': len(activity_info), + 'version': [[1], 0], + }, + }, + 'logs': [ + tests.tmpdir + '/.sugar/default/logs/shell.log', + tests.tmpdir + '/.sugar/default/logs/sugar-network-client.log', + tests.tmpdir + '/.sugar/default/logs/context.log', + ], + 'args': ['true', '-b', 'context', '-a', 'activity_id'], + }, + {'event': 'launch', 'state': 'exit'}, + ], + [i for i in injector.launch('context', activity_id='activity_id')]) + + def test_launch_PreemptivePool(self): + self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + activity_info = '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]) + activity_bundle = self.zips(('topdir/activity/activity.info', activity_info)) + release = conn.upload(['context'], activity_bundle, cmd='submit', initial=True) + + launch = injector.launch('context') + for event in launch: + if event.get('state') == 'exec': + break + assert exists(join('client', 'releases', release)) + self.assertEqual(0, injector._pool._du) + for event in launch: + pass + assert exists(join('client', 'releases', release)) + self.assertEqual(len(activity_info), injector._pool._du) + + launch = injector.launch('context') + for event in launch: + if event.get('state') == 'exec': + break + assert exists(join('client', 'releases', release)) + self.assertEqual(0, injector._pool._du) + for event in launch: + pass + assert exists(join('client', 'releases', release)) + self.assertEqual(len(activity_info), injector._pool._du) + + def test_launch_DonntAcquireCheckins(self): + volume = self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector('client') + injector.api = client.api.value + injector.seqno = 0 + + conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ]))), cmd='submit', initial=True) + for __ in injector.launch('context'): + pass + assert injector._pool._du > 0 + + for __ in injector.checkin('context'): + pass + assert injector._pool._du == 0 + for __ in injector.launch('context'): + pass + assert injector._pool._du == 0 + + def test_launch_RefreshCheckins(self): + self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector(tests.tmpdir + '/client') + injector.api = client.api.value + injector.seqno = 1 + + release1 = conn.upload(['context'], self.zips( + ('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = runner', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ])), + ('topdir/activity/runner', '\n'.join([ + '#!/bin/sh', + 'echo -n 1 > output', + ])), + ), cmd='submit', initial=True) + for __ in injector.checkin('context'): + pass + self.assertEqual( + {'event': 'launch', 'state': 'exit'}, + [i for i in injector.launch('context')][-1]) + self.assertEqual([client.api.value, 'stable', 1], json.load(file('client/solutions/context'))[:-1]) + self.assertEqual('1', file('client/releases/%s/output' % release1).read()) + + release2 = conn.upload(['context'], self.zips( + ('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = runner', + 'icon = icon', + 'activity_version = 2', + 'license = Public Domain', + ])), + ('topdir/activity/runner', '\n'.join([ + '#!/bin/sh', + 'echo -n 2 > output', + ])), + ), cmd='submit') + injector.seqno = 2 + self.assertEqual( + {'event': 'launch', 'state': 'exit'}, + [i for i in injector.launch('context')][-1]) + self.assertEqual([client.api.value, 'stable', 2], json.load(file('client/solutions/context'))[:-1]) + self.assertEqual('2', file('client/releases/%s/output' % release2).read()) + + def test_launch_InstallDeps(self): + volume = self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector(tests.tmpdir + '/client') + injector.api = client.api.value + injector.seqno = 1 + + release1 = conn.upload(['context'], self.zips(('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = context', + 'exec = true', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + 'requires = package1; package2', + ]))), cmd='submit', initial=True) + distro = '%s-%s' % (lsb_release.distributor_id(), lsb_release.release()) + volume['context'].create({ + 'guid': 'package1', 'type': ['package'], 'title': {}, 'summary': {}, 'description': {}, 'releases': { + 'resolves': { + distro: {'version': [[1], 0], 'packages': ['pkg1', 'pkg2']}, + }, + }, + }) + volume['context'].create({ + 'guid': 'package2', 'type': ['package'], 'title': {}, 'summary': {}, 'description': {}, 'releases': { + 'resolves': { + distro: {'version': [[1], 0], 'packages': ['pkg3', 'pkg4']}, + }, + }, + }) + + packages = [] + self.override(packagekit, 'install', lambda names: packages.extend(names)) + events = [i for i in injector.launch('context')] + self.assertEqual({'event': 'launch', 'state': 'exit'}, events[-1]) + assert {'event': 'launch', 'state': 'install'} in events + self.assertEqual(['pkg1', 'pkg2', 'pkg3', 'pkg4'], sorted(packages)) + + def test_launch_Document(self): + volume = self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector(tests.tmpdir + '/client') + injector.api = client.api.value + injector.seqno = 1 + + volume['context'].create({'guid': 'book', 'type': ['book'], 'title': {}, 'summary': {}, 'description': {}}) + book = conn.upload(['context'], 'book', cmd='submit', context='book', version='1', license='Public Domain') + + app = conn.upload(['context'], self.zips( + ('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = app', + 'exec = runner', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ])), + ('topdir/activity/runner', '\n'.join([ + '#!/bin/sh', + 'echo -n $@ > output', + ])), + ), cmd='submit', initial=True) + + self.assertEqual( + {'event': 'launch', 'state': 'exit'}, + [i for i in injector.launch('book', activity_id='activity_id', app='app')][-1]) + + self.assertEqual( + '-b app -a activity_id -u %s/client/releases/%s' % (tests.tmpdir, book), + file('client/releases/%s/output' % app).read()) + + def test_launch_DocumentWithDetectingAppByMIMEType(self): + volume = self.start_master() + conn = Connection(auth=http.SugarAuth(keyfile.value)) + injector = Injector(tests.tmpdir + '/client') + injector.api = client.api.value + injector.seqno = 1 + + volume['context'].create({'guid': 'book', 'type': ['book'], 'title': {}, 'summary': {}, 'description': {}}) + book = conn.upload(['context'], 'book', cmd='submit', context='book', version='1', license='Public Domain') + + app = conn.upload(['context'], self.zips( + ('topdir/activity/activity.info', '\n'.join([ + '[Activity]', + 'name = Activity', + 'bundle_id = app', + 'exec = runner', + 'icon = icon', + 'activity_version = 1', + 'license = Public Domain', + ])), + ('topdir/activity/runner', '\n'.join([ + '#!/bin/sh', + 'echo -n $@ > output', + ])), + ), cmd='submit', initial=True) + + self.override(injector_, '_app_by_mimetype', lambda mime_type: 'app') + self.assertEqual( + {'event': 'launch', 'state': 'exit'}, + [i for i in injector.launch('book', activity_id='activity_id')][-1]) + + self.assertEqual( + '-b app -a activity_id -u %s/client/releases/%s' % (tests.tmpdir, book), + file('client/releases/%s/output' % app).read()) + + +if __name__ == '__main__': + tests.main() diff --git a/tests/units/client/packagekit.py b/tests/units/client/packagekit.py new file mode 100755 index 0000000..05cd8eb --- /dev/null +++ b/tests/units/client/packagekit.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# sugar-lint: disable + +from __init__ import tests + +from sugar_network.client.packagekit import _cleanup_distro_version + + +class Packagekit(tests.Test): + + def test_cleanup_distro_version(self): + self.assertEqual('0.3.1-1', _cleanup_distro_version('1:0.3.1-1')) + self.assertEqual('0.3.1-1', _cleanup_distro_version('0.3.1-1ubuntu0')) + self.assertEqual('0.3-post1-rc2', _cleanup_distro_version('0.3-post1-rc2')) + self.assertEqual('0.3.1-2', _cleanup_distro_version('0.3.1-r2-r3')) + self.assertEqual('6.17', _cleanup_distro_version('6b17')) + self.assertEqual('20-1', _cleanup_distro_version('b20_1')) + self.assertEqual('17', _cleanup_distro_version('p17')) + self.assertEqual('7-pre3-2.1.1-3', _cleanup_distro_version('7~u3-2.1.1-3')) # Debian snapshot + self.assertEqual('7-pre3-2.1.1-pre1-1', _cleanup_distro_version('7~u3-2.1.1~pre1-1ubuntu2')) + self.assertEqual(None, _cleanup_distro_version('cvs')) + + +if __name__ == '__main__': + tests.main() diff --git a/tests/units/client/releases.py b/tests/units/client/releases.py deleted file mode 100755 index 30f938e..0000000 --- a/tests/units/client/releases.py +++ /dev/null @@ -1,502 +0,0 @@ -#!/usr/bin/env python -# sugar-lint: disable - -import os -import imp -import json -import time -import pickle -import shutil -import zipfile -import logging -import hashlib -from cStringIO import StringIO -from os.path import exists, dirname - -from __init__ import tests - -from sugar_network.client import journal, releases, cache_limit -from sugar_network.toolkit import coroutine, lsb_release -from sugar_network.node import obs -from sugar_network.model.user import User -from sugar_network.model.context import Context -from sugar_network.model.release import Release -from sugar_network.client import IPCConnection, packagekit, solver -from sugar_network.toolkit import http, Option -from sugar_network import client - - -class Releases(tests.Test): - - def setUp(self, fork_num=0): - tests.Test.setUp(self, fork_num) - self.override(obs, 'get_repos', lambda: []) - self.override(obs, 'presolve', lambda *args: None) - - def test_InstallDeps(self): - self.start_online_client() - conn = IPCConnection() - - blob = self.zips(['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = true', - 'icon = icon', - 'activity_version = 1', - 'license = Public Domain', - 'requires = dep1; dep2', - ]]) - impl = conn.upload(['release'], StringIO(blob), cmd='submit', initial=True) - - conn.post(['context'], { - 'guid': 'dep1', - 'type': 'package', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - 'aliases': { - lsb_release.distributor_id(): { - 'status': 'success', - 'binary': [['dep1.bin']], - }, - }, - }) - conn.post(['context'], { - 'guid': 'dep2', - 'type': 'package', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - 'aliases': { - lsb_release.distributor_id(): { - 'status': 'success', - 'binary': [['dep2.bin']], - }, - }, - }) - - def resolve(names): - with file('resolve', 'a') as f: - pickle.dump(names, f) - return dict([(i, {'name': i, 'pk_id': i, 'version': '0', 'arch': '*', 'installed': i == 'dep1.bin'}) for i in names]) - - def install(packages): - with file('install', 'a') as f: - pickle.dump([i['name'] for i in packages], f) - - self.override(packagekit, 'resolve', resolve) - self.override(packagekit, 'install', install) - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - - with file('resolve') as f: - deps = [pickle.load(f), - pickle.load(f), - ] - self.assertRaises(EOFError, pickle.load, f) - self.assertEqual( - sorted([['dep1.bin'], ['dep2.bin']]), - sorted(deps)) - with file('install') as f: - self.assertEqual(['dep2.bin'], pickle.load(f)) - self.assertRaises(EOFError, pickle.load, f) - - def test_SetExecPermissions(self): - self.start_online_client() - conn = IPCConnection() - - blob = self.zips( - ['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = true', - 'icon = icon', - 'activity_version = 1', - 'license = Public Domain', - ]], - 'TestActivity/activity/foo', - 'TestActivity/bin/bar', - 'TestActivity/bin/probe', - 'TestActivity/file1', - 'TestActivity/test/file2', - ) - impl = conn.upload(['release'], StringIO(blob), cmd='submit', initial=True) - - conn.put(['context', 'bundle_id'], True, cmd='clone') - - path = 'client/release/%s/%s/data.blob/' % (impl[:2], impl) - assert os.access(path + 'activity/foo', os.X_OK) - assert os.access(path + 'bin/bar', os.X_OK) - assert os.access(path + 'bin/probe', os.X_OK) - assert not os.access(path + 'file1', os.X_OK) - assert not os.access(path + 'test/file2', os.X_OK) - - def test_ReuseCachedSolution(self): - self.start_online_client() - conn = IPCConnection() - - activity_info = '\n'.join([ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = true', - 'icon = icon', - 'activity_version = 1', - 'license = Public Domain', - 'stability = stable', - ]) - blob = self.zips(['TestActivity/activity/activity.info', activity_info]) - impl = conn.upload(['release'], StringIO(blob), cmd='submit', initial=True) - solution = ['http://127.0.0.1:8888', ['stable'], [{ - 'license': ['Public Domain'], - 'stability': 'stable', - 'version': '1', - 'context': 'bundle_id', - 'path': tests.tmpdir + '/client/release/%s/%s/data.blob' % (impl[:2], impl), - 'guid': impl, - 'layer': ['origin'], - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, - 'ctime': self.node_volume['release'].get(impl).ctime, - 'notes': {'en-us': ''}, - 'tags': [], - 'data': { - 'unpack_size': len(activity_info), - 'blob_size': len(blob), - 'digest': hashlib.sha1(blob).hexdigest(), - 'mime_type': 'application/vnd.olpc-sugar', - 'spec': {'*-*': {'commands': {'activity': {'exec': 'true'}}, 'requires': {}}}, - }, - }]] - cached_path = 'solutions/bu/bundle_id' - - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - self.assertEqual(solution, json.load(file(cached_path))) - - os.utime(cached_path, (0, 0)) - self.assertEqual(solution, json.load(file(cached_path))) - assert os.stat(cached_path).st_mtime == 0 - - def test_InvalidaeCachedSolutions(self): - self.start_online_client() - conn = IPCConnection() - - conn.post(['context'], { - 'guid': 'bundle_id', - 'type': 'activity', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) - - solution = json.dumps(['http://127.0.0.1:8888', ['stable'], [{ - 'license': ['Public Domain'], - 'stability': 'stable', - 'version': '1', - 'context': 'bundle_id', - 'path': tests.tmpdir, - 'guid': 'impl', - 'data': { - 'spec': {'*-*': {'commands': {'activity': {'exec': 'true'}}, 'requires': {}}}, - }, - }]]) - cached_path = 'solutions/bu/bundle_id' - self.touch([cached_path, solution]) - cached_mtime = int(os.stat(cached_path).st_mtime) - - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - - client.api.value = 'fake' - self.assertEqual('NotFound', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['exception']) - self.assertEqual(solution, file(cached_path).read()) - - client.api.value = 'http://127.0.0.1:8888' - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - - self.client_routes._node_mtime = cached_mtime + 2 - self.assertEqual('NotFound', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['exception']) - self.assertEqual(solution, file(cached_path).read()) - - self.client_routes._node_mtime = cached_mtime - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - - self.override(packagekit, 'mtime', lambda: cached_mtime + 2) - self.assertEqual('NotFound', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['exception']) - self.assertEqual(solution, file(cached_path).read()) - - self.override(packagekit, 'mtime', lambda: cached_mtime) - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - - self.touch(('config', [ - '[stabilities]', - 'bundle_id = buggy', - ])) - Option.load(['config']) - self.assertEqual('NotFound', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['exception']) - self.assertEqual(solution, file(cached_path).read()) - - self.touch(('config', [ - '[stabilities]', - 'bundle_id = stable', - ])) - Option.load(['config']) - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - - def test_DeliberateReuseCachedSolutionInOffline(self): - self.start_online_client() - conn = IPCConnection() - - conn.post(['context'], { - 'guid': 'bundle_id', - 'type': 'activity', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) - - solution = json.dumps(['http://127.0.0.1:8888', ['stable'], [{ - 'license': ['Public Domain'], - 'stability': 'stable', - 'version': '1', - 'context': 'bundle_id', - 'path': tests.tmpdir, - 'guid': 'impl', - 'data': { - 'spec': {'*-*': {'commands': {'activity': {'exec': 'true'}}, 'requires': {}}}, - }, - }]]) - self.touch(['solutions/bu/bundle_id', solution]) - - client.api.value = 'fake' - self.assertEqual('NotFound', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['exception']) - - self.node.stop() - coroutine.sleep(.1) - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - - def test_StabilityPreferences(self): - self.start_online_client() - conn = IPCConnection() - - conn.upload(['release'], StringIO(self.zips(['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = true', - 'icon = icon', - 'activity_version = 1', - 'license = Public Domain', - 'stability = stable', - ]])), cmd='submit', initial=True) - conn.upload(['release'], StringIO(self.zips(['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = true', - 'icon = icon', - 'activity_version = 2', - 'license = Public Domain', - 'stability = testing', - ]])), cmd='submit') - conn.upload(['release'], StringIO(self.zips(['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = true', - 'icon = icon', - 'activity_version = 3', - 'license = Public Domain', - 'stability = buggy', - ]])), cmd='submit') - cached_path = 'solutions/bu/bundle_id' - - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - self.assertEqual('1', json.load(file(cached_path))[2][0]['version']) - - self.touch(('config', [ - '[stabilities]', - 'bundle_id = testing', - ])) - Option.load(['config']) - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - self.assertEqual('2', json.load(file(cached_path))[2][0]['version']) - - self.touch(('config', [ - '[stabilities]', - 'bundle_id = testing buggy', - ])) - Option.load(['config']) - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - self.assertEqual('3', json.load(file(cached_path))[2][0]['version']) - - self.touch(('config', [ - '[stabilities]', - 'default = testing', - ])) - Option.load(['config']) - self.assertEqual('exit', [i for i in conn.get(['context', 'bundle_id'], cmd='launch')][-1]['event']) - self.assertEqual('2', json.load(file(cached_path))[2][0]['version']) - - def test_LaunchContext(self): - self.start_online_client() - conn = IPCConnection() - - app = conn.upload(['release'], StringIO(self.zips( - ['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = activity', - 'icon = icon', - 'activity_version = 1', - 'license = Public Domain', - ]], - ['TestActivity/bin/activity', [ - '#!/bin/sh', - 'cat $6', - ]], - )), cmd='submit', initial=True) - - conn.post(['context'], { - 'guid': 'document', - 'type': 'book', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) - doc = conn.post(['release'], { - 'context': 'document', - 'license': 'GPLv3+', - 'version': '1', - 'stability': 'stable', - }) - self.node_volume['release'].update(doc, {'data': { - 'mime_type': 'application/octet-stream', - 'blob': StringIO('content'), - }}) - - self.assertEqual('exit', [i for i in conn.get(['context', 'document'], cmd='launch', context='bundle_id')][-1]['event']) - coroutine.sleep(.1) - self.assertEqual('content', file('.sugar/default/logs/bundle_id.log').read()) - - def test_CreateAllImplPropsOnCheckin(self): - home_volume = self.start_online_client() - conn = IPCConnection() - - blob = self.zips( - ['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = true', - 'icon = icon', - 'activity_version = 1', - 'license = Public Domain', - ]], - ) - impl = conn.upload(['release'], StringIO(blob), cmd='submit', initial=True) - conn.put(['context', 'bundle_id'], True, cmd='clone') - - doc = home_volume['release'].get(impl) - assert doc.meta('ctime') is not None - assert doc.meta('mtime') is not None - assert doc.meta('seqno') is not None - self.assertEqual({tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, doc.meta('author')['value']) - self.assertEqual(['origin'], doc.meta('layer')['value']) - self.assertEqual('bundle_id', doc.meta('context')['value']) - self.assertEqual(['Public Domain'], doc.meta('license')['value']) - self.assertEqual('1', doc.meta('version')['value']) - self.assertEqual('stable', doc.meta('stability')['value']) - self.assertEqual({'en-us': ''}, doc.meta('notes')['value']) - self.assertEqual([], doc.meta('tags')['value']) - - def test_LaunchAcquiring(self): - volume = self.start_online_client() - conn = IPCConnection() - - app = conn.upload(['release'], StringIO(self.zips( - ['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = activity', - 'icon = icon', - 'activity_version = 1', - 'license = Public Domain', - ]], - ['TestActivity/bin/activity', [ - '#!/bin/sh', - 'sleep 1', - ]], - )), cmd='submit', initial=True) - - conn.post(['context'], { - 'guid': 'document', - 'type': 'book', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) - doc = conn.post(['release'], { - 'context': 'document', - 'license': 'GPLv3+', - 'version': '1', - 'stability': 'stable', - }) - self.node_volume['release'].update(doc, {'data': { - 'mime_type': 'application/octet-stream', - 'blob': StringIO('content'), - }}) - - launch = conn.get(['context', 'document'], cmd='launch', context='bundle_id') - self.assertEqual('launch', next(launch)['event']) - self.assertEqual('exec', next(launch)['event']) - - class statvfs(object): - f_blocks = 100 - f_bfree = 10 - f_frsize = 1 - self.override(os, 'statvfs', lambda *args: statvfs()) - cache_limit.value = 10 - - self.assertRaises(RuntimeError, self.client_routes._cache.ensure, 1, 0) - assert volume['release'].exists(app) - assert volume['release'].exists(doc) - self.assertEqual([], [i for i in self.client_routes._cache]) - - self.assertEqual('exit', next(launch)['event']) - self.assertEqual([app, doc], [i for i in self.client_routes._cache]) - - def test_NoAcquiringForClones(self): - volume = self.start_online_client() - conn = IPCConnection() - - app = conn.upload(['release'], StringIO(self.zips( - ['TestActivity/activity/activity.info', [ - '[Activity]', - 'name = TestActivity', - 'bundle_id = bundle_id', - 'exec = activity', - 'icon = icon', - 'activity_version = 1', - 'license = Public Domain', - ]], - ['TestActivity/bin/activity', [ - '#!/bin/sh', - 'sleep 1', - ]], - )), cmd='submit', initial=True) - - conn.put(['context', 'bundle_id'], True, cmd='clone') - self.assertEqual([], [i for i in self.client_routes._cache]) - - launch = conn.get(['context', 'bundle_id'], cmd='launch') - self.assertEqual('launch', next(launch)['event']) - self.assertEqual('exec', next(launch)['event']) - self.assertEqual([], [i for i in self.client_routes._cache]) - self.assertEqual('exit', next(launch)['event']) - self.assertEqual([], [i for i in self.client_routes._cache]) - - -if __name__ == '__main__': - tests.main() diff --git a/tests/units/client/solver.py b/tests/units/client/solver.py deleted file mode 100755 index 29e1472..0000000 --- a/tests/units/client/solver.py +++ /dev/null @@ -1,277 +0,0 @@ -#!/usr/bin/env python -# sugar-lint: disable - -import os -import imp - -from __init__ import tests - -from sugar_network.client import IPCConnection, packagekit, solver -from sugar_network.toolkit import lsb_release - - -class SolverTest(tests.Test): - - def test_select_architecture(self): - host_arch = os.uname()[-1] - all_arches = [i for i in solver.machine_ranks.keys() if i] - - self.assertEqual(host_arch, solver.select_architecture( - sorted(all_arches, cmp=lambda x, y: cmp(solver.machine_ranks[x], solver.machine_ranks[y])))) - self.assertEqual(host_arch, solver.select_architecture( - sorted(all_arches, cmp=lambda x, y: cmp(solver.machine_ranks[y], solver.machine_ranks[x])))) - self.assertEqual(host_arch, solver.select_architecture([host_arch])) - self.assertEqual(host_arch, solver.select_architecture(['foo', host_arch, 'bar'])) - - def test_ProcessCommonDependencies(self): - self.start_online_client() - conn = IPCConnection() - - context = conn.post(['context'], { - 'type': 'activity', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - 'dependencies': ['dep1', 'dep2'], - }) - impl = conn.post(['release'], { - 'context': context, - 'license': 'GPLv3+', - 'version': '1', - 'stability': 'stable', - 'notes': '', - }) - self.node_volume['release'].update(impl, {'data': { - 'spec': { - '*-*': { - 'commands': { - 'activity': { - 'exec': 'echo', - }, - }, - 'requires': { - 'dep2': {'restrictions': [['1', '2']]}, - 'dep3': {}, - }, - }, - }, - }}) - conn.post(['context'], { - 'guid': 'dep1', - 'type': 'package', - 'title': 'title1', - 'summary': 'summary', - 'description': 'description', - 'aliases': { - lsb_release.distributor_id(): { - 'status': 'success', - 'binary': [['dep1.bin']], - }, - }, - }) - conn.post(['context'], { - 'guid': 'dep2', - 'type': 'package', - 'title': 'title2', - 'summary': 'summary', - 'description': 'description', - 'aliases': { - lsb_release.distributor_id(): { - 'status': 'success', - 'binary': [['dep2.bin']], - }, - }, - }) - conn.post(['context'], { - 'guid': 'dep3', - 'type': 'package', - 'title': 'title3', - 'summary': 'summary', - 'description': 'description', - 'aliases': { - lsb_release.distributor_id(): { - 'status': 'success', - 'binary': [['dep3.bin']], - }, - }, - }) - - def resolve(names): - return dict([(i, {'name': i, 'pk_id': i, 'version': '1', 'arch': '*', 'installed': True}) for i in names]) - - self.override(packagekit, 'resolve', resolve) - - self.assertEqual( - sorted([ - {'version': '1', 'guid': 'dep1', 'context': 'dep1', 'stability': 'packaged', 'license': None}, - {'version': '1', 'guid': 'dep2', 'context': 'dep2', 'stability': 'packaged', 'license': None}, - {'version': '1', 'guid': 'dep3', 'context': 'dep3', 'stability': 'packaged', 'license': None}, - {'version': '1', 'context': context, 'guid': impl, 'stability': 'stable', 'license': ['GPLv3+'], - 'layer': ['origin'], - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, - 'ctime': self.node_volume['release'].get(impl).ctime, - 'notes': {'en-us': ''}, - 'tags': [], - 'data': {'spec': {'*-*': {'commands': {'activity': {'exec': 'echo'}}, 'requires': - {'dep2': {'restrictions': [['1', '2']]}, 'dep3': {}}}}}, - 'requires': {'dep1': {}, 'dep2': {}}}, - ]), - sorted(solver.solve(self.client_routes.fallback, context, ['stable']))) - - def test_SolveSugar(self): - self.touch(('__init__.py', '')) - self.touch(('jarabe.py', 'class config: version = "0.94"')) - file_, pathname_, description_ = imp.find_module('jarabe', ['.']) - imp.load_module('jarabe', file_, pathname_, description_) - - self.start_online_client() - conn = IPCConnection() - - context = conn.post(['context'], { - 'type': 'activity', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) - conn.post(['context'], { - 'guid': 'sugar', - 'type': 'package', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) - - impl = conn.post(['release'], { - 'context': context, - 'license': 'GPLv3+', - 'version': '1', - 'stability': 'stable', - 'notes': '', - }) - self.node_volume['release'].update(impl, {'data': { - 'spec': { - '*-*': { - 'commands': { - 'activity': { - 'exec': 'echo', - }, - }, - 'requires': { - 'sugar': {}, - }, - }, - }, - }}) - self.assertEqual([ - { - 'version': '1', - 'context': context, - 'guid': impl, - 'stability': 'stable', - 'license': ['GPLv3+'], - 'layer': ['origin'], - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, - 'ctime': self.node_volume['release'].get(impl).ctime, - 'notes': {'en-us': ''}, - 'tags': [], - 'data': {'spec': {'*-*': {'commands': {'activity': {'exec': 'echo'}}, 'requires': {'sugar': {}}}}}}, - {'version': '0.94', 'context': 'sugar', 'guid': 'sugar-0.94', 'stability': 'packaged', 'license': None}, - ], - solver.solve(self.client_routes.fallback, context, ['stable'])) - - self.node_volume['release'].update(impl, {'data': { - 'spec': { - '*-*': { - 'commands': { - 'activity': { - 'exec': 'echo', - }, - }, - 'requires': { - 'sugar': {'restrictions': [['0.80', '0.87']]}, - }, - }, - }, - }}) - self.assertEqual([ - { - 'version': '1', - 'context': context, - 'guid': impl, - 'stability': 'stable', - 'license': ['GPLv3+'], - 'layer': ['origin'], - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, - 'ctime': self.node_volume['release'].get(impl).ctime, - 'notes': {'en-us': ''}, - 'tags': [], - 'data': {'spec': {'*-*': {'commands': {'activity': {'exec': 'echo'}}, 'requires': - {'sugar': {'restrictions': [['0.80', '0.87']]}}}}}}, - {'version': '0.86', 'context': 'sugar', 'guid': 'sugar-0.86', 'stability': 'packaged', 'license': None}, - ], - solver.solve(self.client_routes.fallback, context, ['stable'])) - - def test_StripSugarVersion(self): - self.touch(('__init__.py', '')) - self.touch(('jarabe.py', 'class config: version = "0.94.1"')) - file_, pathname_, description_ = imp.find_module('jarabe', ['.']) - imp.load_module('jarabe', file_, pathname_, description_) - - self.start_online_client() - conn = IPCConnection() - - context = conn.post(['context'], { - 'type': 'activity', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) - conn.post(['context'], { - 'guid': 'sugar', - 'type': 'package', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) - - impl = conn.post(['release'], { - 'context': context, - 'license': 'GPLv3+', - 'version': '1', - 'stability': 'stable', - 'notes': '', - }) - self.node_volume['release'].update(impl, {'data': { - 'spec': { - '*-*': { - 'commands': { - 'activity': { - 'exec': 'echo', - }, - }, - 'requires': { - 'sugar': {}, - }, - }, - }, - }}) - self.assertEqual([ - { - 'version': '1', - 'context': context, - 'guid': impl, - 'stability': 'stable', - 'license': ['GPLv3+'], - 'layer': ['origin'], - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, - 'ctime': self.node_volume['release'].get(impl).ctime, - 'notes': {'en-us': ''}, - 'tags': [], - 'data': {'spec': {'*-*': {'commands': {'activity': {'exec': 'echo'}}, 'requires': {'sugar': {}}}}}}, - {'version': '0.94', 'context': 'sugar', 'guid': 'sugar-0.94', 'stability': 'packaged', 'license': None}, - ], - solver.solve(self.client_routes.fallback, context, ['stable'])) - - -if __name__ == '__main__': - tests.main() diff --git a/tests/units/model/context.py b/tests/units/model/context.py index d33cb73..bd39c04 100755 --- a/tests/units/model/context.py +++ b/tests/units/model/context.py @@ -81,7 +81,6 @@ class ContextTest(tests.Test): 'summary': 'summary', 'description': 'description', }) - return activity_info1 = '\n'.join([ '[Activity]', diff --git a/tests/units/node/model.py b/tests/units/node/model.py index 024c148..6788105 100755 --- a/tests/units/node/model.py +++ b/tests/units/node/model.py @@ -269,7 +269,7 @@ class ModelTest(tests.Test): }, }) self.assertEqual( - {context: {'command': ('activity', 3), 'blob': '3', 'version': [[3], 0]}}, + {context: {'command': ('activity', 3), 'title': '', 'blob': '3', 'version': [[3], 0]}}, model.solve(volume, context)) context = volume['context'].create({ @@ -280,7 +280,7 @@ class ModelTest(tests.Test): }, }) self.assertEqual( - {context: {'command': ('activity', 3), 'blob': '3', 'version': [[3], 0]}}, + {context: {'command': ('activity', 3), 'title': '', 'blob': '3', 'version': [[3], 0]}}, model.solve(volume, context)) def test_solve_SortByStability(self): @@ -295,7 +295,7 @@ class ModelTest(tests.Test): }, }) self.assertEqual( - {context: {'command': ('activity', 2), 'blob': '2', 'version': [[2], 0]}}, + {context: {'command': ('activity', 2), 'title': '', 'blob': '2', 'version': [[2], 0]}}, model.solve(volume, context)) def test_solve_CollectDeps(self): @@ -334,10 +334,10 @@ class ModelTest(tests.Test): }) self.assertEqual({ - 'context1': {'blob': '1', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'context2': {'blob': '2', 'version': [[2], 0]}, - 'context3': {'blob': '3', 'version': [[3], 0]}, - 'context4': {'blob': '4', 'version': [[4], 0]}, + 'context1': {'title': '', 'blob': '1', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'context2': {'title': '', 'blob': '2', 'version': [[2], 0]}, + 'context3': {'title': '', 'blob': '3', 'version': [[3], 0]}, + 'context4': {'title': '', 'blob': '4', 'version': [[4], 0]}, }, model.solve(volume, 'context1')) @@ -370,12 +370,12 @@ class ModelTest(tests.Test): }) self.assertEqual({ - 'context1': {'blob': '1', 'version': [[1], 0], 'command': ('activity', 1)}, - 'context2': {'blob': '2', 'version': [[2], 0]}, + 'context1': {'title': '', 'blob': '1', 'version': [[1], 0], 'command': ('activity', 1)}, + 'context2': {'title': '', 'blob': '2', 'version': [[2], 0]}, }, model.solve(volume, 'context1', command='activity')) self.assertEqual({ - 'context1': {'blob': '1', 'version': [[1], 0], 'command': ('application', 2)}, + 'context1': {'title': '', 'blob': '1', 'version': [[1], 0], 'command': ('application', 2)}, }, model.solve(volume, 'context1', command='application')) @@ -401,8 +401,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context1': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '2', 'version': [[2], 0]}, + 'context1': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '2', 'version': [[2], 0]}, }, model.solve(volume, 'context1')) @@ -414,8 +414,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context1': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '3', 'version': [[3], 0]}, + 'context1': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '3', 'version': [[3], 0]}, }, model.solve(volume, 'context1')) @@ -427,8 +427,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context1': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '5', 'version': [[5], 0]}, + 'context1': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '5', 'version': [[5], 0]}, }, model.solve(volume, 'context1')) @@ -440,8 +440,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context1': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '5', 'version': [[5], 0]}, + 'context1': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '5', 'version': [[5], 0]}, }, model.solve(volume, 'context1')) @@ -453,8 +453,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context1': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '4', 'version': [[4], 0]}, + 'context1': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '4', 'version': [[4], 0]}, }, model.solve(volume, 'context1')) @@ -466,8 +466,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context1': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '3', 'version': [[3], 0]}, + 'context1': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '3', 'version': [[3], 0]}, }, model.solve(volume, 'context1')) @@ -479,8 +479,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context1': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '1', 'version': [[1], 0]}, + 'context1': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '1', 'version': [[1], 0]}, }, model.solve(volume, 'context1')) @@ -516,8 +516,8 @@ class ModelTest(tests.Test): }) self.assertEqual({ - 'context1': {'blob': '6', 'version': [[1], 0], 'command': ('activity', 6)}, - 'context4': {'blob': '5', 'version': [[1], 0]}, + 'context1': {'title': '', 'blob': '6', 'version': [[1], 0], 'command': ('activity', 6)}, + 'context4': {'title': '', 'blob': '5', 'version': [[1], 0]}, }, model.solve(volume, 'context1')) @@ -545,8 +545,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '2', 'version': [[2], 0]}, + 'context': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '2', 'version': [[2], 0]}, }, model.solve(volume, 'context')) @@ -560,8 +560,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '4', 'version': [[4], 0]}, + 'context': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '4', 'version': [[4], 0]}, }, model.solve(volume, 'context')) @@ -575,8 +575,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '3', 'version': [[3], 0]}, + 'context': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '3', 'version': [[3], 0]}, }, model.solve(volume, 'context')) @@ -602,7 +602,7 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'context': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, }, model.solve(volume, 'context')) @@ -614,8 +614,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '5', 'version': [[5], 0]}, + 'context': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '5', 'version': [[5], 0]}, }, model.solve(volume, 'context')) @@ -627,8 +627,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, - 'dep': {'blob': '4', 'version': [[4], 0]}, + 'context': {'title': '', 'blob': '10', 'version': [[1], 0], 'command': ('activity', 'command')}, + 'dep': {'title': '', 'blob': '4', 'version': [[4], 0]}, }, model.solve(volume, 'context')) @@ -682,7 +682,7 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, + 'context': {'title': '', 'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, 'package': {'packages': ['pkg1', 'pkg2'], 'version': [[1], 0]}, }, model.solve(volume, context, lsb_id='Ubuntu', lsb_release='10.04')) @@ -700,8 +700,8 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, - 'dep': {'blob': '2', 'version': [[1], 0]}, + 'context': {'title': '', 'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, + 'dep': {'title': '', 'blob': '2', 'version': [[1], 0]}, 'package': {'packages': ['pkg1', 'pkg2'], 'version': [[1], 0]}, }, model.solve(volume, context, lsb_id='Ubuntu', lsb_release='10.04')) @@ -724,7 +724,7 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, + 'context': {'title': '', 'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, 'package1': {'packages': ['bin1', 'bin2', 'devel1', 'devel2'], 'version': []}, }, model.solve(volume, context, lsb_id='Ubuntu')) @@ -745,7 +745,7 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, + 'context': {'title': '', 'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, 'package2': {'packages': ['bin'], 'version': []}, }, model.solve(volume, context, lsb_id='Ubuntu', lsb_release='fake')) @@ -772,17 +772,17 @@ class ModelTest(tests.Test): }, }) self.assertEqual({ - 'context': {'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, + 'context': {'title': '', 'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, 'package1': {'packages': ['pkg1'], 'version': []}, }, model.solve(volume, context)) self.assertEqual({ - 'context': {'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, + 'context': {'title': '', 'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, 'package1': {'packages': ['pkg1'], 'version': []}, }, model.solve(volume, context, lsb_id='Fake')) self.assertEqual({ - 'context': {'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, + 'context': {'title': '', 'blob': '1', 'command': ('activity', 'command'), 'version': [[1], 0]}, 'package1': {'packages': ['pkg1'], 'version': []}, }, model.solve(volume, context, lsb_id='Fake', lsb_release='fake')) diff --git a/tests/units/node/node.py b/tests/units/node/node.py index a8c68e8..0f934d4 100755 --- a/tests/units/node/node.py +++ b/tests/units/node/node.py @@ -361,7 +361,7 @@ class NodeTest(tests.Test): 'title': 'title1', 'summary': 'summary', 'description': 'description', - 'artifact_icon': '', + 'artefact_icon': '', 'icon': '', 'logo': '', }) @@ -562,6 +562,7 @@ class NodeTest(tests.Test): self.assertEqual({ 'activity': { + 'title': 'activity', 'blob': activity_blob, 'command': ['activity', 'true'], 'version': [[1], 0], @@ -569,6 +570,7 @@ class NodeTest(tests.Test): 'unpack_size': len(activity_unpack), }, 'dep': { + 'title': 'dep', 'blob': dep_blob, 'version': [[2], 0], 'size': len(dep_pack), @@ -638,6 +640,7 @@ class NodeTest(tests.Test): self.assertEqual({ 'activity': { + 'title': 'activity', 'blob': activity_blob, 'command': ['activity', 'true'], 'version': [[1], 0], @@ -645,6 +648,7 @@ class NodeTest(tests.Test): 'unpack_size': len(activity_unpack), }, 'dep': { + 'title': 'dep', 'blob': dep_blob, 'version': [[2], 0], 'size': len(dep_pack), diff --git a/tests/units/node/slave.py b/tests/units/node/slave.py index 184da43..55da003 100755 --- a/tests/units/node/slave.py +++ b/tests/units/node/slave.py @@ -25,6 +25,14 @@ class SlaveTest(tests.Test): def setUp(self): tests.Test.setUp(self) + class statvfs(object): + f_blocks = 100 + f_bfree = 999999999 + f_frsize = 1 + + self.statvfs = statvfs + self.override(os, 'statvfs', lambda *args: statvfs()) + class Document(db.Resource): @db.indexed_property(db.Localized, slot=1, prefix='N', full_text=True) diff --git a/tests/units/toolkit/router.py b/tests/units/toolkit/router.py index 52a721e..0c18cee 100755 --- a/tests/units/toolkit/router.py +++ b/tests/units/toolkit/router.py @@ -1306,8 +1306,8 @@ class RouterTest(tests.Test): @route('GET', [None, None, None], cmd='cmd', mime_type='text/event-stream') def ok(self): - yield {} - yield {'foo': 'bar'} + yield {'event': 'probe'} + yield {'event': 'probe', 'foo': 'bar'} events = [] def localcast(event): @@ -1324,8 +1324,8 @@ class RouterTest(tests.Test): coroutine.sleep(.1) self.assertEqual([ - {'method': 'GET', 'resource': 'resource', 'guid': 'guid', 'prop': 'prop', 'cmd': 'cmd'}, - {'method': 'GET', 'resource': 'resource', 'guid': 'guid', 'prop': 'prop', 'cmd': 'cmd', 'foo': 'bar'}, + {'method': 'GET', 'resource': 'resource', 'guid': 'guid', 'prop': 'prop', 'cmd': 'cmd', 'event': 'probe'}, + {'method': 'GET', 'resource': 'resource', 'guid': 'guid', 'prop': 'prop', 'cmd': 'cmd', 'foo': 'bar', 'event': 'probe'}, ], events) del events[:] @@ -1336,9 +1336,9 @@ class RouterTest(tests.Test): @route('GET', mime_type='text/event-stream') def error(self, request): - request.session['bar'] = 'foo' - yield {} - yield {'foo': 'bar'}, {'add': 'on'} + yield {'foo': 'bar'} + yield {'bar': 'foo'} + yield {'event': 'probe'} raise RuntimeError('error') events = [] @@ -1356,9 +1356,8 @@ class RouterTest(tests.Test): coroutine.sleep(.1) self.assertEqual([ - {'method': 'GET'}, - {'method': 'GET', 'foo': 'bar', 'add': 'on'}, - {'method': 'GET', 'bar': 'foo', 'event': 'failure', 'exception': 'RuntimeError', 'error': 'error'}, + {'method': 'GET', 'foo': 'bar', 'bar': 'foo', 'event': 'probe'}, + {'method': 'GET', 'foo': 'bar', 'bar': 'foo', 'event': 'failure', 'exception': 'RuntimeError', 'error': 'error'}, ], events) del events[:] @@ -1369,8 +1368,8 @@ class RouterTest(tests.Test): @route('GET', mime_type='text/event-stream') def get(self, request): - yield {} - yield {'request': request.content} + yield {'event': 'probe'} + yield {'event': 'probe', 'request': request.content} events = [] def localcast(event): @@ -1389,8 +1388,8 @@ class RouterTest(tests.Test): coroutine.sleep(.1) self.assertEqual([ - {'method': 'GET'}, - {'method': 'GET', 'request': 'probe'}, + {'method': 'GET', 'event': 'probe'}, + {'method': 'GET', 'request': 'probe', 'event': 'probe'}, ], events) del events[:] |