Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/units/client/solver.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/client/solver.py')
-rwxr-xr-xtests/units/client/solver.py238
1 files changed, 197 insertions, 41 deletions
diff --git a/tests/units/client/solver.py b/tests/units/client/solver.py
index 6e35a50..b3d9666 100755
--- a/tests/units/client/solver.py
+++ b/tests/units/client/solver.py
@@ -2,10 +2,11 @@
# sugar-lint: disable
import os
+import imp
from __init__ import tests
-from sugar_network.client import IPCConnection, packagekit, solver, clones
+from sugar_network.client import IPCConnection, packagekit, solver
from sugar_network.toolkit import lsb_release
@@ -22,57 +23,212 @@ class SolverTest(tests.Test):
self.assertEqual(host_arch, solver.select_architecture([host_arch]))
self.assertEqual(host_arch, solver.select_architecture(['foo', host_arch, 'bar']))
- def test_FirstSuccessfulSolveMighMissImplsDueToPackageDeps(self):
- self.override(packagekit, 'resolve', lambda names:
- dict([(i, {'name': i, 'pk_id': i, 'version': '0', 'arch': '*', 'installed': True}) for i in names]))
-
- self.touch(('Activities/1/activity/activity.info', [
- '[Activity]',
- 'name = name',
- 'bundle_id = bundle_id',
- 'exec = false',
- 'icon = icon',
- 'activity_version = 1',
- 'license = Public Domain',
- ]))
- self.touch(('Activities/2/activity/activity.info', [
- '[Activity]',
- 'name = name',
- 'bundle_id = bundle_id',
- 'exec = false',
- 'icon = icon',
- 'activity_version = 2',
- 'license = Public Domain',
- 'requires = dep',
- ]))
-
- home_volume = self.start_online_client()
- clones.populate(home_volume['context'], ['Activities'])
- ipc = IPCConnection()
-
- ipc.post(['context'], {
- 'guid': 'dep',
- 'type': 'package',
+ 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(['implementation'], {
+ 'context': context,
+ 'license': 'GPLv3+',
+ 'version': '1',
+ 'stability': 'stable',
+ 'notes': '',
+ })
+ self.node_volume['implementation'].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': [['dep.bin']],
+ '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']],
},
},
})
- solution = solver.solve(ipc, 'bundle_id', ['stable'])
- self.assertEqual(
- 2, len(solution))
- self.assertEqual(
- ('bundle_id', '2'),
- (solution[0]['context'], solution[0]['version']))
+ 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(
- ('dep', '0'),
- (solution[1]['context'], solution[1]['version']))
+ 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', 'command': ['echo'], 'context': context, 'guid': impl, 'stability': 'stable', 'license': ['GPLv3+']},
+ ]),
+ 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(['implementation'], {
+ 'context': context,
+ 'license': 'GPLv3+',
+ 'version': '1',
+ 'stability': 'stable',
+ 'notes': '',
+ })
+ self.node_volume['implementation'].update(impl, {'data': {
+ 'spec': {
+ '*-*': {
+ 'commands': {
+ 'activity': {
+ 'exec': 'echo',
+ },
+ },
+ 'requires': {
+ 'sugar': {},
+ },
+ },
+ },
+ }})
+ self.assertEqual([
+ {'version': '1', 'command': ['echo'], 'context': context, 'guid': impl, 'stability': 'stable', 'license': ['GPLv3+']},
+ {'version': '0.94', 'context': 'sugar', 'guid': 'sugar-0.94', 'stability': 'packaged', 'license': None},
+ ],
+ solver.solve(self.client_routes.fallback, context, ['stable']))
+
+ self.node_volume['implementation'].update(impl, {'data': {
+ 'spec': {
+ '*-*': {
+ 'commands': {
+ 'activity': {
+ 'exec': 'echo',
+ },
+ },
+ 'requires': {
+ 'sugar': {'restrictions': [['0.80', '0.87']]},
+ },
+ },
+ },
+ }})
+ self.assertEqual([
+ {'version': '1', 'command': ['echo'], 'context': context, 'guid': impl, 'stability': 'stable', 'license': ['GPLv3+']},
+ {'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(['implementation'], {
+ 'context': context,
+ 'license': 'GPLv3+',
+ 'version': '1',
+ 'stability': 'stable',
+ 'notes': '',
+ })
+ self.node_volume['implementation'].update(impl, {'data': {
+ 'spec': {
+ '*-*': {
+ 'commands': {
+ 'activity': {
+ 'exec': 'echo',
+ },
+ },
+ 'requires': {
+ 'sugar': {},
+ },
+ },
+ },
+ }})
+ self.assertEqual([
+ {'version': '1', 'command': ['echo'], 'context': context, 'guid': impl, 'stability': 'stable', 'license': ['GPLv3+']},
+ {'version': '0.94', 'context': 'sugar', 'guid': 'sugar-0.94', 'stability': 'packaged', 'license': None},
+ ],
+ solver.solve(self.client_routes.fallback, context, ['stable']))
if __name__ == '__main__':