diff options
Diffstat (limited to 'tests/units/client/cache.py')
-rwxr-xr-x | tests/units/client/cache.py | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/tests/units/client/cache.py b/tests/units/client/cache.py index 6a73f36..e980549 100755 --- a/tests/units/client/cache.py +++ b/tests/units/client/cache.py @@ -12,7 +12,7 @@ from __init__ import tests from sugar_network import db from sugar_network.model.context import Context -from sugar_network.model.implementation import Implementation +from sugar_network.model.release import Release 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 @@ -32,9 +32,9 @@ class CacheTest(tests.Test): self.override(os, 'statvfs', lambda *args: statvfs()) def test_open(self): - volume = db.Volume('db', [Context, Implementation]) + volume = db.Volume('db', [Context, Release]) - volume['implementation'].create({ + volume['release'].create({ 'guid': '1', 'context': 'context', 'license': ['GPL'], @@ -42,8 +42,8 @@ class CacheTest(tests.Test): 'stability': 'stable', 'data': {'blob_size': 1}, }) - os.utime('db/implementation/1/1', (1, 1)) - volume['implementation'].create({ + os.utime('db/release/1/1', (1, 1)) + volume['release'].create({ 'guid': '5', 'context': 'context', 'license': ['GPL'], @@ -51,8 +51,8 @@ class CacheTest(tests.Test): 'stability': 'stable', 'data': {'blob_size': 5}, }) - os.utime('db/implementation/5/5', (5, 5)) - volume['implementation'].create({ + os.utime('db/release/5/5', (5, 5)) + volume['release'].create({ 'guid': '2', 'context': 'context', 'license': ['GPL'], @@ -60,16 +60,16 @@ class CacheTest(tests.Test): 'stability': 'stable', 'data': {}, }) - os.utime('db/implementation/2/2', (2, 2)) - volume['implementation'].create({ + os.utime('db/release/2/2', (2, 2)) + volume['release'].create({ 'guid': '3', 'context': 'context', 'license': ['GPL'], 'version': '3', 'stability': 'stable', }) - os.utime('db/implementation/3/3', (3, 3)) - volume['implementation'].create({ + os.utime('db/release/3/3', (3, 3)) + volume['release'].create({ 'guid': '4', 'context': 'context', 'license': ['GPL'], @@ -77,13 +77,13 @@ class CacheTest(tests.Test): 'stability': 'stable', 'data': {'blob_size': 4, 'unpack_size': 44}, }) - os.utime('db/implementation/4/4', (4, 4)) + 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, Implementation]) + volume = db.Volume('db', [Context, Release]) volume['context'].create({ 'guid': 'context', @@ -92,7 +92,7 @@ class CacheTest(tests.Test): 'summary': 'summary', 'description': 'description', }) - volume['implementation'].create({ + volume['release'].create({ 'guid': 'impl', 'context': 'context', 'license': ['GPL'], @@ -104,113 +104,113 @@ class CacheTest(tests.Test): cache = Cache(volume) self.assertEqual(['impl'], [i for i in cache]) - os.symlink('../../../implementation/im/impl', 'db/context/co/context/.clone') + 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, Implementation]) - - volume['implementation'].create({'data': {'blob_size': 1}, 'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/implementation/1/1', (1, 1)) - volume['implementation'].create({'data': {'blob_size': 2}, 'guid': '2', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/implementation/2/2', (2, 2)) - volume['implementation'].create({'data': {'blob_size': 3}, 'guid': '3', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/implementation/3/3', (3, 3)) + volume = db.Volume('db', [Context, Release]) + + 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['implementation'].exists('1') - assert volume['implementation'].exists('2') - assert volume['implementation'].exists('3') + assert volume['release'].exists('1') + assert volume['release'].exists('2') + assert volume['release'].exists('3') cache.ensure(1, 0) - assert volume['implementation'].exists('1') - assert volume['implementation'].exists('2') - assert volume['implementation'].exists('3') + assert volume['release'].exists('1') + assert volume['release'].exists('2') + assert volume['release'].exists('3') cache.ensure(2, 0) - assert not volume['implementation'].exists('1') - assert volume['implementation'].exists('2') - assert volume['implementation'].exists('3') + assert not volume['release'].exists('1') + assert volume['release'].exists('2') + assert volume['release'].exists('3') cache.ensure(4, 0) - assert not volume['implementation'].exists('2') - assert not volume['implementation'].exists('3') + 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, Implementation]) + volume = db.Volume('db', [Context, Release]) cache = Cache(volume) # To initiate the cache cache.ensure(0, 0) - volume['implementation'].create({'data': {'blob_size': 1}, 'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) + 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['implementation'].exists('1') + assert not volume['release'].exists('1') self.assertRaises(RuntimeError, cache.ensure, 1, 0) def test_ensure_ConsiderTmpSize(self): - volume = db.Volume('db', [Context, Implementation]) - volume['implementation'].create({'data': {'blob_size': 1}, 'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) + volume = db.Volume('db', [Context, Release]) + 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['implementation'].exists('1') + assert volume['release'].exists('1') cache.ensure(1, 10) - assert not volume['implementation'].exists('1') + assert not volume['release'].exists('1') def test_recycle(self): ts = time.time() - volume = db.Volume('db', [Context, Implementation]) - volume['implementation'].create({'data': {'blob_size': 1}, 'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/implementation/1/1', (ts - 1.5 * 86400, ts - 1.5 * 86400)) - volume['implementation'].create({'data': {'blob_size': 1}, 'guid': '2', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/implementation/2/2', (ts - 2.5 * 86400, ts - 2.5 * 86400)) - volume['implementation'].create({'data': {'blob_size': 1}, 'guid': '3', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - os.utime('db/implementation/3/3', (ts - 3.5 * 86400, ts - 3.5 * 86400)) + volume = db.Volume('db', [Context, Release]) + 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['implementation'].exists('1') - assert volume['implementation'].exists('2') - assert volume['implementation'].exists('3') + assert volume['release'].exists('1') + assert volume['release'].exists('2') + assert volume['release'].exists('3') cache_lifetime.value = 3 cache.recycle() - assert volume['implementation'].exists('1') - assert volume['implementation'].exists('2') - assert not volume['implementation'].exists('3') + 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['implementation'].exists('1') - assert not volume['implementation'].exists('2') - assert not volume['implementation'].exists('3') + 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, Implementation]) + volume = db.Volume('db', [Context, Release]) cache = Cache(volume) - volume['implementation'].create({'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - volume['implementation'].create({'guid': '2', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - volume['implementation'].create({'guid': '3', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) + 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]) @@ -229,7 +229,7 @@ class CacheTest(tests.Test): conn = IPCConnection() self.statvfs.f_blocks = 0 - impl1 = conn.upload(['implementation'], StringIO(self.zips(['TestActivity/activity/activity.info', [ + impl1 = conn.upload(['release'], StringIO(self.zips(['TestActivity/activity/activity.info', [ '[Activity]', 'name = TestActivity', 'bundle_id = context', @@ -242,13 +242,13 @@ class CacheTest(tests.Test): conn.put(['context', 'context'], True, cmd='clone') self.assertEqual([], [i for i in self.client_routes._cache]) - assert local_volume['implementation'].exists(impl1) + 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['implementation'].exists(impl1) + assert local_volume['release'].exists(impl1) - impl2 = conn.upload(['implementation'], StringIO(self.zips(['TestActivity/activity/activity.info', [ + impl2 = conn.upload(['release'], StringIO(self.zips(['TestActivity/activity/activity.info', [ '[Activity]', 'name = TestActivity', 'bundle_id = context', @@ -262,21 +262,21 @@ class CacheTest(tests.Test): shutil.rmtree('solutions') conn.put(['context', 'context'], True, cmd='clone') self.assertEqual([impl1], [i for i in self.client_routes._cache]) - assert local_volume['implementation'].exists(impl1) - assert local_volume['implementation'].exists(impl2) + 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['implementation'].exists(impl1) - assert local_volume['implementation'].exists(impl2) + assert local_volume['release'].exists(impl1) + assert local_volume['release'].exists(impl2) def test_Acquiring(self): - volume = db.Volume('db', [Context, Implementation]) + volume = db.Volume('db', [Context, Release]) cache = Cache(volume) - volume['implementation'].create({'guid': '1', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - volume['implementation'].create({'guid': '2', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) - volume['implementation'].create({'guid': '3', 'context': 'context', 'version': '1', 'license': ['GPL'], 'stability': 'stable'}) + 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]) |