Exemplo n.º 1
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 = Request().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
Exemplo n.º 2
0
class Api(object):
    def __init__(self):
        self.req = Request({'Content-Type': 'application/json'})

    def request(self, command):
        return self.req.build_query(command.method, command.endpoint, command.data)

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