def test_oauth2_token_request_error(self): expected_args = { 'client_id': '111111', 'client_secret': '22222', 'grant_type': 'wish', 'some_key': 'some_value' } fake_response = {'error': 'bigtuna', 'error_description': 'jim'} (flexmock(requests).should_receive('post').with_args( 'https://www.box.com/api/oauth2/token', expected_args).and_return(mocked_response(fake_response)).once()) with self.assertRaises( BoxAuthenticationException) as expected_exception: _oauth2_token_request('111111', '22222', 'wish', some_key='some_value') self.assertEqual('jim', expected_exception.exception.message) self.assertEqual('bigtuna', expected_exception.exception.error)
def test_oauth2_token_request_error(self): expected_args = { 'client_id': '111111', 'client_secret': '22222', 'grant_type': 'wish', 'some_key': 'some_value' } fake_response = { 'error': 'bigtuna', 'error_description': 'jim' } (flexmock(requests) .should_receive('post') .with_args('https://www.box.com/api/oauth2/token', expected_args) .and_return(mocked_response(fake_response)) .once()) with self.assertRaises(BoxAuthenticationException) as expected_exception: _oauth2_token_request('111111', '22222', 'wish', some_key='some_value') self.assertEqual('jim', expected_exception.exception.message) self.assertEqual('bigtuna', expected_exception.exception.error)
def test_oauth2_token_request(self): expected_args = { 'client_id': '111111', 'client_secret': '22222', 'grant_type': 'wish', 'some_key': 'some_value' } fake_response = {'hello': 'world'} (flexmock(requests).should_receive('post').with_args( 'https://www.box.com/api/oauth2/token', expected_args).and_return( flexmock(json=lambda: fake_response)).once()) response = _oauth2_token_request('111111', '22222', 'wish', some_key='some_value') self.assertDictEqual(fake_response, response)
def test_oauth2_token_request(self): expected_args = { 'client_id': '111111', 'client_secret': '22222', 'grant_type': 'wish', 'some_key': 'some_value' } fake_response = { 'hello': 'world' } (flexmock(requests) .should_receive('post') .with_args('https://www.box.com/api/oauth2/token', expected_args) .and_return(flexmock(json=lambda: fake_response)) .once()) response = _oauth2_token_request('111111', '22222', 'wish', some_key='some_value') self.assertDictEqual(fake_response, response)