Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(77)

Unified Diff: server/guiserver/tests/bundles/test_base.py

Issue 26740043: After deploying a bundle increment counter.
Patch Set: After deploying a bundle increment counter. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « server/guiserver/manage.py ('k') | server/guiserver/tests/bundles/test_utils.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/guiserver/tests/bundles/test_base.py
=== modified file 'server/guiserver/tests/bundles/test_base.py'
--- server/guiserver/tests/bundles/test_base.py 2013-11-07 17:27:20 +0000
+++ server/guiserver/tests/bundles/test_base.py 2013-11-15 18:31:05 +0000
@@ -42,6 +42,18 @@
raise jujuclient.EnvError({'Error': 'bad wolf'})
+class FakeFuture(object):
+ def __init__(self, cancelled=False, exception=None):
+ self._cancelled = cancelled
+ self._exception = exception
+
+ def cancelled(self):
+ return self._cancelled
+
+ def exception(self):
+ return self._exception
+
+
@mock.patch('time.time', mock.Mock(return_value=42))
class TestDeployer(helpers.BundlesTestMixin, AsyncTestCase):
@@ -108,7 +120,8 @@
deployer = self.make_deployer()
with self.patch_import_bundle():
deployment_id = deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
self.assertIsInstance(deployment_id, int)
# Wait for the deployment to be completed.
self.wait()
@@ -118,7 +131,8 @@
deployer = self.make_deployer()
with self.patch_import_bundle() as mock_import_bundle:
deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
# Wait for the deployment to be completed.
self.wait()
mock_import_bundle.assert_called_once_with(
@@ -140,7 +154,8 @@
deployer = self.make_deployer()
with self.patch_import_bundle():
deployment_id = deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
watcher_id = deployer.watch(deployment_id)
self.assertIsInstance(watcher_id, int)
# Wait for the deployment to be completed.
@@ -157,7 +172,8 @@
deployer = self.make_deployer()
with self.patch_import_bundle():
deployment_id = deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
watcher_id = deployer.watch(deployment_id)
# A first change is received notifying that the deployment is started.
changes = yield deployer.next(watcher_id)
@@ -178,9 +194,10 @@
deployer = self.make_deployer()
with self.patch_import_bundle():
deployment1 = deployer.import_bundle(
- self.user, 'bundle', self.bundle)
+ self.user, 'bundle', self.bundle, bundle_id=None)
deployment2 = deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
watcher1 = deployer.watch(deployment1)
watcher2 = deployer.watch(deployment2)
# The first deployment is started.
@@ -205,7 +222,8 @@
deployer = self.make_deployer()
with self.patch_import_bundle(side_effect=RuntimeError('bad wolf')):
deployment_id = deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
watcher_id = deployer.watch(deployment_id)
# We expect two changes: the second one should include the error.
yield deployer.next(watcher_id)
@@ -222,7 +240,8 @@
import_bundle_path = 'guiserver.bundles.base.blocking.import_bundle'
with mock.patch(import_bundle_path, import_bundle_mock):
deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
# Wait for the deployment to be completed.
self.wait()
status = deployer.status()
@@ -249,9 +268,10 @@
# The test callback is passed to the first deployment because we
# expect the second one to be immediately cancelled.
deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
deployment_id = deployer.import_bundle(
- self.user, 'bundle', self.bundle)
+ self.user, 'bundle', self.bundle, bundle_id=None)
watcher_id = deployer.watch(deployment_id)
self.assertIsNone(deployer.cancel(deployment_id))
# We expect two changes: the second one should notify the deployment
@@ -274,7 +294,8 @@
deployer = self.make_deployer()
with self.patch_import_bundle():
deployment_id = deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
watcher_id = deployer.watch(deployment_id)
# Assume the deployment is completed after two changes.
yield deployer.next(watcher_id)
@@ -291,7 +312,8 @@
deployer = self.make_deployer()
with self.patch_import_bundle() as mock_import_bundle:
deployment_id = deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
watcher_id = deployer.watch(deployment_id)
# Wait until the deployment is started.
yield deployer.next(watcher_id)
@@ -314,9 +336,10 @@
deployer = self.make_deployer()
with self.patch_import_bundle():
deployment1 = deployer.import_bundle(
- self.user, 'bundle', self.bundle)
+ self.user, 'bundle', self.bundle, bundle_id=None)
deployment2 = deployer.import_bundle(
- self.user, 'bundle', self.bundle, test_callback=self.stop)
+ self.user, 'bundle', self.bundle, bundle_id=None,
+ test_callback=self.stop)
# Wait for the deployment to be completed.
self.wait()
# At this point we expect two completed deployments.
@@ -326,6 +349,64 @@
self.assertEqual(deployment1, change1['DeploymentId'])
self.assertEqual(deployment2, change2['DeploymentId'])
+ def test_import_callback_cancelled(self):
+ deployer = self.make_deployer()
+ deployer_id = 123
+ deployer._queue.append(deployer_id)
+ deployer._futures[deployer_id] = None
+ mock_path = 'guiserver.bundles.utils.increment_deployment_counter'
+ future = FakeFuture(True)
+ with mock.patch.object(
+ deployer._observer, 'notify_cancelled') as mock_notify:
+ with mock.patch(mock_path) as mock_incrementer:
+ deployer._import_callback(deployer_id, None, future)
+ mock_notify.assert_called_with(deployer_id)
+ self.assertFalse(mock_incrementer.called)
+
+ def test_import_callback_error(self):
+ deployer = self.make_deployer()
+ deployer_id = 123
+ deployer._queue.append(deployer_id)
+ deployer._futures[deployer_id] = None
+ mock_path = 'guiserver.bundles.utils.increment_deployment_counter'
+ future = FakeFuture(exception='aiiee')
+ with mock.patch.object(
+ deployer._observer, 'notify_completed') as mock_notify:
+ with mock.patch(mock_path) as mock_incrementer:
+ deployer._import_callback(deployer_id, None, future)
+ mock_notify.assert_called_with(deployer_id, error='aiiee')
+ self.assertFalse(mock_incrementer.called)
+
+ def test_import_callback_no_bundleid(self):
+ deployer = self.make_deployer()
+ deployer_id = 123
+ deployer._queue.append(deployer_id)
+ deployer._futures[deployer_id] = None
+ mock_path = 'guiserver.bundles.utils.increment_deployment_counter'
+ future = FakeFuture()
+ with mock.patch.object(
+ deployer._observer, 'notify_completed') as mock_notify:
+ with mock.patch(mock_path) as mock_incrementer:
+ deployer._import_callback(deployer_id, None, future)
+ mock_notify.assert_called_with(deployer_id, error=None)
+ self.assertFalse(mock_incrementer.called)
+
+ def test_import_callback_success(self):
+ deployer = self.make_deployer()
+ deployer_id = 123
+ bundle_id = '~jorge/basket/bundle'
+ deployer._charmworldurl = 'http://cw.example.com'
+ deployer._queue.append(deployer_id)
+ deployer._futures[deployer_id] = None
+ mock_path = 'guiserver.bundles.utils.increment_deployment_counter'
+ future = FakeFuture()
+ with mock.patch.object(
+ deployer._observer, 'notify_completed') as mock_notify:
+ with mock.patch(mock_path) as mock_incrementer:
+ deployer._import_callback(deployer_id, bundle_id, future)
+ mock_notify.assert_called_with(deployer_id, error=None)
+ mock_incrementer.assert_called_with(bundle_id, deployer._charmworldurl)
+
class TestDeployMiddleware(helpers.BundlesTestMixin, AsyncTestCase):
« no previous file with comments | « server/guiserver/manage.py ('k') | server/guiserver/tests/bundles/test_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b