Beispiel #1
0
 def test_request_user_token(self):
     c = Credentials('id', 'secret', 'uri')
     send = MagicMock(return_value=mock_response())
     with patch(cred_module + '.send', send):
         c.request_user_token('code')
         send.assert_called_once()
     c.close()
Beispiel #2
0
 def test_auto_refresh_client_token(self):
     c = Credentials('id', 'secret')
     token = make_token({'refresh_token': None})
     c.request_client_token = MagicMock(return_value=token)
     c.refresh(token)
     c.request_client_token.assert_called_once()
     c.close()
Beispiel #3
0
 def test_server_error_raises_http_error(self):
     c = Credentials('id', 'secret')
     response = mock_response(500, {})
     c.send = MagicMock(return_value=response)
     with pytest.raises(HTTPError):
         c.request_client_token()
     c.close()
Beispiel #4
0
 def test_auto_refresh_pkce_token(self):
     c = Credentials('id')
     token = make_token(uses_pkce=True)
     c.refresh_pkce_token = MagicMock(return_value=token)
     c.refresh(token)
     c.refresh_pkce_token.assert_called_once()
     c.close()
Beispiel #5
0
 def test_client_error_without_description(self):
     c = Credentials('id', 'secret')
     error = {'error': 'Bad thing'}
     response = mock_response(400, error)
     c.send = MagicMock(return_value=response)
     with pytest.raises(HTTPError):
         c.request_client_token()
     c.close()
Beispiel #6
0
    def test_refresh_user_token_refresh_replaced_if_returned(self):
        c = Credentials('id', 'secret')
        token = token_dict()
        response = mock_response(content=token)

        send = MagicMock(return_value=response)
        with patch(cred_module + '.send', send):
            refreshed = c.refresh_user_token('refresh')
            assert refreshed.refresh_token == token['refresh_token']
        c.close()
Beispiel #7
0
 def test_refresh_pkce_token(self):
     c = Credentials('id')
     c.send = MagicMock(return_value=mock_response())
     token = c.refresh_pkce_token('refresh')
     assert token.uses_pkce
     c.close()
Beispiel #8
0
 def test_request_pkce_token(self):
     c = Credentials('id')
     c.send = MagicMock(return_value=mock_response())
     token = c.request_pkce_token('scope', 'verifier')
     assert token.uses_pkce
     c.close()
Beispiel #9
0
 def test_pkce_user_authorisation(self):
     c = Credentials('id', redirect_uri='redirect')
     c.pkce_user_authorisation('scope', 'state')
     c.close()
Beispiel #10
0
 def test_refresh_user_token(self, app_env, user_refresh):
     c = Credentials(app_env[0], app_env[1])
     token = c.refresh_user_token(user_refresh)
     assert token.refresh_token is not None
     assert len(token.scope) > 0
     c.close()
Beispiel #11
0
 def test_user_authorisation_url(self):
     c = Credentials('id', redirect_uri='uri')
     url = c.user_authorisation_url('scope', 'state')
     assert 'scope=scope' in url
     assert 'state=state' in url
     c.close()
Beispiel #12
0
 def test_basic_token_with_no_secret_raises(self):
     c = Credentials('id')
     with pytest.raises(ValueError):
         c.request_client_token()
     c.close()
Beispiel #13
0
 def test_repr(self):
     c = Credentials('id', 'secret')
     assert repr(c).startswith('Credentials(')
     c.close()
Beispiel #14
0
    def test_bad_arguments_raises_error(self):
        c = Credentials('id', 'secret')

        with pytest.raises(HTTPError):
            c.request_client_token()
        c.close()
Beispiel #15
0
 def test_user_authorisation_accepts_scope_list(self):
     c = Credentials('id', redirect_uri='uri')
     url = c.user_authorisation_url(['a', 'b'], 'state')
     assert 'scope=a+b' in url
     c.close()
Beispiel #16
0
 def test_request_client_token(self, app_env):
     c = Credentials(app_env[0], app_env[1])
     token = c.request_client_token()
     assert token.refresh_token is None
     assert str(token.scope) == ''
     c.close()
Beispiel #17
0
 def test_user_authorisation_url_equal_to_expiring(self, app_env):
     auth = Credentials(*app_env)
     util = RefreshingCredentials(*app_env)
     assert auth.user_authorisation_url() == util.user_authorisation_url()
     auth.close()