Created
December 13, 2018 12:03
-
-
Save davidkazuhiro/1f4e185ba74c95e90617a766640c2683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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