Description: Batched fixes to everything that was mock-broken
 This patch contains a collection of cherry-picked fixes to various parts
 of plainbox that were just silently broken because of mock's ignorance
 of non-existing assertion methods.
Origin: upstream
Forwarded: not-needed
Last-Update: 2015-09-02

--- plainbox-0.22.2.orig/plainbox/impl/secure/test_plugins.py
+++ plainbox-0.22.2/plainbox/impl/secure/test_plugins.py
@@ -123,7 +123,7 @@ class PlugInCollectionBaseTests(TestCase
         passed to the initializer.
         """
         col = DummyPlugInCollection(load=True)
-        col.load.assert_called()
+        col.load.assert_called_once_with()
 
     def test_defaults(self):
         """
@@ -329,7 +329,7 @@ class PkgResourcesPlugInCollectionTests(
         # Load plugins
         self.col.load()
         # Ensure that pkg_resources were interrogated
-        mock_iter.assert_calledwith(self._NAMESPACE)
+        mock_iter.assert_called_with(self._NAMESPACE)
         # Ensure that both entry points were loaded
         mock_ep1.load.assert_called_with()
         mock_ep2.load.assert_called_with()
@@ -350,7 +350,7 @@ class PkgResourcesPlugInCollectionTests(
         # Load plugins
         self.col.load()
         # Ensure that pkg_resources were interrogated
-        mock_iter.assert_calledwith(self._NAMESPACE)
+        mock_iter.assert_called_with(self._NAMESPACE)
         # Ensure that both entry points were loaded
         mock_ep1.load.assert_called_with()
         mock_ep2.load.assert_called_with()
@@ -514,7 +514,7 @@ class FsPlugInCollectionTests(TestCase):
                  {'encoding': 'UTF-8'}),
             ])
         # Ensure that no exception was logged
-        mock_logger.error.assert_not_called()
+        self.assertEqual(mock_logger.error.mock_calls, [])
         # Ensure that everything was okay
         self.assertEqual(col.problem_list, [])
         # Ensure that both files got added
