def test_finish_authenticate_v2(self): args = { 'client_id': '111', 'client_secret': '222', 'code': '333', 'grant_type': 'authorization_code', } flexmock(requests)\ .should_receive('post')\ .with_args('https://www.box.com/api/oauth2/token', args)\ .and_return(flexmock(json=lambda: {'aaa': 'bbb'}))\ .once() result = finish_authenticate_v2('111', '222', '333') self.assertDictEqual({'aaa': 'bbb'}, result) flexmock(requests)\ .should_receive('post')\ .with_args('https://www.box.com/api/oauth2/token', args)\ .and_return(flexmock(json=lambda: {'aaa': 'bbb'}))\ .once() result = finish_authenticate_v2('111', '222', {'bla': 'ba', 'code': '333'}) self.assertDictEqual({'aaa': 'bbb'}, result) flexmock(box.client)\ .should_receive('_oauth2_token_request')\ .never()
def test_test_finish_authenticate_v2_dict_with_error(self): with self.assertRaises(BoxAuthenticationException) as expected_exception: result = finish_authenticate_v2('111', '222', {'error': 'some_error', 'code': '333', 'error_description': 'foobar'}) self.assertDictEqual({'aaa': 'bbb'}, result) self.assertEqual('foobar', expected_exception.exception.message) self.assertEqual('some_error', expected_exception.exception.error)
def test_finish_authenticate_v2(self): args = { 'client_id': '111', 'client_secret': '222', 'code': '333', 'grant_type': 'authorization_code', } flexmock(requests)\ .should_receive('post')\ .with_args('https://www.box.com/api/oauth2/token', args)\ .and_return(flexmock(json=lambda: {'aaa': 'bbb'}))\ .once() result = finish_authenticate_v2('111', '222', '333') self.assertDictEqual({'aaa': 'bbb'}, result)
from box import start_authenticate_v2, finish_authenticate_v2 #code='OxeEF4WGfvo824bWZqYk5MZVq0JKzhEv' code='h1J9HeATdM4DHKVHZDjZOH3J9ALfCuza' response = finish_authenticate_v2('2dytaokzsribrjnulz3q67dvz2aicd6s', 'pAeZkP0RxBPo4RpP8g5KziOSVv2CNlmx', code) print response