def test_it_verifies_the_jwt_bearer(self, pyramid_request, oauth_service): pyramid_request.POST = {'assertion': 'the-assertion', 'grant_type': 'the-grant-type'} views.access_token(pyramid_request) oauth_service.verify_jwt_bearer.assert_called_once_with( assertion='the-assertion', grant_type='the-grant-type' )
def test_it_verifies_the_token(self, pyramid_request, oauth_service): pyramid_request.POST = {'assertion': 'the-assertion', 'grant_type': 'the-grant-type'} views.access_token(pyramid_request) oauth_service.verify_token_request.assert_called_once_with( pyramid_request.POST )
def test_it_returns_expires_in_if_the_token_expires( self, factories, pyramid_request, oauth_service): token = factories.DeveloperToken(expires=datetime.datetime.utcnow() + datetime.timedelta(hours=1)) oauth_service.create_token.return_value = token assert 'expires_in' in views.access_token(pyramid_request)
def test_it_returns_an_oauth_compliant_response(self, pyramid_request, oauth_service): token = models.Token() oauth_service.create_token.return_value = token assert views.access_token(pyramid_request) == { 'access_token': token.value, 'token_type': 'bearer', 'expires_in': TOKEN_TTL.total_seconds(), }
def test_it_does_not_returns_the_refresh_token_if_the_token_does_not_have_one( self, pyramid_request): assert 'refresh_token' not in views.access_token(pyramid_request)
def test_it_returns_the_refresh_token_if_the_token_has_one( self, pyramid_request, token): token.refresh_token = 'test_refresh_token' assert views.access_token( pyramid_request)['refresh_token'] == token.refresh_token
def test_it_does_not_return_expires_in_if_the_token_does_not_expire( self, pyramid_request): assert 'expires_in' not in views.access_token(pyramid_request)
def test_it_returns_an_oauth_compliant_response(self, pyramid_request, token): response = views.access_token(pyramid_request) assert response['access_token'] == token.value assert response['token_type'] == 'bearer'
def test_it_creates_a_token(self, pyramid_request, oauth_service): views.access_token(pyramid_request) oauth_service.create_token.assert_called_once_with( mock.sentinel.user, mock.sentinel.authclient)