def test__view___is_valid_token_request_whenCalledWithValidRequest_WillReturnTryeAndNoneAndData( self): client_info = {'client_id': 1234, 'scope': 1234} query_params = { 'grant_type': 'authorization_code', 'code': view.generate_authorisation_token(client_info), 'redirect_uri': 'http%3A%2F%2Flocalhost:5001%2Fauth' } headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW' } mock_request = mock.MagicMock(spec=Request, args=query_params, headers=headers) validation_result = view._is_valid_token_request(mock_request) expected_data = { 'grant_type': 'authorization_code', 'code': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjEyMzQsImFtciI6InBhc3N3b3JkIiwiaXNzIjoibWF0dC1wYyIs \ ImlhdCI6MTQ3MjY1NjQ0MSwiZXhwIjoxNDcyNjU2NDcxLCJzY3AiOjEyMzQsImF1ZCI6Im1hdHQtcGMifQ.f1BhHLl0UeZT4l1 \ taxVHAWaBiH8nhyVEP-05FUuVQGk', 'redirect_uri': 'http%3A%2F%2Flocalhost:5001%2Fauth', 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW' } expected_result = True, None, expected_data
def test__view___is_valid_token_request__whenCalledWithNoAuthorizationCode_WillReturnFalseAndInvalidCodeAndNoData( self): query_params = { 'grant_type': 'authorization_code', 'code': None, 'redirect_uri': 'http%3A%2F%2Flocalhost:5001%2Fauth' } headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW' } mock_request = mock.MagicMock(spec=Request, args=query_params, headers=headers) validation_result = view._is_valid_token_request(mock_request) expected_result = False, 'invalid_code', None self.assertEqual(validation_result, expected_result)
def test__view___is_valid_token_request__whenCalledWithoutAuthorizationHeader_WillReturnFalseAndInvalidRequestAndNoData( self): client_info = {'client_id': 1234, 'scope': 1234} query_params = { 'grant_type': 'authorization_code', 'code': view.generate_authorisation_token(client_info), 'redirect_uri': 'http%3A%2F%2Flocalhost:5001%2Fauth' } headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': None } mock_request = mock.MagicMock(spec=Request, args=query_params, headers=headers) validation_result = view._is_valid_token_request(mock_request) expected_result = False, 'authorization header expected', None self.assertEqual(validation_result, expected_result)