Esempio n. 1
0
 def test_request_without_token(self):
     with mock.patch('requests.sessions.Session.send') as send:
         send.return_value = mock_send_value({'name': 'a'})
         client = OAuthClient(client_id='foo')
         try:
             client.get('https://i.b/user')
         except OAuthError as exc:
             self.assertEqual('missing_token', exc.error)
Esempio n. 2
0
    def test_request_with_token(self):
        with mock.patch('requests.sessions.Session.send') as send:
            send.return_value = mock_send_value({'name': 'a'})

            client = OAuthClient(client_id='foo')
            token = get_bearer_token()
            resp = client.get('https://i.b/user', token=token)
            self.assertEqual(resp.json()['name'], 'a')

            resp = client.post('https://i.b/user', token=token)
            self.assertEqual(resp.json()['name'], 'a')

            resp = client.put('https://i.b/user', token=token)
            self.assertEqual(resp.json()['name'], 'a')

            resp = client.delete('https://i.b/user', token=token)
            self.assertEqual(resp.json()['name'], 'a')

            client.api_base_url = 'https://i.b'
            resp = client.get('user', token=token)
            self.assertEqual(resp.json()['name'], 'a')