def test_authentication(self, m): def check_auth(request): return request.headers['Authorization'] == 'Bearer aaa' m.get('https://api-demo.lingo24.com/docs/v1/foo', additional_matcher=check_auth, text='{}') authenticator = Authenticator('xxx', 'yyy', 'https://www.example.com/callback') authenticator.store.set({'access_token': 'aaa'}) client = Client(authenticator, 'demo') client.api_get('foo')
def test_authentication_expired_on_client(self, m): def check_auth(request): return request.headers['Authorization'] == 'Bearer ccc' m.get('https://api-demo.lingo24.com/docs/v1/foo', additional_matcher=check_auth, text='{}') m.post( 'https://api.lingo24.com/docs/v1/oauth2/access?refresh_token=bbb', text=json.dumps({ 'access_token': 'ccc', 'refresh_token': 'ddd', 'expires_in': 123 })) authenticator = Authenticator('xxx', 'yyy', 'https://www.example.com/callback') authenticator.store.set({ 'access_token': 'aaa', 'refresh_token': 'bbb', 'expires_at': 1000 }) client = Client(authenticator, 'demo') client.api_get('foo')
def test_authentication_expired_on_server(self, m): def text_callback(request, context): if request.headers['Authorization'] == 'Bearer ccc': return '{}' else: context.status_code = 401 m.get('https://api-demo.lingo24.com/docs/v1/foo', text=text_callback) m.post( 'https://api.lingo24.com/docs/v1/oauth2/access?refresh_token=bbb', text=json.dumps({ 'access_token': 'ccc', 'refresh_token': 'ddd', 'expires_in': 123 })) authenticator = Authenticator('xxx', 'yyy', 'https://www.example.com/callback') authenticator.store.set({ 'access_token': 'aaa', 'refresh_token': 'bbb', 'expires_at': 50000 }) client = Client(authenticator, 'demo') client.api_get('foo')