Ejemplo n.º 1
0
 def it_handles_updating_token_with_charset(self, response, token_response_with_charset):
     returns = [token_response_with_charset, token_response_with_charset, response]
     h = RequestHandler("")
     h._send_request = Mock(side_effect=lambda *args: returns.pop(0))
     with patch("ubersmith.api.time") as time:
         time.sleep = lambda x: None
         assert self.test_data == h.process_request("uber.method_list").data
Ejemplo n.º 2
0
 def it_raises_updating_token_after_3_tries(self, response, token_response):
     returns = [token_response, token_response, token_response, response]
     h = RequestHandler("")
     h._send_request = Mock(side_effect=lambda *args: returns.pop(0))
     with patch("ubersmith.api.time") as time:
         time.sleep = lambda x: None
         with pytest.raises(UpdatingTokenResponse):
             h.process_request("uber.method_list")
Ejemplo n.º 3
0
 def it_handles_updating_token(self, response, token_response):
     returns = [
         token_response,
         token_response,
         response,
     ]
     h = RequestHandler('')
     h._send_request = Mock(side_effect=lambda *args: returns.pop(0))
     with patch('ubersmith.api.time') as time:
         time.sleep = lambda x: None
         assert self.test_data == h.process_request('uber.method_list').data
Ejemplo n.º 4
0
 def it_handles_updating_token(self, response, token_response):
     returns = [
         token_response,
         token_response,
         response,
     ]
     h = RequestHandler('')
     h._send_request = Mock(side_effect=lambda *args: returns.pop(0))
     with patch('ubersmith.api.time') as time:
         time.sleep = lambda x: None
         assert self.test_data == h.process_request('uber.method_list').data
Ejemplo n.º 5
0
 def it_raises_updating_token_after_3_tries(self, response, token_response):
     returns = [
         token_response,
         token_response,
         token_response,
         response,
     ]
     h = RequestHandler('')
     h._send_request = Mock(side_effect=lambda *args: returns.pop(0))
     with patch('ubersmith.api.time') as time:
         time.sleep = lambda x: None
         with pytest.raises(UpdatingTokenResponse):
             h.process_request('uber.method_list')
Ejemplo n.º 6
0
 def it_is_able_to_proxy_calls_to_modules(self):
     h = RequestHandler('')
     for call_base, call_name in (m.split('.') for m in METHODS):
         assert hasattr(h, call_base)
         proxy = getattr(h, call_base)
         partial = getattr(proxy, call_name)
         assert callable(partial)
         assert partial.request_handler == h
Ejemplo n.º 7
0
 def it_validates_bad_methods(self):
     h = RequestHandler('')
     with pytest.raises(RequestError) as e:
         h.process_request('boop')
     assert str(e.value) == "Requested method is not valid."
Ejemplo n.º 8
0
 def it_can_disable_ssl_validation(self, response):
     h = RequestHandler('', verify=False)
     with patch('ubersmith.api.RequestHandler.session') as session:
         session.post.return_value = response
         h.process_request('uber.method_list')
         assert session.post.call_args[1]['verify'] is False
Ejemplo n.º 9
0
 def it_validates_ssl(self, response):
     h = RequestHandler('')
     with patch('ubersmith.api.RequestHandler.session') as session:
         session.post.return_value = response
         h.process_request('uber.method_list')
         assert session.post.call_args[1]['verify'] is True
Ejemplo n.º 10
0
 def it_does_not_proxy_calls_to_methods_that_are_not_callable(self):
     h = RequestHandler('')
     ubersmith.uber.rando = 'X-rando'
     with pytest.raises(AttributeError):
         h.uber.rando
Ejemplo n.º 11
0
 def it_does_not_proxy_calls_to_methods_that_do_not_exist(self):
     h = RequestHandler('')
     with pytest.raises(AttributeError):
         h.uber.invalid_method
Ejemplo n.º 12
0
 def it_raises_maintenance_response(self, maintenance_response):
     h = RequestHandler('')
     h._send_request = Mock(return_value=maintenance_response)
     with pytest.raises(MaintenanceResponse):
         h.process_request('uber.method_list')
Ejemplo n.º 13
0
 def it_handles_normal_responses(self, response):
     h = RequestHandler('')
     h._send_request = Mock(return_value=response)
     assert self.test_data == h.process_request('uber.method_list').data
Ejemplo n.º 14
0
 def it_validates_ssl(self, response):
     h = RequestHandler("")
     with patch("ubersmith.api.RequestHandler.session") as session:
         session.post.return_value = response
         h.process_request("uber.method_list")
         assert session.post.call_args[1]["verify"] is True
Ejemplo n.º 15
0
 def it_can_disable_ssl_validation(self, response):
     h = RequestHandler("", verify=False)
     with patch("ubersmith.api.RequestHandler.session") as session:
         session.post.return_value = response
         h.process_request("uber.method_list")
         assert session.post.call_args[1]["verify"] is False
Ejemplo n.º 16
0
 def it_handles_normal_responses(self, response):
     h = RequestHandler('')
     h._send_request = Mock(return_value=response)
     assert self.test_data == h.process_request('uber.method_list').data
Ejemplo n.º 17
0
 def it_validates_bad_methods(self):
     h = RequestHandler('')
     with pytest.raises(RequestError) as e:
         h.process_request('boop')
     assert str(e.value) == "Requested method is not valid."
Ejemplo n.º 18
0
 def it_can_disable_ssl_validation(self, response):
     h = RequestHandler('', verify=False)
     with patch('ubersmith.api.requests') as requests:
         requests.post.return_value = response
         h.process_request('uber.method_list')
         assert requests.post.call_args[1]['verify'] is False
Ejemplo n.º 19
0
 def it_validates_ssl(self, response):
     h = RequestHandler('')
     with patch('ubersmith.api.requests') as requests:
         requests.post.return_value = response
         h.process_request('uber.method_list')
         assert requests.post.call_args[1]['verify'] is True
Ejemplo n.º 20
0
def test_get_set_default_handler():
    h = RequestHandler('')
    set_default_request_handler(h)
    assert get_default_request_handler() == h
    ubersmith.api._DEFAULT_REQUEST_HANDLER = None
Ejemplo n.º 21
0
 def it_uses_passed_session(self):
     session = Mock()
     h = RequestHandler('', session=session)
     h._send_request('uber.method_list', {})
     assert session.post.called
Ejemplo n.º 22
0
 def it_raises_maintenance_response(self, maintenance_response):
     h = RequestHandler('')
     h._send_request = Mock(return_value=maintenance_response)
     with pytest.raises(MaintenanceResponse):
         h.process_request('uber.method_list')
Ejemplo n.º 23
0
def init(base_url, username=None, password=None, verify=True):
    """Initialize ubersmith API module with HTTP request handler."""
    handler = RequestHandler(base_url, username, password, verify)
    set_default_request_handler(handler)
    return handler
Ejemplo n.º 24
0
 def it_uses_passed_session(self):
     session = Mock()
     h = RequestHandler("", session=session)
     h._send_request("uber.method_list", {})
     assert session.post.called