def test_client_proxy_string(): # When I create a client with a proxy as a string proxy = "baz:1234" c = BaseClient() # Then the Client should create the proxy config as a dictionary c._normalize_proxy.should.be({"http": proxy, "https": proxy})
def test_client_proxy_dict(): # When I create a client with a proxy as a string proxy = {"baz": "1234"} c = BaseClient() # Then the Client should create the proxy config as a dictionary c._normalize_proxy.should.be(proxy)
def test_client_proxy_dict(): """ Base Client should parse proxy dicts """ # When I create a client with a proxy as a dict proxy = {"baz": "1234"} c = BaseClient(proxy=proxy) # Then the Client should create the proxy config as a dictionary c.proxy.should.equal(proxy)
def test_client_proxy_string(): """ Base Client should parse proxy strings """ # When I create a client with a proxy as a string proxy = "baz:1234" c = BaseClient(proxy=proxy) # Then the Client should create the proxy config as a dictionary c.proxy.should.equal({"http": proxy, "https": proxy})
def test_make_request_non_200(): httpretty.register_uri(httpretty.GET, "https://www.github.com", body=None, status=400) # When I make an API request and receive a 400 c = BaseClient() # Then I should raise the appropriate requests exception c._make_request.when.called_with(requests.get, "https://www.github.com")\ .should.throw(requests.RequestException)
def test_make_request_non_200(): """ Bad HTTP Responses should throw an error """ httpretty.register_uri(httpretty.GET, "http://foobar.com", body="123", status=400) # When I make an API request and receive a 400 c = BaseClient() # Then I should raise the appropriate requests exception c._make_request.when.called_with(requests.get, "http://foobar.com")\ .should.throw(requests.RequestException)
def test_make_request_timeout(): httpretty.register_uri( httpretty.GET, "www.example.com", body=None, ) # When I make an API request and receive no response c = BaseClient() # Then I should raise a NewRelicApiException c._make_request.when.called_with(requests.get, "http://www.example.com", timeout=0.05, retries=1)\ .should.throw(requests.RequestException)