--- plainbox-0.22.2.orig/plainbox/impl/session/test_resume.py
+++ plainbox-0.22.2/plainbox/impl/session/test_resume.py
@@ -117,53 +117,101 @@ class SessionResumeExceptionTests(TestCa
 
 class SessionResumeHelperTests(TestCase):
 
-    @mock.patch('plainbox.impl.session.resume.SessionResumeHelper1')
-    def test_resume_dispatch_v1(self, mocked_helper1):
-        data = gzip.compress(
-            b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
-            b'{"app_blob":null,"flags":[],"running_job_name":null,"title":null'
-            b'},"results":{}},"version":1}')
-        SessionResumeHelper([], None, None).resume(data)
-        mocked_helper1.resume_json.assert_called_once()
-
-    @mock.patch('plainbox.impl.session.resume.SessionResumeHelper2')
-    def test_resume_dispatch_v2(self, mocked_helper2):
-        data = gzip.compress(
-            b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
-            b'{"app_blob":null,"flags":[],"running_job_name":null,"title":null'
-            b'},"results":{}},"version":2}')
-        SessionResumeHelper([], None, None).resume(data)
-        mocked_helper2.resume_json.assert_called_once()
-
-    @mock.patch('plainbox.impl.session.resume.SessionResumeHelper3')
-    def test_resume_dispatch_v3(self, mocked_helper3):
-        data = gzip.compress(
-            b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
-            b'{"app_blob":null,"app_id":null,"flags":[],'
-            b'"running_job_name":null,"title":null'
-            b'},"results":{}},"version":3}')
-        SessionResumeHelper([], None, None).resume(data)
-        mocked_helper3.resume_json.assert_called_once()
-
-    @mock.patch('plainbox.impl.session.resume.SessionResumeHelper4')
-    def test_resume_dispatch_v4(self, mocked_helper4):
-        data = gzip.compress(
-            b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
-            b'{"app_blob":null,"app_id":null,"flags":[],'
-            b'"running_job_name":null,"title":null'
-            b'},"results":{}},"version":4}')
-        SessionResumeHelper([], None, None).resume(data)
-        mocked_helper4.resume_json.assert_called_once()
-
-    @mock.patch('plainbox.impl.session.resume.SessionResumeHelper5')
-    def test_resume_dispatch_v5(self, mocked_helper5):
-        data = gzip.compress(
-            b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
-            b'{"app_blob":null,"app_id":null,"flags":[],'
-            b'"running_job_name":null,"title":null'
-            b'},"results":{}},"version":5}')
-        SessionResumeHelper([], None, None).resume(data)
-        mocked_helper5.resume_json.assert_called_once()
+    def test_resume_dispatch_v1(self):
+        helper1 = SessionResumeHelper1
+        with mock.patch.object(helper1, 'resume_json'):
+            data = gzip.compress(
+                b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
+                b'{"app_blob":null,"flags":[],"running_job_name":null,'
+                b'"title":null},"results":{}},"version":1}')
+            SessionResumeHelper([], None, None).resume(data)
+            helper1.resume_json.assert_called_once_with(
+                {'session': {'jobs': {},
+                             'metadata': {'title': None,
+                                          'running_job_name': None,
+                                          'app_blob': None,
+                                          'flags': []},
+                             'desired_job_list': [],
+                             'results': {}},
+                 'version': 1}, None)
+
+    def test_resume_dispatch_v2(self):
+        helper2 = SessionResumeHelper2
+        with mock.patch.object(helper2, 'resume_json'):
+            data = gzip.compress(
+                b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
+                b'{"app_blob":null,"flags":[],"running_job_name":null,'
+                b'"title":null},"results":{}},"version":2}')
+            SessionResumeHelper([], None, None).resume(data)
+            helper2.resume_json.assert_called_once_with(
+                {'session': {'jobs': {},
+                             'metadata': {'title': None,
+                                          'running_job_name': None,
+                                          'app_blob': None,
+                                          'flags': []},
+                             'desired_job_list': [],
+                             'results': {}},
+                 'version': 2}, None)
+
+    def test_resume_dispatch_v3(self):
+        helper3 = SessionResumeHelper3
+        with mock.patch.object(helper3, 'resume_json'):
+            data = gzip.compress(
+                b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
+                b'{"app_blob":null,"app_id":null,"flags":[],'
+                b'"running_job_name":null,"title":null'
+                b'},"results":{}},"version":3}')
+            SessionResumeHelper([], None, None).resume(data)
+            helper3.resume_json.assert_called_once_with(
+                {'session': {'jobs': {},
+                             'metadata': {'title': None,
+                                          'app_id': None,
+                                          'running_job_name': None,
+                                          'app_blob': None,
+                                          'flags': []},
+                             'desired_job_list': [],
+                             'results': {}},
+                 'version': 3}, None)
+
+    def test_resume_dispatch_v4(self):
+        helper4 = SessionResumeHelper4
+        with mock.patch.object(helper4, 'resume_json'):
+            data = gzip.compress(
+                b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
+                b'{"app_blob":null,"app_id":null,"flags":[],'
+                b'"running_job_name":null,"title":null'
+                b'},"results":{}},"version":4}')
+            SessionResumeHelper([], None, None).resume(data)
+            helper4.resume_json.assert_called_once_with(
+                {'session': {'jobs': {},
+                             'metadata': {'title': None,
+                                          'app_id': None,
+                                          'running_job_name': None,
+                                          'app_blob': None,
+                                          'flags': []},
+                             'desired_job_list': [],
+                             'results': {}},
+                 'version': 4}, None)
+
+    def test_resume_dispatch_v5(self):
+        helper5 = SessionResumeHelper5
+        with mock.patch.object(helper5, 'resume_json'):
+            data = gzip.compress(
+                b'{"session":{"desired_job_list":[],"jobs":{},"metadata":'
+                b'{"app_blob":null,"app_id":null,"flags":[],'
+                b'"running_job_name":null,"title":null'
+                b'},"results":{}},"version":5}')
+            SessionResumeHelper([], None, None).resume(data)
+            helper5.resume_json.assert_called_once_with(
+                {'session': {'jobs': {},
+                             'metadata': {'title': None,
+                                          'app_id': None,
+                                          'running_job_name': None,
+                                          'app_blob': None,
+                                          'flags': []},
+                             'desired_job_list': [],
+                             'results': {}},
+                 'version': 5}, None)
 
     def test_resume_dispatch_v6(self):
         data = gzip.compress(
--- plainbox-0.22.2.orig/plainbox/impl/session/test_state.py
+++ plainbox-0.22.2/plainbox/impl/session/test_state.py
@@ -994,7 +994,7 @@ class SessionDeviceContextTests(SignalTe
         with mock.patch.object(self.ctx, '_compute_execution_ctrl_list') as m:
             result = self.ctx.execution_controller_list
         self.assertIs(result, m())
-        m.assert_called_once()
+        m.assert_any_call()
 
     def test_execution_controller_list__cached(self):
         """
@@ -1007,7 +1007,7 @@ class SessionDeviceContextTests(SignalTe
             result1 = self.ctx.execution_controller_list
             result2 = self.ctx.execution_controller_list
         self.assertIs(result1, result2)
-        m.assert_called_once()
+        m.assert_any_call()
         self.assertIn(
             SessionDeviceContext._CACHE_EXECUTION_CTRL_LIST,
             self.ctx._shared_cache)
--- plainbox-0.22.2.orig/plainbox/impl/test_ctrl.py
+++ plainbox-0.22.2/plainbox/impl/test_ctrl.py
@@ -226,7 +226,7 @@ class CheckBoxSessionStateControllerTest
         self.assertIs(
             session_state.job_state_map[job.id].result, result)
         # Ensure that signals got fired
-        session_state.on_job_state_map_changed.assert_called_once()
+        session_state.on_job_state_map_changed.assert_called_once_with()
         session_state.on_job_result_changed.assert_called_once_with(
             job, result)
 
--- plainbox-0.22.2.orig/plainbox/impl/test_pod.py
+++ plainbox-0.22.2/plainbox/impl/test_pod.py
@@ -249,8 +249,8 @@ class FieldCollectionTests(TestCase):
         """.inspect_namespace() calls add_field() on each Field."""
         with mock.patch.object(self.fc, 'add_field') as mock_add_field:
             self.fc.inspect_namespace(self.ns, 'cls')
-        mock_add_field.assert_has_call(self.foo, 'cls')
-        mock_add_field.assert_has_call(self.bar, 'cls')
+            calls = [mock.call(self.foo, 'cls'), mock.call(self.bar, 'cls')]
+            mock_add_field.assert_has_calls(calls, any_order=True)
 
     def test_inspect_namespace_sets_field_name(self):
         """.inspect_namespace() sets .name of each field."""
