def test_upload_file_with_timestamps(self): client = BoxClient("my_token") response = mocked_response({"entries": [{"id": "1"}]}) (flexmock(client).should_receive("_check_for_errors").once()) ( flexmock(requests) .should_receive("post") .with_args( "https://upload.box.com/api/2.0/files/content", { "parent_id": "666", "content_modified_at": "2007-05-04T03:02:01+00:00", "content_created_at": "2006-05-04T03:02:01+00:00", }, headers=client.default_headers, files={"hello.jpg": ("hello.jpg", FileObjMatcher("hello world"))}, ) .and_return(response) .once() ) result = client.upload_file( "hello.jpg", StringIO("hello world"), parent=666, content_created_at=datetime(2006, 5, 4, 3, 2, 1, 0, tzinfo=UTC()), content_modified_at=datetime(2007, 5, 4, 3, 2, 1, 0, tzinfo=UTC()), ) self.assertEqual({"id": "1"}, result)
def test_upload_file_with_parent_as_dict(self): client = BoxClient('my_token') (flexmock(client) .should_receive('_check_for_errors') .once()) response = mocked_response({'entries': [{'id': '1'}]}) (flexmock(requests) .should_receive('post') .with_args('https://upload.box.com/api/2.0/files/content', {'parent_id': '666'}, headers=client.default_headers, files={'hello.jpg': ('hello.jpg', FileObjMatcher('hello world'))}) .and_return(response) .once()) result = client.upload_file('hello.jpg', StringIO('hello world'), parent={'id': 666}) self.assertEqual({'id': '1'}, result)
def test_upload_file_with_parent_as_dict(self): client = BoxClient("my_token") (flexmock(client).should_receive("_check_for_errors").once()) response = mocked_response({"entries": [{"id": "1"}]}) ( flexmock(requests) .should_receive("post") .with_args( "https://upload.box.com/api/2.0/files/content", {"parent_id": "666"}, headers=client.default_headers, files={"hello.jpg": ("hello.jpg", FileObjMatcher("hello world"))}, ) .and_return(response) .once() ) result = client.upload_file("hello.jpg", StringIO("hello world"), parent={"id": 666}) self.assertEqual({"id": "1"}, result)
def test_upload_file_with_timestamps(self): client = BoxClient('my_token') response = mocked_response({'entries': [{'id': '1'}]}) (flexmock(client) .should_receive('_check_for_errors') .once()) (flexmock(requests) .should_receive('post') .with_args('https://upload.box.com/api/2.0/files/content', { 'parent_id': '666', 'content_modified_at': '2007-05-04T03:02:01+00:00', 'content_created_at': '2006-05-04T03:02:01+00:00' }, headers=client.default_headers, files={'hello.jpg': ('hello.jpg', FileObjMatcher('hello world'))}) .and_return(response) .once()) result = client.upload_file('hello.jpg', StringIO('hello world'), parent=666, content_created_at=datetime(2006, 5, 4, 3, 2, 1, 0, tzinfo=UTC()), content_modified_at=datetime(2007, 5, 4, 3, 2, 1, 0, tzinfo=UTC())) self.assertEqual({'id': '1'}, result)
from box import BoxClient from StringIO import StringIO code = 'h1J9HeATdM4DHKVHZDjZOH3J9ALfCuza' #response= {u'access_token': u'XnpOFtKpn2JUmAOPwKtUyzunZ0mOQAJt', u'restricted_to': [], u'expires_in': 4072, u'refresh_token': u'7PNqFf1Bmv6uM0zkoTxnFh3UOqYs2qIoLvGe04hlhDv76fDqI4n4JqRo0V8R53NY', u'token_type': u'bearer'} #response= {u'access_token': u'VVeRMPOXltFoSWAckvADXTwQyrZsc906', u'restricted_to': [], u'token_type': u'bearer', u'expires_in': 4040, u'refresh_token': u'y5KyiuQstgWdEZsYifALo13EH5x7j5HGxBVlXOnIy6kfeKHSLsMTyA1MC4a5zfdP'} response = { u'access_token': u'rDMonxdCPfhJMAGU7qIA1QPEZf0tlnS8', u'restricted_to': [], u'token_type': u'bearer', u'expires_in': 3722, u'refresh_token': u'pCGF1OO4zsEGoAjXeAftqMLin250LeXqwpcL0caTcvGcmVy3TJq3Twxqo5SrSxf6' } client = BoxClient(response['access_token']) metadata = client.upload_file('fuckyou.txt', StringIO('hello world')) print metadata '''{u'shared_link': None, u'sha1': u'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', u'modified_by': {u'login': u'*****@*****.**', u'type': u'user', u'id': u'216264056', u'name': u'Siddhanth Gupta'}, u'name': u'fuckyou.txt', u'parent': {u'sequence_id': None, u'etag': None, u'type': u'folder', u'id': u'0', u'name': u'All Files'}, u'purged_at': None, u'trashed_at': None, u'created_at': u'2014-06-28T13:56:35-07:00', u'modified_at': u'2014-06-28T13:56:35-07:00', u'item_status': u'active', u'created_by': {u'login': u'*****@*****.**', u'type': u'user', u'id': u'216264056', u'name': u'Siddhanth Gupta'}, u'content_modified_at': u'2014-06-28T13:56:35-07:00', u'sequence_id': u'0', u'etag': u'0', u'owned_by': {u'login': u'*****@*****.**', u'type': u'user', u'id': u'216264056', u'name': u'Siddhanth Gupta'}, u'path_collection': {u'total_count': 1, u'entries': [{u'sequence_id': None, u'etag': None, u'type': u'folder', u'id': u'0', u'name': u'All Files'}]}, u'size': 11, u'type': u'file', u'id': u'18532645558', u'content_created_at': u'2014-06-28T13:56:35-07:00', u'description': u''} '''
from box import BoxClient from StringIO import StringIO response = { u'access_token': u'VVeRMPOXltFoSWAckvADXTwQyrZsc906', u'restricted_to': [], u'token_type': u'bearer', u'expires_in': 4040, u'refresh_token': u'y5KyiuQstgWdEZsYifALo13EH5x7j5HGxBVlXOnIy6kfeKHSLsMTyA1MC4a5zfdP' } client = BoxClient(response['access_token']) client.upload_file('shit.txt', StringIO('f**k the world'))
from box import BoxClient from StringIO import StringIO code='h1J9HeATdM4DHKVHZDjZOH3J9ALfCuza' #response= {u'access_token': u'XnpOFtKpn2JUmAOPwKtUyzunZ0mOQAJt', u'restricted_to': [], u'expires_in': 4072, u'refresh_token': u'7PNqFf1Bmv6uM0zkoTxnFh3UOqYs2qIoLvGe04hlhDv76fDqI4n4JqRo0V8R53NY', u'token_type': u'bearer'} #response= {u'access_token': u'VVeRMPOXltFoSWAckvADXTwQyrZsc906', u'restricted_to': [], u'token_type': u'bearer', u'expires_in': 4040, u'refresh_token': u'y5KyiuQstgWdEZsYifALo13EH5x7j5HGxBVlXOnIy6kfeKHSLsMTyA1MC4a5zfdP'} response={u'access_token': u'rDMonxdCPfhJMAGU7qIA1QPEZf0tlnS8', u'restricted_to': [], u'token_type': u'bearer', u'expires_in': 3722, u'refresh_token': u'pCGF1OO4zsEGoAjXeAftqMLin250LeXqwpcL0caTcvGcmVy3TJq3Twxqo5SrSxf6'} client = BoxClient(response['access_token']) metadata=client.upload_file('fuckyou.txt', StringIO('hello world')) print metadata '''{u'shared_link': None, u'sha1': u'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', u'modified_by': {u'login': u'*****@*****.**', u'type': u'user', u'id': u'216264056', u'name': u'Siddhanth Gupta'}, u'name': u'fuckyou.txt', u'parent': {u'sequence_id': None, u'etag': None, u'type': u'folder', u'id': u'0', u'name': u'All Files'}, u'purged_at': None, u'trashed_at': None, u'created_at': u'2014-06-28T13:56:35-07:00', u'modified_at': u'2014-06-28T13:56:35-07:00', u'item_status': u'active', u'created_by': {u'login': u'*****@*****.**', u'type': u'user', u'id': u'216264056', u'name': u'Siddhanth Gupta'}, u'content_modified_at': u'2014-06-28T13:56:35-07:00', u'sequence_id': u'0', u'etag': u'0', u'owned_by': {u'login': u'*****@*****.**', u'type': u'user', u'id': u'216264056', u'name': u'Siddhanth Gupta'}, u'path_collection': {u'total_count': 1, u'entries': [{u'sequence_id': None, u'etag': None, u'type': u'folder', u'id': u'0', u'name': u'All Files'}]}, u'size': 11, u'type': u'file', u'id': u'18532645558', u'content_created_at': u'2014-06-28T13:56:35-07:00', u'description': u''} '''
from box import BoxClient from StringIO import StringIO response= {u'access_token': u'VVeRMPOXltFoSWAckvADXTwQyrZsc906', u'restricted_to': [], u'token_type': u'bearer', u'expires_in': 4040, u'refresh_token': u'y5KyiuQstgWdEZsYifALo13EH5x7j5HGxBVlXOnIy6kfeKHSLsMTyA1MC4a5zfdP'} client = BoxClient(response['access_token']) client.upload_file('shit.txt', StringIO('f**k the world'))