def test_get(self): request = HSRequest(self.client.auth) response = request.get(url='http://httpbin.org/get', headers={'Custom-Header': 'Nothing'}, parameters={'param': 'Nothing'}, get_json=False) self.assertEqual(response.status_code, 200) response = request.get(url='http://httpbin.org/get', get_json=True) self.assertEquals(isinstance(response, dict), True)
def test_not_found(self): request = HSRequest(self.client.auth, self.env) try: request.get(url=self.client.API_URL + "/not/found") self.fail("NotFound was expected") except NotFound: pass except BaseException as e: self.fail("BadRequest was expected but got %s instead" % e.__class__.__name__)
def test_not_authorized(self): request = HSRequest(("test", ''), self.env) try: request.get(self.client.ACCOUNT_INFO_URL) self.fail("Unauthorized was expected") except Unauthorized: pass except BaseException as e: self.fail("BadRequest was expected but got %s instead" % e.__class__.__name__)
def test_get_https(self): request = HSRequest(self.client.auth) response = request.get(url='https://httpbin.org/get', headers={'Custom-Header': 'Nothing'}, parameters={'param': 'Nothing'}, get_json=False) self.assertEqual(response.status_code, 200) response = request.get(url='https://httpbin.org/get', get_json=True) self.assertEquals(isinstance(response, dict), True) try: response = request.get(url='https://app.hellosign.com/oauth/token', get_json=True) except BadRequest as e: self.assertEqual('400 error' in str(e), True)
def test_call(self): auth = HSAccessTokenAuth(access_token="thetoken", access_token_type="thetokentype") request = HSRequest(auth) response = request.get(url='http://httpbin.org/headers') self.assertEquals(response['headers']['Authorization'], 'thetokentype thetoken')