[ARVADOS] updated: 446785a11237f832e9bac540a04e7dd238b45a9e

git at public.curoverse.com git at public.curoverse.com
Mon Feb 16 11:30:36 EST 2015


Summary of changes:
 sdk/python/tests/arvados_testutil.py |  4 ++++
 sdk/python/tests/test_collections.py | 11 +++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

       via  446785a11237f832e9bac540a04e7dd238b45a9e (commit)
      from  f22dda84271714c924c322bafba5e9f184e4fb33 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 446785a11237f832e9bac540a04e7dd238b45a9e
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Mon Feb 16 11:32:47 2015 -0500

    4823: Notes on how the mocking works with requests.Session

diff --git a/sdk/python/tests/arvados_testutil.py b/sdk/python/tests/arvados_testutil.py
index 2926b20..49ed79c 100644
--- a/sdk/python/tests/arvados_testutil.py
+++ b/sdk/python/tests/arvados_testutil.py
@@ -53,6 +53,10 @@ def fake_requests_response(code, body, **headers):
     r.raw = io.BytesIO(body)
     return r
 
+# The following methods patch requests.Session(), where return_value is a mock
+# Session object.  The put/get attributes are set on mock Session, and the
+# desired put/get behavior is set on the put/get mocks.
+
 def mock_put_responses(body, *codes, **headers):
     m = mock.MagicMock()
     if isinstance(body, tuple):
diff --git a/sdk/python/tests/test_collections.py b/sdk/python/tests/test_collections.py
index 8e513c6..fbec8b2 100644
--- a/sdk/python/tests/test_collections.py
+++ b/sdk/python/tests/test_collections.py
@@ -710,23 +710,26 @@ class CollectionWriterTestCase(unittest.TestCase, CollectionTestMixin):
 
     def test_write_insufficient_replicas_via_disks(self):
         client = mock.MagicMock(name='api_client')
-        self.mock_keep_services(client, status=200, service_type='disk', count=2)
-        writer = self.foo_writer(api_client=client, replication=3)
         with self.mock_keep(
                 None, 200, 200,
                 **{'x-keep-replicas-stored': 1}) as keepmock:
+            self.mock_keep_services(client, status=200, service_type='disk', count=2)
+            writer = self.foo_writer(api_client=client, replication=3)
             with self.assertRaises(arvados.errors.KeepWriteError):
                 writer.manifest_text()
 
     def test_write_three_replicas(self):
         client = mock.MagicMock(name='api_client')
-        self.mock_keep_services(client, status=200, service_type='disk', count=6)
         with self.mock_keep(
                 None, 500, 500, 500, 200, 200, 200,
                 **{'x-keep-replicas-stored': 1}) as keepmock:
+            self.mock_keep_services(client, status=200, service_type='disk', count=6)
             writer = self.foo_writer(api_client=client, replication=3)
             writer.manifest_text()
-            self.assertEqual(6, keepmock.call_count)
+            # keepmock is the mock session constructor; keepmock.return_value
+            # is the mock session object, and keepmock.return_value.put is the
+            # actual mock method of interest.
+            self.assertEqual(6, keepmock.return_value.put.call_count)
 
     def test_write_whole_collection_through_retries(self):
         writer = self.foo_writer(num_retries=2)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list