Exemplo n.º 1
0
 def test_bad_request(self):
     request = HSRequest(self.client.auth)
     try:
         request.post(url=self.client.ACCOUNT_UPDATE_URL,
                      data={"bad": "request"})
     except BadRequest:
         pass
Exemplo n.º 2
0
 def test_post_https(self):
     request = HSRequest(self.client.auth)
     response = request.post(
         url="https://httpbin.org/post", data={"test": "None"}, get_json=False, headers={"Custom-Header": "Nothing"}
     )
     self.assertEquals(response.status_code, 200)
     response = request.post(url="https://httpbin.org/post", data={"test": "None"}, get_json=True)
 def test_call(self):
     auth = HSAccessTokenAuth(access_token="at_test",
                              access_token_type="att_test")
     request = HSRequest(auth)
     response = request.get(url='http://httpbin.org/headers')
     self.assertEquals(response['headers']['Authorization'],
                       'at_test att_test')
Exemplo n.º 4
0
 def test_bad_request(self):
     request = HSRequest(self.client.auth)
     try:
         request.post(url=self.client.ACCOUNT_UPDATE_URL,
                      data={"bad": "request"})
     except BadRequest:
         pass
 def test_call(self):
     auth = HSAccessTokenAuth(access_token="at_test",
                              access_token_type="att_test")
     request = HSRequest(auth)
     response = request.get(url='http://httpbin.org/headers')
     self.assertEquals(response['headers']['Authorization'],
                       'at_test att_test')
Exemplo n.º 6
0
 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.assertEquals(response.status_code, 200)
     response = request.get(url='http://httpbin.org/get', get_json=True)
     self.assertEquals(isinstance(response, dict), True)
Exemplo n.º 7
0
 def test_post_https(self):
     request = HSRequest(self.client.auth)
     response = request.post(url='https://httpbin.org/post',
                             data={"test": "None"},
                             get_json=False,
                             headers={'Custom-Header': 'Nothing'})
     self.assertEquals(response.status_code, 200)
     response = request.post(url='https://httpbin.org/post',
                             data={"test": "None"},
                             get_json=True)
Exemplo n.º 8
0
 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.assertEquals(response.status_code, 200)
     response = request.get(url="http://httpbin.org/get", get_json=True)
     self.assertEquals(isinstance(response, dict), True)
Exemplo n.º 9
0
    def test_get_file(self):
        request = HSRequest(self.client.auth)
        f = tempfile.NamedTemporaryFile(delete=True)
        temp_filename = f.name
        f.close()
        response = request.get_file(
            url="http://httpbin.org/robots.txt", headers={"Custom-Header": "Nothing"}, filename=temp_filename
        )
        os.unlink(temp_filename)
        self.assertEquals(response, True)

        response = request.get_file(
            url="http://httpbin.org/robots.txt", headers={"Custom-Header": "Nothing"}, filename=""
        )
        self.assertEquals(response, False)
Exemplo n.º 10
0
    def test_get_file(self):
        request = HSRequest(self.client.auth)
        f = tempfile.NamedTemporaryFile(delete=True)
        temp_filename = f.name
        f.close()
        response = request.get_file(url='http://httpbin.org/robots.txt',
                                    headers={'Custom-Header': 'Nothing'},
                                    filename=temp_filename)
        os.unlink(temp_filename)
        self.assertEquals(response, True)

        response = request.get_file(url='http://httpbin.org/robots.txt',
                                    headers={'Custom-Header': 'Nothing'},
                                    filename='')
        self.assertEquals(response, False)
Exemplo n.º 11
0
    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.assertEquals(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://www.hellosign.com/oauth/token',
                                   get_json=True)
        except BadRequest, e:
            self.assertEquals('400 error' in str(e), True)
Exemplo n.º 12
0
    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.assertEquals(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://www.hellosign.com/oauth/token", get_json=True)
        except BadRequest, e:
            self.assertEquals("400 error" in str(e), True)
Exemplo n.º 13
0
 def test_not_found(self):
     request = HSRequest(self.client.auth)
     try:
         request.get(url=self.client.API_URL + "/not/found")
     except NotFound:
         pass
Exemplo n.º 14
0
 def test_not_authorized(self):
     request = HSRequest(HTTPBasicAuth("test", ''))
     try:
         request.get(self.client.ACCOUNT_INFO_URL)
     except Unauthorized:
         pass
Exemplo n.º 15
0
 def test_not_found(self):
     request = HSRequest(self.client.auth)
     try:
         request.get(url=self.client.API_URL + "/not/found")
     except NotFound:
         pass
Exemplo n.º 16
0
 def test_not_authorized(self):
     request = HSRequest(HTTPBasicAuth("test", ''))
     try:
         request.get(self.client.ACCOUNT_INFO_URL)
     except Unauthorized:
         pass