コード例 #1
0
 def test__connection_getter_with_batch(self):
     from google.cloud.storage.batch import Batch
     PROJECT = 'PROJECT'
     CREDENTIALS = _make_credentials()
     client = self._make_one(project=PROJECT, credentials=CREDENTIALS)
     batch = Batch(client)
     client._push_batch(batch)
     self.assertIsNot(client._connection, client._base_connection)
     self.assertIs(client._connection, batch)
     self.assertIs(client.current_batch, batch)
コード例 #2
0
 def test_connection_getter_with_batch(self):
     from google.cloud.storage.batch import Batch
     PROJECT = 'PROJECT'
     CREDENTIALS = _Credentials()
     client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
     batch = Batch(client)
     client._push_batch(batch)
     self.assertTrue(client.connection is not client._connection)
     self.assertTrue(client.connection is batch)
     self.assertTrue(client.current_batch is batch)
コード例 #3
0
    def test__push_batch_and__pop_batch(self):
        from google.cloud.storage.batch import Batch

        PROJECT = 'PROJECT'
        CREDENTIALS = _make_credentials()

        client = self._make_one(project=PROJECT, credentials=CREDENTIALS)
        batch1 = Batch(client)
        batch2 = Batch(client)
        client._push_batch(batch1)
        self.assertEqual(list(client._batch_stack), [batch1])
        self.assertIs(client.current_batch, batch1)
        client._push_batch(batch2)
        self.assertIs(client.current_batch, batch2)
        # list(_LocalStack) returns in reverse order.
        self.assertEqual(list(client._batch_stack), [batch2, batch1])
        self.assertIs(client._pop_batch(), batch2)
        self.assertEqual(list(client._batch_stack), [batch1])
        self.assertIs(client._pop_batch(), batch1)
        self.assertEqual(list(client._batch_stack), [])
コード例 #4
0
    def batch(self):
        """Factory constructor for batch object.

        .. note::
          This will not make an HTTP request; it simply instantiates
          a batch object owned by this client.

        :rtype: :class:`google.cloud.storage.batch.Batch`
        :returns: The batch object created.
        """
        return Batch(client=self)
コード例 #5
0
    def test_duplicate_user_agent(self):
        # Regression test for issue #565
        from google.cloud._http import ClientInfo
        from google.cloud.storage.batch import Batch
        from google.cloud.storage import __version__

        client_info = ClientInfo(user_agent="test/123")
        conn = self._make_one(object(), client_info=client_info)
        expected_user_agent = "test/123 gcloud-python/{} ".format(__version__)
        self.assertEqual(conn._client_info.user_agent, expected_user_agent)

        client = mock.Mock(_connection=conn, spec=["_connection"])
        batch = Batch(client)
        self.assertEqual(batch._client_info.user_agent, expected_user_agent)