Skip to content

Instantly share code, notes, and snippets.

@winstonewert
Forked from davidkazuhiro/output
Created December 13, 2018 23:03
Show Gist options
  • Save winstonewert/fbf32a1a35f9c9e1011a34eb5396cd60 to your computer and use it in GitHub Desktop.
Save winstonewert/fbf32a1a35f9c9e1011a34eb5396cd60 to your computer and use it in GitHub Desktop.
start
test_mock (test_upload.UploaderTest) ... FAIL
NoneType: None
======================================================================
FAIL: test_mock (test_upload.UploaderTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/mock.py", line 1191, in patched
return func(*args, **keywargs)
File "/Users/david.somers-harris/git/ghe/ghe/costallocator/test_upload.py", line 19, in test_mock
self.assertIsInstance(self.uploader.client, unittest.mock.Mock)
AssertionError: <boxsdk.client.client.Client object at 0x1032f1a20> is not an instance of <class 'unittest.mock.Mock'>
----------------------------------------------------------------------
Ran 1 test in 0.004s
FAILED (failures=1)
import io
import unittest
from unittest.mock import patch
import boxsdk
import upload
class UploaderTest(unittest.TestCase):
def setUp(self):
self.patcher = patch('boxsdk.Client')
self.mock_client = self.patcher.start()
self.uploader = upload.Uploader('fake_client_id', 'fake_client_secret', 'fake_token')
def tearDown(self):
self.patcher.stop()
@patch('boxsdk.Client')
def test_mock(self, MockClient):
self.assertIsInstance(self.uploader.client, unittest.mock.Mock)
""" @patch('boxsdk.Client')
def test_auth(self, MockClient):
self.assertIsInstance(self.uploader.client, boxsdk.Client)
@patch('boxsdk.Client')
def test_upload(self, MockClient):
#MockClient.return_value.folder.return_value.upload_stream.return_value =
stream = io.StringIO('test')
boxfile = self.uploader.upload(stream, 'test.txt', '60844312510')
self.assertIsInstance(boxfile, boxsdk.object.file.File)
"""
import boxsdk
from boxsdk import Client, OAuth2
class Uploader:
def __init__(self, box_client_id, box_client_secret, box_token):
oauth2 = OAuth2(box_client_id,
box_client_secret,
access_token=box_token)
self.client = Client(oauth2)
def upload(self, stream, filename, folder):
return self.client.folder(folder).upload_stream(stream, filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment