示例#1
0
 def test_connection_pooled(self):
     configuration.host = 'localhost'
     configuration.port = 65521
     run_server()
     request = ApisRequest()
     data = {'event': '$login.authenticate', 'user_id': '12345'}
     response = request.build_query('post', 'authenticate', data)
     num_pools = len(response.connection.poolmanager.pools.keys())
     configuration.host = 'api.castle.io'
     configuration.port = 443
     self.assertEqual(num_pools, 1)
示例#2
0
    def test_build_query(self):
        data = {'event': '$login.authenticate', 'user_id': '12345'}
        configuration.api_secret = 'api_secret'
        # JSON requires double quotes for its strings
        response_text = {"action": "allow", "user_id": "12345"}
        responses.add(responses.POST,
                      'https://api.castle.io/v1/authenticate',
                      json=response_text,
                      status=200)
        res = ApisRequest().build_query('post', 'authenticate', data)
        self.assertIsInstance(res, Response)
        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.json(), response_text)

        configuration.api_secret = None
示例#3
0
class Api(object):
    def __init__(self):
        self.req = ApisRequest({'Content-Type': 'application/json'})

    def request(self, command):
        if not configuration.isValid():
            raise ConfigurationError
        return self.req.build_query(command.method, command.path, command.data)

    def call(self, command):
        return ApisResponse(self.request(command)).call()
示例#4
0
 def __init__(self):
     self.req = ApisRequest({'Content-Type': 'application/json'})
示例#5
0
 def test_verify_false(self):
     configuration.port = 3001
     self.assertEqual(ApisRequest().verify(), False)
     configuration.port = 443
示例#6
0
 def test_verify_true(self):
     self.assertEqual(ApisRequest().verify(), True)
示例#7
0
 def test_build_url(self):
     self.assertEqual(ApisRequest().build_url('authenticate'),
                      'https://api.castle.io/v1/authenticate')
示例#8
0
 def test_init_base_url(self):
     self.assertEqual(ApisRequest().base_url, 'https://api.castle.io/v1')
示例#9
0
 def test_init_headers(self):
     headers = {'X-Castle-Client-Id': '1234'}
     self.assertEqual(ApisRequest(headers).headers, headers)