def test_get_sets_field_defaults(self, pyramid_request): ctrl = AuthClientCreateController(pyramid_request) ctx = ctrl.get() assert ctx['form'] == {'authority': 'example.com', 'grant_type': GrantType.authorization_code, 'response_type': ResponseType.code, 'trusted': False}
def test_get_sets_field_defaults(self, pyramid_request): ctrl = AuthClientCreateController(pyramid_request) ctx = ctrl.get() assert ctx['form'] == {'authority': 'example.com', 'grant_type': GrantType.authorization_code, 'response_type': ResponseType.code, 'trusted': False}
def test_post_does_not_generate_secret_for_authcode_clients(self, form_post, pyramid_request): pyramid_request.POST = form_post pyramid_request.POST['grant_type'] = 'authorization_code' ctrl = AuthClientCreateController(pyramid_request) ctrl.post() client = pyramid_request.db.query(AuthClient).one() assert client.secret is None
def test_post_does_not_generate_secret_for_authcode_clients(self, form_post, pyramid_request): pyramid_request.POST = form_post pyramid_request.POST['grant_type'] = 'authorization_code' ctrl = AuthClientCreateController(pyramid_request) ctrl.post() client = pyramid_request.db.query(AuthClient).one() assert client.secret is None
def test_post_generates_secret_for_client_credentials_clients(self, form_post, pyramid_request): pyramid_request.POST = form_post pyramid_request.POST['grant_type'] = 'client_credentials' secret_gen = Mock(return_value='keep-me-secret') ctrl = AuthClientCreateController(pyramid_request, secret_gen=secret_gen) ctrl.post() client = pyramid_request.db.query(AuthClient).one() assert client.secret == 'keep-me-secret'
def test_post_sets_response_type(self, form_post, pyramid_request, grant_type, expected_response_type): pyramid_request.POST = form_post pyramid_request.POST['grant_type'] = grant_type ctrl = AuthClientCreateController(pyramid_request) ctrl.post() client = pyramid_request.db.query(AuthClient).one() assert client.response_type == expected_response_type
def test_post_creates_authclient(self, form_post, pyramid_request): pyramid_request.POST = form_post pyramid_request.POST['name'] = 'Third Party App' ctrl = AuthClientCreateController(pyramid_request) ctrl.post() pyramid_request.db.query(AuthClient) \ .filter_by(name='Third Party App') \ .one()
def test_post_redirects_to_edit_view(self, form_post, pyramid_request): pyramid_request.POST = form_post ctrl = AuthClientCreateController(pyramid_request) response = ctrl.post() client = pyramid_request.db.query(AuthClient).one() expected_location = pyramid_request.route_url('admin_oauthclients_edit', id=client.id) assert response == redirect_302_to(expected_location)
def test_post_generates_secret_for_client_credentials_clients(self, form_post, pyramid_request): pyramid_request.POST = form_post pyramid_request.POST['grant_type'] = 'client_credentials' secret_gen = Mock(return_value='keep-me-secret') ctrl = AuthClientCreateController(pyramid_request, secret_gen=secret_gen) ctrl.post() client = pyramid_request.db.query(AuthClient).one() assert client.secret == 'keep-me-secret'
def test_post_sets_response_type(self, form_post, pyramid_request, grant_type, expected_response_type): pyramid_request.POST = form_post pyramid_request.POST['grant_type'] = grant_type ctrl = AuthClientCreateController(pyramid_request) ctrl.post() client = pyramid_request.db.query(AuthClient).one() assert client.response_type == expected_response_type
def test_post_creates_authclient(self, form_post, pyramid_request): pyramid_request.POST = form_post pyramid_request.POST['name'] = 'Third Party App' ctrl = AuthClientCreateController(pyramid_request) ctrl.post() pyramid_request.db.query(AuthClient) \ .filter_by(name='Third Party App') \ .one()
def test_post_redirects_to_edit_view(self, form_post, matchers, pyramid_request): pyramid_request.POST = form_post ctrl = AuthClientCreateController(pyramid_request) response = ctrl.post() client = pyramid_request.db.query(AuthClient).one() expected_location = pyramid_request.route_url('admin_oauthclients_edit', id=client.id) assert response == matchers.Redirect302To(expected_location)