def test_upload_from_filename(self):
    from google.cloud._testing import _NamedTemporaryFile
    blob = self._make_one('blob-name', bucket=None)
    created_json = {'metadata': {'mint': 'ice-cream'}}
    blob._do_upload = mock.Mock(return_value=created_json, spec=[])
    self.assertIsNone(blob.metadata)
    data = b'soooo much data'
    content_type = u'image/svg+xml'
    client = mock.sentinel.client
    with _NamedTemporaryFile() as temp:
        with open(temp.name, 'wb') as file_obj:
            file_obj.write(data)
        ret_val = blob.upload_from_filename(temp.name, content_type=content_type, client=client)
    self.assertIsNone(ret_val)
    self.assertEqual(blob.metadata, created_json['metadata'])
    stream = self._do_upload_mock_call_helper(blob, client, content_type, len(data))
    self.assertTrue(stream.closed)
    self.assertEqual(stream.mode, 'rb')
    self.assertEqual(stream.name, temp.name)
def test_upload_from_filename(self):
    from google.cloud._testing import _NamedTemporaryFile
    blob = self._make_one('blob-name', bucket=None)
    created_json = {'metadata': {'mint': 'ice-cream'}}
    blob._do_upload = mock.Mock(return_value=created_json, spec=[])
    self.assertIsNone(blob.metadata)
    data = b'soooo much data'
    content_type = u'image/svg+xml'
    client = mock.sentinel.client
    with _NamedTemporaryFile() as temp:
        with open(temp.name, 'wb') as file_obj:
            file_obj.write(data)
        ret_val = blob.upload_from_filename(temp.name, content_type=content_type, client=client)
    self.assertIsNone(ret_val)
    self.assertEqual(blob.metadata, created_json['metadata'])
    stream = self._do_upload_mock_call_helper(blob, client, content_type, len(data))
    self.assertTrue(stream.closed)
    self.assertEqual(stream.mode, 'rb')
    self.assertEqual(stream.name, temp.name)