コード例 #1
0
 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')
コード例 #2
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.assertEqual(response.status_code, 200)
     response = request.get(url='http://httpbin.org/get', get_json=True)
     self.assertEquals(isinstance(response, dict), True)
コード例 #3
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.assertEqual(response.status_code, 200)
     response = request.post(url='https://httpbin.org/post',
                             data={"test": "None"},
                             get_json=True)
コード例 #4
0
 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__)
コード例 #5
0
 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__)
コード例 #6
0
 def test_bad_request(self):
     request = HSRequest(self.client.auth, self.env)
     try:
         request.post(url=self.client.ACCOUNT_UPDATE_URL,
                      data={"bad": "request"})
         self.fail("BadRequest was expected")
     except BadRequest:
         pass
     except BaseException as e:
         self.fail("BadRequest was expected but got %s instead" %
                   e.__class__.__name__)
コード例 #7
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.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)
コード例 #8
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'},
                                    path_or_file=temp_filename)
        os.unlink(temp_filename)
        self.assertEqual(response, True)

        response = request.get_file(url='http://httpbin.org/robots.txt',
                                    headers={'Custom-Header': 'Nothing'},
                                    path_or_file='')
        self.assertEqual(response, False)

        out = io.StringIO()
        response = request.get_file(url='http://httpbin.org/robots.txt',
                                    headers={'Custom-Header': 'Nothing'},
                                    path_or_file=out)
        self.assertEqual(response, True)
コード例 #9
0
    def test_user_agent(self):
        ''' Test that the user agent is correctly sent '''

        self.client.create_account("*****@*****.**" % time())

        req_headers = self.client.request.headers
        self.assertIsNotNone(req_headers)
        self.assertIsInstance(req_headers, dict)
        self.assertIsNotNone(req_headers.get('User-Agent'))
        self.assertEquals(req_headers['User-Agent'], HSRequest._get_user_agent())

        parts = req_headers['User-Agent'].split('/')
        self.assertIs(len(parts), 2)
        self.assertEquals(parts[0], 'hellosign-python-sdk')
        parts = parts[1].split('.')
        self.assertIs(len(parts), 3)
        try:
            int(parts[0])
            int(parts[1])
        except ValueError:
            self.fail('Invalid version number')
        self.assertEquals(parts[2], '5')