コード例 #1
0
 def test_upload_function_zip(self, get_conn, requests_put):
     mck, open_module = get_open_mock()
     with mock.patch('{}.open'.format(open_module), mck):
         generate_upload_url_method = get_conn.return_value.projects.return_value.locations. \
             return_value.functions.return_value.generateUploadUrl
         execute_method = generate_upload_url_method.return_value.execute
         execute_method.return_value = {"uploadUrl": "http://uploadHere"}
         requests_put.return_value = None
         res = self.gcf_function_hook.upload_function_zip(
             location=GCF_LOCATION, zip_path="/tmp/path.zip")
         self.assertEqual("http://uploadHere", res)
         generate_upload_url_method.assert_called_once_with(
             parent='projects/example-project/locations/location')
         execute_method.assert_called_once_with(num_retries=5)
         requests_put.assert_called_once_with(
             data=mock.ANY,
             headers={
                 'Content-type': 'application/zip',
                 'x-goog-content-length-range': '0,104857600'
             },
             url='http://uploadHere')
コード例 #2
0
 def test_upload_function_zip(self, get_conn, requests_put):
     m, open_module = get_open_mock()
     with mock.patch('{}.open'.format(open_module), m):
         generate_upload_url_method = get_conn.return_value.projects.return_value.locations. \
             return_value.functions.return_value.generateUploadUrl
         execute_method = generate_upload_url_method.return_value.execute
         execute_method.return_value = {"uploadUrl": "http://uploadHere"}
         requests_put.return_value = None
         res = self.gcf_function_hook.upload_function_zip(
             location=GCF_LOCATION,
             zip_path="/tmp/path.zip"
         )
         self.assertEqual("http://uploadHere", res)
         generate_upload_url_method.assert_called_with(
             parent='projects/example-project/locations/location')
         execute_method.assert_called_once_with(num_retries=5)
         requests_put.assert_called_once_with(
             data=mock.ANY,
             headers={'Content-type': 'application/zip',
                      'x-goog-content-length-range': '0,104857600'},
             url='http://uploadHere'
         )