def test_api_rate_limit_exceeded_outside_window(): """ API Rate limit should not trigger outside of rate limit window """ # When I make an API request with a rate limit and I am have a previous # request outside of the time window def foobar(): pass c = Client(account_id="foo", api_key="bar") c.foobar_window = datetime.datetime.now() - datetime.timedelta(seconds=61) # Then I should not receive a API Rate Limit Timeout c._api_rate_limit_exceeded(foobar, window=60).should.be.false
def test_get_metric_names(): httpretty.register_uri(httpretty.GET, NEW_RELIC_REGEX, body=METRIC_NAMES_SAMPLE, status=200 ) # When I make an API request to view applications c = Client(account_id="1", api_key="2") # Then I should receive an array of Applications result = c.get_metric_names("foo") result.should.be.a('dict') result.should.have.key('WebTransaction') result['WebTransaction'].should.be.a('list') result['WebTransaction'].should.have.length_of(8)
def test_api_rate_limit_exceeded_inside_window(): """ API Rate limit should trigger inside of rate limit window """ # When I make an API request with a rate limit and I am have a previous # request inside of the time window def foobar(): pass c = Client(account_id="foo", api_key="bar") c.foobar_window = datetime.datetime.now() - datetime.timedelta(seconds=59) # Then I should receive a wait time c._api_rate_limit_exceeded.when.called_with(foobar, window=60)\ .should.throw(NewRelicApiRateLimitException)