Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/units/model
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/model')
-rw-r--r--tests/units/model/__main__.py2
-rwxr-xr-xtests/units/model/context.py327
-rwxr-xr-xtests/units/model/model.py519
-rwxr-xr-xtests/units/model/post.py176
-rwxr-xr-xtests/units/model/release.py124
-rwxr-xr-xtests/units/model/routes.py86
6 files changed, 932 insertions, 302 deletions
diff --git a/tests/units/model/__main__.py b/tests/units/model/__main__.py
index 2766988..3814380 100644
--- a/tests/units/model/__main__.py
+++ b/tests/units/model/__main__.py
@@ -2,9 +2,9 @@
from __init__ import tests
+from model import *
from post import *
from context import *
-from release import *
from routes import *
if __name__ == '__main__':
diff --git a/tests/units/model/context.py b/tests/units/model/context.py
index 3389f41..71357f2 100755
--- a/tests/units/model/context.py
+++ b/tests/units/model/context.py
@@ -1,82 +1,331 @@
#!/usr/bin/env python
# sugar-lint: disable
+from cStringIO import StringIO
from os.path import exists
from __init__ import tests
from sugar_network import db
-from sugar_network.node import obs
+from sugar_network.db import files
+from sugar_network.client import IPCConnection, Connection, keyfile
from sugar_network.model.context import Context
-from sugar_network.client import IPCConnection
-from sugar_network.toolkit import coroutine, enforce
+from sugar_network.toolkit.coroutine import this
+from sugar_network.toolkit.router import Request
+from sugar_network.toolkit import i18n, http, coroutine, enforce
class ContextTest(tests.Test):
def test_SetCommonLayerForPackages(self):
- self.start_online_client()
- ipc = IPCConnection()
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
- guid = ipc.post(['context'], {
+ guid = conn.post(['context'], {
'type': 'package',
'title': 'title',
'summary': 'summary',
'description': 'description',
})
- self.assertEqual(['common'], ipc.get(['context', guid, 'layer']))
+ self.assertEqual(['common'], conn.get(['context', guid, 'layer']))
- guid = ipc.post(['context'], {
+ guid = conn.post(['context'], {
'type': 'package',
'title': 'title',
'summary': 'summary',
'description': 'description',
'layer': 'foo',
})
- self.assertEqual(['foo', 'common'], ipc.get(['context', guid, 'layer']))
+ self.assertEqual(['foo', 'common'], conn.get(['context', guid, 'layer']))
- guid = ipc.post(['context'], {
+ guid = conn.post(['context'], {
'type': 'package',
'title': 'title',
'summary': 'summary',
'description': 'description',
'layer': ['common', 'bar'],
})
- self.assertEqual(['common', 'bar'], ipc.get(['context', guid, 'layer']))
+ self.assertEqual(['common', 'bar'], conn.get(['context', guid, 'layer']))
- def test_DefaultImages(self):
- self.start_online_client()
- ipc = IPCConnection()
+ def test_Releases(self):
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
- guid = ipc.post(['context'], {
- 'guid': 'guid',
+ context = conn.post(['context'], {
'type': 'activity',
- 'title': 'title',
+ 'title': 'Activity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+
+ activity_info1 = '\n'.join([
+ '[Activity]',
+ 'name = Activity',
+ 'bundle_id = %s' % context,
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 1',
+ 'license = Public Domain',
+ ])
+ bundle1 = self.zips(('topdir/activity/activity.info', activity_info1))
+ release1 = conn.upload(['context', context, 'releases'], StringIO(bundle1))
+ assert release1 == str(hash(bundle1))
+ self.assertEqual({
+ release1: {
+ 'seqno': 5,
+ 'author': {tests.UID: {'name': tests.UID, 'order': 0, 'role': 3}},
+ 'value': {
+ 'license': ['Public Domain'],
+ 'announce': next(volume['post'].find(query='title:1')[0]).guid,
+ 'release': [[1], 0],
+ 'requires': [],
+ 'spec': {'*-*': {'bundle': str(hash(bundle1)), 'commands': {'activity': {'exec': 'true'}}, 'requires': {}}},
+ 'stability': 'stable',
+ 'unpack_size': len(activity_info1),
+ 'version': '1',
+ },
+ },
+ }, conn.get(['context', context, 'releases']))
+ assert files.get(str(hash(bundle1)))
+
+ activity_info2 = '\n'.join([
+ '[Activity]',
+ 'name = Activity',
+ 'bundle_id = %s' % context,
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 2',
+ 'license = Public Domain',
+ ])
+ bundle2 = self.zips(('topdir/activity/activity.info', activity_info2))
+ release2 = conn.upload(['context', context, 'releases'], StringIO(bundle2))
+ assert release2 == str(hash(bundle2))
+ self.assertEqual({
+ release1: {
+ 'seqno': 5,
+ 'author': {tests.UID: {'name': tests.UID, 'order': 0, 'role': 3}},
+ 'value': {
+ 'license': ['Public Domain'],
+ 'announce': next(volume['post'].find(query='title:1')[0]).guid,
+ 'release': [[1], 0],
+ 'requires': [],
+ 'spec': {'*-*': {'bundle': str(hash(bundle1)), 'commands': {'activity': {'exec': 'true'}}, 'requires': {}}},
+ 'stability': 'stable',
+ 'unpack_size': len(activity_info1),
+ 'version': '1',
+ },
+ },
+ release2: {
+ 'seqno': 7,
+ 'author': {tests.UID: {'name': tests.UID, 'order': 0, 'role': 3}},
+ 'value': {
+ 'license': ['Public Domain'],
+ 'announce': next(volume['post'].find(query='title:2')[0]).guid,
+ 'release': [[2], 0],
+ 'requires': [],
+ 'spec': {'*-*': {'bundle': str(hash(bundle2)), 'commands': {'activity': {'exec': 'true'}}, 'requires': {}}},
+ 'stability': 'stable',
+ 'unpack_size': len(activity_info2),
+ 'version': '2',
+ },
+ },
+ }, conn.get(['context', context, 'releases']))
+ assert files.get(str(hash(bundle1)))
+ assert files.get(str(hash(bundle2)))
+
+ conn.delete(['context', context, 'releases', release1])
+ self.assertEqual({
+ release1: {
+ 'seqno': 8,
+ 'author': {tests.UID: {'name': tests.UID, 'order': 0, 'role': 3}},
+ },
+ release2: {
+ 'seqno': 7,
+ 'author': {tests.UID: {'name': tests.UID, 'order': 0, 'role': 3}},
+ 'value': {
+ 'license': ['Public Domain'],
+ 'announce': next(volume['post'].find(query='title:2')[0]).guid,
+ 'release': [[2], 0],
+ 'requires': [],
+ 'spec': {'*-*': {'bundle': str(hash(bundle2)), 'commands': {'activity': {'exec': 'true'}}, 'requires': {}}},
+ 'stability': 'stable',
+ 'unpack_size': len(activity_info2),
+ 'version': '2',
+ },
+ },
+ }, conn.get(['context', context, 'releases']))
+ assert files.get(str(hash(bundle1))) is None
+ assert files.get(str(hash(bundle2)))
+
+ conn.delete(['context', context, 'releases', release2])
+ self.assertEqual({
+ release1: {
+ 'seqno': 8,
+ 'author': {tests.UID: {'name': tests.UID, 'order': 0, 'role': 3}},
+ },
+ release2: {
+ 'seqno': 9,
+ 'author': {tests.UID: {'name': tests.UID, 'order': 0, 'role': 3}},
+ },
+ }, conn.get(['context', context, 'releases']))
+ assert files.get(str(hash(bundle1))) is None
+ assert files.get(str(hash(bundle2))) is None
+
+ def test_IncrementReleasesSeqnoOnNewReleases(self):
+ events = []
+ volume = self.start_master()
+ this.broadcast = lambda x: events.append(x)
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ context = conn.post(['context'], {
+ 'type': 'activity',
+ 'title': 'Activity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+ self.assertEqual([
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(0, volume.releases_seqno.value)
+
+ conn.put(['context', context], {
+ 'summary': 'summary2',
+ })
+ self.assertEqual([
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(0, volume.releases_seqno.value)
+
+ bundle = self.zips(('topdir/activity/activity.info', '\n'.join([
+ '[Activity]',
+ 'name = Activity',
+ 'bundle_id = %s' % context,
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 1',
+ 'license = Public Domain',
+ ])))
+ release = conn.upload(['context', context, 'releases'], StringIO(bundle))
+ self.assertEqual([
+ {'event': 'release', 'seqno': 1},
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(1, volume.releases_seqno.value)
+
+ bundle = self.zips(('topdir/activity/activity.info', '\n'.join([
+ '[Activity]',
+ 'name = Activity',
+ 'bundle_id = %s' % context,
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 2',
+ 'license = Public Domain',
+ ])))
+ release = conn.upload(['context', context, 'releases'], StringIO(bundle))
+ self.assertEqual([
+ {'event': 'release', 'seqno': 1},
+ {'event': 'release', 'seqno': 2},
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(2, volume.releases_seqno.value)
+
+ bundle = self.zips(('topdir/activity/activity.info', '\n'.join([
+ '[Activity]',
+ 'name = Activity',
+ 'bundle_id = %s' % context,
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 2',
+ 'license = Public Domain',
+ ])))
+ release = conn.upload(['context', context, 'releases'], StringIO(bundle))
+ self.assertEqual([
+ {'event': 'release', 'seqno': 1},
+ {'event': 'release', 'seqno': 2},
+ {'event': 'release', 'seqno': 3},
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(3, volume.releases_seqno.value)
+
+ conn.delete(['context', context, 'releases', release])
+ self.assertEqual([
+ {'event': 'release', 'seqno': 1},
+ {'event': 'release', 'seqno': 2},
+ {'event': 'release', 'seqno': 3},
+ {'event': 'release', 'seqno': 4},
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(4, volume.releases_seqno.value)
+
+ def test_IncrementReleasesSeqnoOnDependenciesChange(self):
+ events = []
+ volume = self.start_master()
+ this.broadcast = lambda x: events.append(x)
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ context = conn.post(['context'], {
+ 'type': 'activity',
+ 'title': 'Activity',
'summary': 'summary',
'description': 'description',
})
- assert exists('master/context/gu/guid/artifact_icon.blob')
- assert exists('master/context/gu/guid/icon.blob')
- assert exists('master/context/gu/guid/logo.blob')
-
- def test_RatingSort(self):
- directory = db.Volume('db', [Context])['context']
-
- directory.create({'guid': '1', 'type': 'activity', 'title': '', 'summary': '', 'description': '', 'rating': [0, 0]})
- directory.create({'guid': '2', 'type': 'activity', 'title': '', 'summary': '', 'description': '', 'rating': [1, 2]})
- directory.create({'guid': '3', 'type': 'activity', 'title': '', 'summary': '', 'description': '', 'rating': [1, 4]})
- directory.create({'guid': '4', 'type': 'activity', 'title': '', 'summary': '', 'description': '', 'rating': [10, 10]})
- directory.create({'guid': '5', 'type': 'activity', 'title': '', 'summary': '', 'description': '', 'rating': [30, 90]})
-
- self.assertEqual(
- ['1', '2', '3', '4', '5'],
- [i.guid for i in directory.find()[0]])
- self.assertEqual(
- ['1', '4', '2', '5', '3'],
- [i.guid for i in directory.find(order_by='rating')[0]])
- self.assertEqual(
- ['3', '5', '2', '4', '1'],
- [i.guid for i in directory.find(order_by='-rating')[0]])
+ self.assertEqual([
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(0, volume.releases_seqno.value)
+
+ conn.put(['context', context], {
+ 'dependencies': 'dep',
+ })
+ self.assertEqual([
+ {'event': 'release', 'seqno': 1},
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(1, volume.releases_seqno.value)
+
+ def test_IncrementReleasesSeqnoOnDeletes(self):
+ events = []
+ volume = self.start_master()
+ this.broadcast = lambda x: events.append(x)
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ context = conn.post(['context'], {
+ 'type': 'activity',
+ 'title': 'Activity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+ self.assertEqual([
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(0, volume.releases_seqno.value)
+
+ conn.put(['context', context], {
+ 'layer': ['deleted'],
+ })
+ self.assertEqual([
+ {'event': 'release', 'seqno': 1},
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(1, volume.releases_seqno.value)
+
+ conn.put(['context', context], {
+ 'layer': [],
+ })
+ self.assertEqual([
+ {'event': 'release', 'seqno': 1},
+ {'event': 'release', 'seqno': 2},
+ ], [i for i in events if i['event'] == 'release'])
+ self.assertEqual(2, volume.releases_seqno.value)
+
+ def test_RestoreReleasesSeqno(self):
+ events = []
+ volume = self.start_master()
+ this.broadcast = lambda x: events.append(x)
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ context = conn.post(['context'], {
+ 'type': 'activity',
+ 'title': 'Activity',
+ 'summary': 'summary',
+ 'description': 'description',
+ 'dependencies': 'dep',
+ })
+ self.assertEqual(1, volume.releases_seqno.value)
+
+ volume.close()
+ volume = db.Volume('master', [])
+ self.assertEqual(1, volume.releases_seqno.value)
if __name__ == '__main__':
diff --git a/tests/units/model/model.py b/tests/units/model/model.py
new file mode 100755
index 0000000..f8b3866
--- /dev/null
+++ b/tests/units/model/model.py
@@ -0,0 +1,519 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# sugar-lint: disable
+
+import base64
+
+from __init__ import tests
+
+from sugar_network import db
+from sugar_network.db import files
+from sugar_network.model import load_bundle
+from sugar_network.model.post import Post
+from sugar_network.client import IPCConnection, Connection, keyfile
+from sugar_network.toolkit.router import Request
+from sugar_network.toolkit.coroutine import this
+from sugar_network.toolkit import i18n, http, coroutine, enforce
+
+
+class ModelTest(tests.Test):
+
+ def test_RatingSort(self):
+ directory = db.Volume('db', [Post])['post']
+
+ directory.create({'guid': '1', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'rating': [0, 0]})
+ directory.create({'guid': '2', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'rating': [1, 2]})
+ directory.create({'guid': '3', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'rating': [1, 4]})
+ directory.create({'guid': '4', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'rating': [10, 10]})
+ directory.create({'guid': '5', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'rating': [30, 90]})
+
+ self.assertEqual(
+ ['1', '2', '3', '4', '5'],
+ [i.guid for i in directory.find()[0]])
+ self.assertEqual(
+ ['1', '4', '2', '5', '3'],
+ [i.guid for i in directory.find(order_by='rating')[0]])
+ self.assertEqual(
+ ['3', '5', '2', '4', '1'],
+ [i.guid for i in directory.find(order_by='-rating')[0]])
+
+ def test_load_bundle_Activity(self):
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ conn.post(['context'], {
+ 'guid': 'bundle_id',
+ 'type': 'activity',
+ 'title': 'Activity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+ activity_info = '\n'.join([
+ '[Activity]',
+ 'name = Activity',
+ 'bundle_id = bundle_id',
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 1',
+ 'license = Public Domain',
+ 'stability = developer',
+ 'requires = sugar>=0.88; dep'
+ ])
+ changelog = "LOG"
+ bundle = self.zips(
+ ('topdir/activity/activity.info', activity_info),
+ ('topdir/CHANGELOG', changelog),
+ )
+ blob = files.post(bundle)
+
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID)
+ context, release = load_bundle(blob, 'bundle_id')
+
+ self.assertEqual({
+ 'mime_type': 'application/vnd.olpc-sugar',
+ 'name': 'Activity-1',
+ }, files.get(blob.digest))
+ self.assertEqual('bundle_id', context)
+ self.assertEqual('1', release['version'])
+ self.assertEqual('developer', release['stability'])
+ self.assertEqual(['Public Domain'], release['license'])
+ self.assertEqual('developer', release['stability'])
+ self.assertEqual(sorted(['dep', 'sugar-0.88']), sorted(release['requires']))
+ self.assertEqual({
+ '*-*': {
+ 'bundle': blob.digest,
+ 'commands': {'activity': {'exec': 'true'}},
+ 'requires': {'dep': {}, 'sugar': {'restrictions': [('0.88', None)]}},
+ },
+ },
+ release['spec'])
+ self.assertEqual(len(activity_info) + len(changelog), release['unpack_size'])
+
+ post = volume['post'][release['announce']]
+ assert tests.UID in post['author']
+ self.assertEqual('notification', post['type'])
+ self.assertEqual({
+ 'en': 'Activity 1 release',
+ 'es': 'Activity 1 release',
+ 'fr': 'Activity 1 release',
+ }, post['title'])
+ self.assertEqual({
+ 'en-us': 'LOG',
+ }, post['message'])
+
+ def test_load_bundle_NonActivity(self):
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ conn.post(['context'], {
+ 'guid': 'bundle_id',
+ 'type': 'book',
+ 'title': 'NonActivity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+ bundle = 'non-activity'
+ blob = files.post(bundle)
+
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID,
+ content_type = 'content/type', version='2', license='GPL')
+ context, release = load_bundle(blob, 'bundle_id')
+
+ self.assertEqual({
+ 'mime_type': 'content/type',
+ 'name': 'NonActivity-2',
+ }, files.get(blob.digest))
+ self.assertEqual('bundle_id', context)
+ self.assertEqual('2', release['version'])
+ self.assertEqual(['GPL'], release['license'])
+
+ post = volume['post'][release['announce']]
+ assert tests.UID in post['author']
+ self.assertEqual('notification', post['type'])
+ self.assertEqual({
+ 'en': 'NonActivity 2 release',
+ 'es': 'NonActivity 2 release',
+ 'fr': 'NonActivity 2 release',
+ }, post['title'])
+ self.assertEqual({
+ 'en-us': '',
+ }, post['message'])
+
+ def test_load_bundle_ReuseActivityLicense(self):
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ conn.post(['context'], {
+ 'guid': 'bundle_id',
+ 'type': 'activity',
+ 'title': 'Activity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+
+ activity_info_wo_license = '\n'.join([
+ '[Activity]',
+ 'name = Activity',
+ 'bundle_id = bundle_id',
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 1',
+ ])
+ bundle = self.zips(('topdir/activity/activity.info', activity_info_wo_license))
+ blob_wo_license = files.post(bundle)
+ self.assertRaises(http.BadRequest, load_bundle, blob_wo_license, 'bundle_id')
+
+ volume['context'].update('bundle_id', {'releases': {
+ 'new': {'release': 2, 'license': ['New']},
+ }})
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID)
+ context, release = load_bundle(blob_wo_license, 'bundle_id')
+ self.assertEqual(['New'], release['license'])
+
+ volume['context'].update('bundle_id', {'releases': {
+ 'new': {'release': 2, 'license': ['New']},
+ 'old': {'release': 1, 'license': ['Old']},
+ }})
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID)
+ context, release = load_bundle(blob_wo_license, 'bundle_id')
+ self.assertEqual(['New'], release['license'])
+
+ volume['context'].update('bundle_id', {'releases': {
+ 'new': {'release': 2, 'license': ['New']},
+ 'old': {'release': 1, 'license': ['Old']},
+ 'newest': {'release': 3, 'license': ['Newest']},
+ }})
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID)
+ context, release = load_bundle(blob_wo_license, 'bundle_id')
+ self.assertEqual(['Newest'], release['license'])
+
+ def test_load_bundle_ReuseNonActivityLicense(self):
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ conn.post(['context'], {
+ 'guid': 'bundle_id',
+ 'type': 'book',
+ 'title': 'Activity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+
+ blob = files.post('non-activity')
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID, version='1')
+ self.assertRaises(http.BadRequest, load_bundle, blob, 'bundle_id')
+
+ volume['context'].update('bundle_id', {'releases': {
+ 'new': {'release': 2, 'license': ['New']},
+ }})
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID, version='1')
+ context, release = load_bundle(blob, 'bundle_id')
+ self.assertEqual(['New'], release['license'])
+
+ volume['context'].update('bundle_id', {'releases': {
+ 'new': {'release': 2, 'license': ['New']},
+ 'old': {'release': 1, 'license': ['Old']},
+ }})
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID, version='1')
+ context, release = load_bundle(blob, 'bundle_id')
+ self.assertEqual(['New'], release['license'])
+
+ volume['context'].update('bundle_id', {'releases': {
+ 'new': {'release': 2, 'license': ['New']},
+ 'old': {'release': 1, 'license': ['Old']},
+ 'newest': {'release': 3, 'license': ['Newest']},
+ }})
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID, version='1')
+ context, release = load_bundle(blob, 'bundle_id')
+ self.assertEqual(['Newest'], release['license'])
+
+ def test_load_bundle_WrontContextType(self):
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ conn.post(['context'], {
+ 'guid': 'bundle_id',
+ 'type': 'group',
+ 'title': 'NonActivity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+
+ blob = files.post('non-activity')
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID, version='2', license='GPL')
+ self.assertRaises(http.BadRequest, load_bundle, blob, 'bundle_id')
+
+ activity_info = '\n'.join([
+ '[Activity]',
+ 'name = Activity',
+ 'bundle_id = bundle_id',
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 1',
+ 'license = Public Domain',
+ 'stability = developer',
+ 'requires = sugar>=0.88; dep'
+ ])
+ changelog = "LOG"
+ bundle = self.zips(
+ ('topdir/activity/activity.info', activity_info),
+ ('topdir/CHANGELOG', changelog),
+ )
+ blob = files.post(bundle)
+ self.assertRaises(http.BadRequest, load_bundle, blob, 'bundle_id')
+
+ def test_load_bundle_MissedContext(self):
+ volume = self.start_master()
+ volume['user'].create({'guid': tests.UID, 'name': 'user', 'pubkey': tests.PUBKEY})
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ bundle = self.zips(('topdir/activity/activity.info', '\n'.join([
+ '[Activity]',
+ 'name = Activity',
+ 'bundle_id = bundle_id',
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 1',
+ 'license = Public Domain',
+ 'stability = developer',
+ 'requires = sugar>=0.88; dep'
+ ])))
+ blob = files.post(bundle)
+
+ this.request = Request(principal=tests.UID)
+ self.assertRaises(http.NotFound, load_bundle, blob, initial=False)
+
+ def test_load_bundle_CreateContext(self):
+ volume = self.start_master()
+ volume['user'].create({'guid': tests.UID, 'name': 'user', 'pubkey': tests.PUBKEY})
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ bundle = self.zips(
+ ('ImageViewer.activity/activity/activity.info', '\n'.join([
+ '[Activity]',
+ 'bundle_id = org.laptop.ImageViewerActivity',
+ 'name = Image Viewer',
+ 'summary = The Image Viewer activity is a simple and fast image viewer tool',
+ 'description = It has features one would expect of a standard image viewer, like zoom, rotate, etc.',
+ 'homepage = http://wiki.sugarlabs.org/go/Activities/Image_Viewer',
+ 'activity_version = 1',
+ 'license = GPLv2+',
+ 'icon = activity-imageviewer',
+ 'exec = true',
+ 'mime_types = image/bmp;image/gif',
+ ])),
+ ('ImageViewer.activity/activity/activity-imageviewer.svg', ''),
+ )
+ blob = files.post(bundle)
+
+ this.request = Request(principal=tests.UID)
+ context, release = load_bundle(blob, initial=True)
+ self.assertEqual('org.laptop.ImageViewerActivity', context)
+
+ context = volume['context'].get('org.laptop.ImageViewerActivity')
+ self.assertEqual({'en': 'Image Viewer'}, context['title'])
+ self.assertEqual({'en': 'The Image Viewer activity is a simple and fast image viewer tool'}, context['summary'])
+ self.assertEqual({'en': 'It has features one would expect of a standard image viewer, like zoom, rotate, etc.'}, context['description'])
+ self.assertEqual('http://wiki.sugarlabs.org/go/Activities/Image_Viewer', context['homepage'])
+ self.assertEqual(['image/bmp', 'image/gif'], context['mime_types'])
+ assert context['ctime'] > 0
+ assert context['mtime'] > 0
+ self.assertEqual({tests.UID: {'role': 3, 'name': 'user', 'order': 0}}, context['author'])
+
+ post = volume['post'][release['announce']]
+ assert tests.UID in post['author']
+ self.assertEqual('notification', post['type'])
+ self.assertEqual({
+ 'en': 'Image Viewer 1 release',
+ 'es': 'Image Viewer 1 release',
+ 'fr': 'Image Viewer 1 release',
+ }, post['title'])
+
+ def test_load_bundle_UpdateContext(self):
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ conn.post(['context'], {
+ 'guid': 'org.laptop.ImageViewerActivity',
+ 'type': 'activity',
+ 'title': {'en': ''},
+ 'summary': {'en': ''},
+ 'description': {'en': ''},
+ })
+ svg = '\n'.join([
+ '<?xml version="1.0" encoding="UTF-8"?>',
+ '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [',
+ ' <!ENTITY fill_color "#123456">',
+ ' <!ENTITY stroke_color "#123456">',
+ ']>',
+ '<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50">',
+ ' <rect x="3" y="7" width="44" height="36" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3"/>',
+ ' <polyline points="15,7 25,1 35,7" style="fill:none;;stroke:&stroke_color;;stroke-width:1.25"/>',
+ ' <circle cx="14" cy="19" r="4.5" style="fill:&stroke_color;;stroke:&stroke_color;;stroke-width:1.5"/>',
+ ' <polyline points="3,36 16,32 26,35" style="fill:none;;stroke:&stroke_color;;stroke-width:2.5"/>',
+ ' <polyline points="15,43 37,28 47,34 47,43" style="fill:&stroke_color;;stroke:&stroke_color;;stroke-width:3"/>',
+ ' <polyline points="22,41.5 35,30 27,41.5" style="fill:&fill_color;;stroke:none;;stroke-width:0"/>',
+ ' <polyline points="26,23 28,25 30,23" style="fill:none;;stroke:&stroke_color;;stroke-width:.9"/>',
+ ' <polyline points="31.2,20 33.5,17.7 35.8,20" style="fill:none;;stroke:&stroke_color;;stroke-width:1"/>',
+ ' <polyline points="36,13 38.5,15.5 41,13" style="fill:none;;stroke:&stroke_color;;stroke-width:1"/>',
+ '</svg>',
+ ])
+ bundle = self.zips(
+ ('ImageViewer.activity/activity/activity.info', '\n'.join([
+ '[Activity]',
+ 'bundle_id = org.laptop.ImageViewerActivity',
+ 'name = Image Viewer',
+ 'summary = The Image Viewer activity is a simple and fast image viewer tool',
+ 'description = It has features one would expect of a standard image viewer, like zoom, rotate, etc.',
+ 'homepage = http://wiki.sugarlabs.org/go/Activities/Image_Viewer',
+ 'activity_version = 22',
+ 'license = GPLv2+',
+ 'icon = activity-imageviewer',
+ 'exec = true',
+ 'mime_types = image/bmp;image/gif',
+ ])),
+ ('ImageViewer.activity/locale/ru/LC_MESSAGES/org.laptop.ImageViewerActivity.mo',
+ base64.b64decode('3hIElQAAAAAMAAAAHAAAAHwAAAARAAAA3AAAAAAAAAAgAQAADwAAACEBAAAOAAAAMQEAAA0AAABAAQAACgAAAE4BAAAMAAAAWQEAAA0AAABmAQAAJwAAAHQBAAAUAAAAnAEAABAAAACxAQAABwAAAMIBAAAIAAAAygEAANEBAADTAQAAIQAAAKUDAAATAAAAxwMAABwAAADbAwAAFwAAAPgDAAAhAAAAEAQAAB0AAAAyBAAAQAAAAFAEAAA9AAAAkQQAADUAAADPBAAAFAAAAAUFAAAQAAAAGgUAAAEAAAACAAAABwAAAAAAAAADAAAAAAAAAAwAAAAJAAAAAAAAAAoAAAAEAAAAAAAAAAAAAAALAAAABgAAAAgAAAAFAAAAAENob29zZSBkb2N1bWVudABEb3dubG9hZGluZy4uLgBGaXQgdG8gd2luZG93AEZ1bGxzY3JlZW4ASW1hZ2UgVmlld2VyAE9yaWdpbmFsIHNpemUAUmV0cmlldmluZyBzaGFyZWQgaW1hZ2UsIHBsZWFzZSB3YWl0Li4uAFJvdGF0ZSBhbnRpY2xvY2t3aXNlAFJvdGF0ZSBjbG9ja3dpc2UAWm9vbSBpbgBab29tIG91dABQcm9qZWN0LUlkLVZlcnNpb246IFBBQ0tBR0UgVkVSU0lPTgpSZXBvcnQtTXNnaWQtQnVncy1UbzogClBPVC1DcmVhdGlvbi1EYXRlOiAyMDEyLTA5LTI3IDE0OjU3LTA0MDAKUE8tUmV2aXNpb24tRGF0ZTogMjAxMC0wOS0yMiAxMzo1MCswMjAwCkxhc3QtVHJhbnNsYXRvcjoga3JvbTlyYSA8a3JvbTlyYUBnbWFpbC5jb20+Ckxhbmd1YWdlLVRlYW06IExBTkdVQUdFIDxMTEBsaS5vcmc+Ckxhbmd1YWdlOiAKTUlNRS1WZXJzaW9uOiAxLjAKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PVVURi04CkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IDhiaXQKUGx1cmFsLUZvcm1zOiBucGx1cmFscz0zOyBwbHVyYWw9KG4lMTA9PTEgJiYgbiUxMDAhPTExID8gMCA6IG4lMTA+PTIgJiYgbiUxMDw9NCAmJiAobiUxMDA8MTAgfHwgbiUxMDA+PTIwKSA/IDEgOiAyKTsKWC1HZW5lcmF0b3I6IFBvb3RsZSAyLjAuMwoA0JLRi9Cx0LXRgNC40YLQtSDQtNC+0LrRg9C80LXQvdGCANCX0LDQs9GA0YPQt9C60LAuLi4A0KPQvNC10YHRgtC40YLRjCDQsiDQvtC60L3QtQDQn9C+0LvQvdGL0Lkg0Y3QutGA0LDQvQDQn9GA0L7RgdC80L7RgtGAINC60LDRgNGC0LjQvdC+0LoA0JjRgdGC0LjQvdC90YvQuSDRgNCw0LfQvNC10YAA0J/QvtC70YPRh9C10L3QuNC1INC40LfQvtCx0YDQsNC20LXQvdC40LksINC/0L7QtNC+0LbQtNC40YLQtS4uLgDQn9C+0LLQtdGA0L3Rg9GC0Ywg0L/RgNC+0YLQuNCyINGH0LDRgdC+0LLQvtC5INGB0YLRgNC10LvQutC4ANCf0L7QstC10YDQvdGD0YLRjCDQv9C+INGH0LDRgdC+0LLQvtC5INGB0YLRgNC10LvQutC1ANCf0YDQuNCx0LvQuNC30LjRgtGMANCe0YLQtNCw0LvQuNGC0YwA')),
+ ('ImageViewer.activity/activity/activity-imageviewer.svg', svg),
+ )
+
+ blob = files.post(bundle)
+ this.request = Request(method='POST', path=['context', 'org.laptop.ImageViewerActivity'], principal=tests.UID)
+ context, release = load_bundle(blob, initial=True)
+
+ context = volume['context'].get('org.laptop.ImageViewerActivity')
+ self.assertEqual({
+ 'en': 'Image Viewer',
+ 'ru': u'Просмотр картинок',
+ },
+ context['title'])
+ self.assertEqual({
+ 'en': 'The Image Viewer activity is a simple and fast image viewer tool',
+ },
+ context['summary'])
+ self.assertEqual({
+ 'en': 'It has features one would expect of a standard image viewer, like zoom, rotate, etc.',
+ },
+ context['description'])
+ self.assertEqual(svg, file(files.get(context['artifact_icon']).path).read())
+ assert context['icon'] != 'missing.png'
+ assert context['logo'] != 'missing-logo.png'
+ self.assertEqual('http://wiki.sugarlabs.org/go/Activities/Image_Viewer', context['homepage'])
+ self.assertEqual(['image/bmp', 'image/gif'], context['mime_types'])
+
+ def test_load_bundle_3rdPartyRelease(self):
+ i18n._default_langs = ['en']
+ volume = self.start_master()
+ volume['user'].create({'guid': tests.UID2, 'name': 'user2', 'pubkey': tests.PUBKEY2})
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ conn.post(['context'], {
+ 'guid': 'bundle_id',
+ 'type': 'activity',
+ 'title': 'Activity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+
+ bundle = self.zips(('topdir/activity/activity.info', '\n'.join([
+ '[Activity]',
+ 'name = Activity2',
+ 'bundle_id = bundle_id',
+ 'exec = true',
+ 'icon = icon',
+ 'activity_version = 1',
+ 'license = Public Domain',
+ 'stability = developer',
+ ])))
+ blob = files.post(bundle)
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID2)
+ context, release = load_bundle(blob, 'bundle_id')
+
+ assert tests.UID in volume['context']['bundle_id']['author']
+ assert tests.UID2 not in volume['context']['bundle_id']['author']
+ self.assertEqual({'en': 'Activity'}, volume['context']['bundle_id']['title'])
+
+ post = volume['post'][release['announce']]
+ assert tests.UID not in post['author']
+ assert tests.UID2 in post['author']
+ self.assertEqual('notification', post['type'])
+ self.assertEqual({
+ 'en': 'Activity 1 third-party release',
+ 'es': 'Activity 1 third-party release',
+ 'fr': 'Activity 1 third-party release',
+ }, post['title'])
+
+ files.delete(blob.digest)
+ blob = files.post(bundle)
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID)
+ context, release = load_bundle(blob, 'bundle_id')
+
+ assert tests.UID in volume['context']['bundle_id']['author']
+ assert tests.UID2 not in volume['context']['bundle_id']['author']
+ self.assertEqual({'en': 'Activity2'}, volume['context']['bundle_id']['title'])
+
+ post = volume['post'][release['announce']]
+ assert tests.UID in post['author']
+ assert tests.UID2 not in post['author']
+ self.assertEqual('notification', post['type'])
+ self.assertEqual({
+ 'en': 'Activity2 1 release',
+ 'es': 'Activity2 1 release',
+ 'fr': 'Activity2 1 release',
+ }, post['title'])
+
+ def test_load_bundle_PopulateRequires(self):
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ conn.post(['context'], {
+ 'guid': 'bundle_id',
+ 'type': 'activity',
+ 'title': 'Activity',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+ bundle = self.zips(
+ ('ImageViewer.activity/activity/activity.info', '\n'.join([
+ '[Activity]',
+ 'bundle_id = bundle_id',
+ 'name = Image Viewer',
+ 'activity_version = 22',
+ 'license = GPLv2+',
+ 'icon = activity-imageviewer',
+ 'exec = true',
+ 'requires = dep1, dep2<10, dep3<=20, dep4>30, dep5>=40, dep6>5<7, dep7>=1<=3',
+ ])),
+ ('ImageViewer.activity/activity/activity-imageviewer.svg', ''),
+ )
+ blob = files.post(bundle)
+ this.request = Request(method='POST', path=['context', 'bundle_id'], principal=tests.UID)
+ context, release = load_bundle(blob, 'bundle_id')
+
+ self.assertEqual(
+ sorted([
+ 'dep1', 'dep2', 'dep3', 'dep4-31', 'dep5-40',
+ 'dep6-6',
+ 'dep7-1', 'dep7-2', 'dep7-3',
+ ]),
+ sorted(release['requires']))
+
+ def test_load_bundle_IgnoreNotSupportedContextTypes(self):
+ volume = self.start_master()
+ conn = Connection(auth=http.SugarAuth(keyfile.value))
+
+ context = conn.post(['context'], {
+ 'type': 'package',
+ 'title': '',
+ 'summary': '',
+ 'description': '',
+ })
+ this.request = Request(method='POST', path=['context', context])
+ aggid = conn.post(['context', context, 'releases'], -1)
+ self.assertEqual({
+ aggid: {'seqno': 3, 'value': -1, 'author': {tests.UID: {'role': 3, 'name': tests.UID, 'order': 0}}},
+ }, volume['context'][context]['releases'])
+
+
+if __name__ == '__main__':
+ tests.main()
diff --git a/tests/units/model/post.py b/tests/units/model/post.py
index dc6f6f4..45b85e1 100755
--- a/tests/units/model/post.py
+++ b/tests/units/model/post.py
@@ -8,74 +8,27 @@ from sugar_network.client import Connection, keyfile
from sugar_network.model.user import User
from sugar_network.model.context import Context
from sugar_network.model.post import Post
-from sugar_network.model.release import Release
+from sugar_network.toolkit.coroutine import this
from sugar_network.toolkit import http
class PostTest(tests.Test):
- def test_SetContext(self):
- volume = self.start_master([User, Context, Release, Post])
- client = Connection(auth=http.SugarAuth(keyfile.value))
-
- self.assertRaises(http.NotFound, client.post, ['post'], {'type': 'comment', 'title': '', 'message': '', 'topic': 'absent'})
-
- context = client.post(['context'], {
- 'type': 'package',
- 'title': 'title',
- 'summary': 'summary',
- 'description': 'description',
- })
- topic = client.post(['post'], {
- 'context': context,
- 'title': 'title',
- 'message': 'message',
- 'type': 'update',
- })
- comment = client.post(['post'], {
- 'topic': topic,
- 'title': 'title',
- 'message': 'message',
- 'type': 'comment',
- })
- self.assertEqual(
- context,
- client.get(['post', comment, 'context']))
-
- def test_RatingSort(self):
- directory = db.Volume('db', [Post])['post']
-
- directory.create({'guid': '1', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [0, 0]})
- directory.create({'guid': '2', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [1, 2]})
- directory.create({'guid': '3', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [1, 4]})
- directory.create({'guid': '4', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [10, 10]})
- directory.create({'guid': '5', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [30, 90]})
-
- self.assertEqual(
- ['1', '2', '3', '4', '5'],
- [i.guid for i in directory.find()[0]])
- self.assertEqual(
- ['1', '4', '2', '5', '3'],
- [i.guid for i in directory.find(order_by='rating')[0]])
- self.assertEqual(
- ['3', '5', '2', '4', '1'],
- [i.guid for i in directory.find(order_by='-rating')[0]])
-
def test_FindComments(self):
directory = db.Volume('db', [Post])['post']
- directory.create({'guid': '1', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'comments': {
- '1': {'message': 'foo'},
+ directory.create({'guid': '1', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'comments': {
+ '1': {'value': {'en': 'foo'}},
}})
- directory.create({'guid': '2', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'comments': {
- '1': {'message': 'bar'},
+ directory.create({'guid': '2', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'comments': {
+ '1': {'value': {'en': 'bar'}},
}})
- directory.create({'guid': '3', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'comments': {
- '1': {'message': 'bar'},
- '2': {'message': 'foo'},
+ directory.create({'guid': '3', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'comments': {
+ '1': {'value': {'en': 'bar'}},
+ '2': {'value': {'en': 'foo'}},
}})
- directory.create({'guid': '4', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'comments': {
- '1': {'message': 'foo bar'},
+ directory.create({'guid': '4', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'comments': {
+ '1': {'value': {'en': 'foo bar'}},
}})
self.assertEqual(
@@ -92,6 +45,115 @@ class PostTest(tests.Test):
['1', '3', '4'],
[i.guid for i in directory.find(query='comments:foo')[0]])
+ def test_ShiftContextRating(self):
+ volume = db.Volume('db', [Context, Post])
+ this.volume = volume
+
+ context = volume['context'].create({
+ 'type': 'activity',
+ 'title': {},
+ 'summary': {},
+ 'description': {},
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 0,
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 1,
+ })
+ self.assertEqual([1, 1], volume['context'][context]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 2,
+ })
+ self.assertEqual([2, 3], volume['context'][context]['rating'])
+
+ def test_ShiftTopicRating(self):
+ volume = db.Volume('db2', [Context, Post])
+ this.volume = volume
+
+ context = volume['context'].create({
+ 'type': 'activity',
+ 'title': {},
+ 'summary': {},
+ 'description': {},
+ })
+ topic = volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([0, 0], volume['post'][topic]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'topic': topic,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([0, 0], volume['post'][topic]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'topic': topic,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 0,
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([0, 0], volume['post'][topic]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'topic': topic,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 1,
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([1, 1], volume['post'][topic]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'topic': topic,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 2,
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([2, 3], volume['post'][topic]['rating'])
+
if __name__ == '__main__':
tests.main()
diff --git a/tests/units/model/release.py b/tests/units/model/release.py
deleted file mode 100755
index 2f4bfb1..0000000
--- a/tests/units/model/release.py
+++ /dev/null
@@ -1,124 +0,0 @@
-#!/usr/bin/env python
-# sugar-lint: disable
-
-import os
-
-import xapian
-
-from __init__ import tests
-
-from sugar_network import db
-from sugar_network.model import release
-from sugar_network.model.release import _fmt_version, Release
-from sugar_network.client import IPCConnection
-from sugar_network.toolkit import http, coroutine
-
-
-class ReleaseTest(tests.Test):
-
- def test_fmt_version(self):
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''5''000')),
- _fmt_version('1'))
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0002''0000''5''000')),
- _fmt_version('1.2'))
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0020''0300''5''000')),
- _fmt_version('1.20.300'))
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0020''0300''5''000')),
- _fmt_version('1.20.300.4444'))
-
- self.assertEqual(
- xapian.sortable_serialise(eval('1''9999''0000''5''000')),
- _fmt_version('10001.99999.10000'))
-
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''3''000')),
- _fmt_version('1-pre'))
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''4''000')),
- _fmt_version('1-rc'))
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''5''000')),
- _fmt_version('1-'))
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''6''000')),
- _fmt_version('1-r'))
-
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''3''001')),
- _fmt_version('1-pre1'))
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''4''002')),
- _fmt_version('1-rc2'))
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''6''003')),
- _fmt_version('1-r3'))
-
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''6''000')),
- _fmt_version('1-r-2-3'))
- self.assertEqual(
- xapian.sortable_serialise(eval('1''0000''0000''6''001')),
- _fmt_version('1-r1.2-3'))
-
- def test_OriginalAuthor(self):
- self.start_online_client()
- client = IPCConnection()
-
- self.node_volume['context'].create({
- 'guid': 'context',
- 'type': 'book',
- 'title': 'title',
- 'summary': 'summary',
- 'description': 'description',
- 'author': {'fake': None},
- })
-
- guid = client.post(['release'], {
- 'context': 'context',
- 'license': 'GPLv3+',
- 'version': '1',
- 'stability': 'stable',
- 'notes': '',
- })
- self.assertEqual([], self.node_volume['release'].get(guid)['layer'])
-
- guid = client.post(['release'], {
- 'context': 'context',
- 'license': 'GPLv3+',
- 'version': '1',
- 'stability': 'stable',
- 'notes': '',
- 'layer': ['foo'],
- })
- self.assertEqual(['foo'], self.node_volume['release'].get(guid)['layer'])
-
- self.node_volume['context'].update('context', {'author': {tests.UID: None}})
-
- guid = client.post(['release'], {
- 'context': 'context',
- 'license': 'GPLv3+',
- 'version': '1',
- 'stability': 'stable',
- 'notes': '',
- })
- self.assertEqual(['origin'], self.node_volume['release'].get(guid)['layer'])
-
- guid = client.post(['release'], {
- 'context': 'context',
- 'license': 'GPLv3+',
- 'version': '1',
- 'stability': 'stable',
- 'notes': '',
- 'layer': ['foo'],
- })
- self.assertEqual(
- sorted(['foo', 'origin']),
- sorted(self.node_volume['release'].get(guid)['layer']))
-
-
-if __name__ == '__main__':
- tests.main()
diff --git a/tests/units/model/routes.py b/tests/units/model/routes.py
index 989dfc1..3c21483 100755
--- a/tests/units/model/routes.py
+++ b/tests/units/model/routes.py
@@ -10,36 +10,15 @@ from os.path import exists
from __init__ import tests, src_root
from sugar_network import db, model
+from sugar_network.db import files
from sugar_network.model.user import User
from sugar_network.toolkit.router import Router, Request
+from sugar_network.toolkit.coroutine import this
from sugar_network.toolkit import coroutine
class RoutesTest(tests.Test):
- def test_StaticFiles(self):
- router = Router(model.FrontRoutes())
- local_path = src_root + '/sugar_network/static/httpdocs/images/missing.png'
-
- response = []
- reply = router({
- 'PATH_INFO': '/static/images/missing.png',
- 'REQUEST_METHOD': 'GET',
- },
- lambda status, headers: response.extend([status, dict(headers)]))
- result = file(local_path).read()
- self.assertEqual(result, ''.join([i for i in reply]))
- self.assertEqual([
- '200 OK',
- {
- 'last-modified': formatdate(os.stat(local_path).st_mtime, localtime=False, usegmt=True),
- 'content-length': str(len(result)),
- 'content-type': 'image/png',
- 'content-disposition': 'attachment; filename="missing.png"',
- }
- ],
- response)
-
def test_Subscribe(self):
class Document(db.Resource):
@@ -49,7 +28,7 @@ class RoutesTest(tests.Test):
return value
routes = model.FrontRoutes()
- volume = db.Volume('db', [Document], routes.broadcast)
+ volume = db.Volume('db', [Document])
events = []
def read_events():
@@ -69,6 +48,7 @@ class RoutesTest(tests.Test):
job.kill()
self.assertEqual([
+ {'event': 'pong'},
{'guid': 'guid', 'resource': 'document', 'event': 'create'},
{'guid': 'guid', 'resource': 'document', 'event': 'update'},
{'guid': 'guid', 'event': 'delete', 'resource': u'document'},
@@ -77,66 +57,10 @@ class RoutesTest(tests.Test):
def test_SubscribeWithPong(self):
routes = model.FrontRoutes()
- for event in routes.subscribe(ping=True):
+ for event in routes.subscribe():
break
self.assertEqual({'event': 'pong'}, event)
- def test_feed(self):
- volume = db.Volume('db', model.RESOURCES)
- routes = model.VolumeRoutes(volume)
-
- volume['context'].create({
- 'guid': 'context',
- 'type': 'activity',
- 'title': '',
- 'summary': '',
- 'description': '',
- 'dependencies': ['foo', 'bar'],
- })
- volume['release'].create({
- 'guid': 'release',
- 'context': 'context',
- 'license': 'GPLv3',
- 'version': '1',
- 'date': 0,
- 'stability': 'stable',
- 'notes': '',
- 'data': {
- 'spec': {
- '*-*': {
- 'commands': {'activity': {'exec': 'true'}},
- 'requires': {'dep': {}, 'sugar': {'restrictions': [['0.88', None]]}},
- },
- },
- },
- })
-
- self.assertEqual({
- 'releases': [
- {
- 'guid': 'release',
- 'author': {},
- 'ctime': 0,
- 'data': {
- 'spec': {
- '*-*': {
- 'commands': {'activity': {'exec': 'true'}},
- 'requires': {'dep': {}, 'sugar': {'restrictions': [['0.88', None]]}},
- },
- },
- },
- 'layer': [],
- 'license': 'GPLv3',
- 'notes': {'en-us': ''},
- 'stability': 'stable',
- 'tags': [],
- 'version': '1',
- 'requires': {'bar': {}, 'foo': {}},
- },
- ],
- },
- routes.feed(Request(method='GET', path=['context', 'context']), 'foo'))
-
if __name__ == '__main__':
tests.main()