Exemplo n.º 1
0
def test_view_servers():
    httpretty.register_uri(httpretty.GET,
                           NEW_RELIC_REGEX,
                           body=VIEW_SERVERS_SAMPLE,
                           status=200)

    # When I make an API request to view servers
    c = Client(account_id="1", api_key="2")

    # Then I should receive an array of Servers
    result = c.view_servers()
    result.should.be.an('list')
    result.should.have.length_of(2)

    result[0].should.be.an('pyrelic.Server')
    result[0].overview_url.should.equal(
        'https://rpm.newrelic.com/accounts/1/servers/555')
    result[0].hostname.should.equal('my-hostname.newrelic.com')
    result[0].server_id.should.equal('555')

    result[1].should.be.an('pyrelic.Server')
    result[1].overview_url.should.equal(
        'https://rpm.newrelic.com/accounts/1/servers/556')
    result[1].hostname.should.equal('my-hostname-2.newrelic.com')
    result[1].server_id.should.equal('556')
Exemplo n.º 2
0
def test_notify_deployment_by_name_success():
    """
    Client should be able to notify deployments with application name
    """
    httpretty.register_uri(httpretty.POST,
                           NEW_RELIC_REGEX,
                           body=NOTIFY_DEPLOYMENT_SUCCESS,
                           status=200)
    # When I make an API request to notify of deployment
    c = Client(account_id="1", api_key="2")

    # Then I should receive a valid response
    result = c.notify_deployment(application_name=123,
                                 description='description',
                                 revision='1.2.3',
                                 user='******',
                                 changelog='orange')

    result.should.be.an('dict')

    result.should.have.key('account-id')
    result['account-id'].should.equal('123')

    result.should.have.key('agent-id')
    result['agent-id'].should.equal('456')
Exemplo n.º 3
0
def test_view_servers():
    """
    Client should be able to list Servers
    """
    httpretty.register_uri(httpretty.GET, NEW_RELIC_REGEX,
                           body=VIEW_SERVERS_SAMPLE,
                           status=200
                           )

    # When I make an API request to view servers
    c = Client(account_id="1", api_key="2")

    # Then I should receive an array of Servers
    result = c.view_servers()
    result.should.be.an('list')
    result.should.have.length_of(2)

    result[0].should.be.an('pyrelic.Server')
    result[0].overview_url.should.equal('https://rpm.newrelic.com/accounts/1/servers/555')
    result[0].hostname.should.equal('my-hostname.newrelic.com')
    result[0].server_id.should.equal('555')

    result[1].should.be.an('pyrelic.Server')
    result[1].overview_url.should.equal('https://rpm.newrelic.com/accounts/1/servers/556')
    result[1].hostname.should.equal('my-hostname-2.newrelic.com')
    result[1].server_id.should.equal('556')
Exemplo n.º 4
0
def test_api_rate_limit_exceeded_no_previous_call():
    # When I make an API request with a rate limit and I am have no previous requests
    def foobar():
        pass

    c = Client(account_id="foo", api_key="bar")

    # Then I should not receive a API Rate Limit Timeout
    c._api_rate_limit_exceeded(foobar).should.be.false
Exemplo n.º 5
0
def test_api_rate_limit_exceeded_no_previous_call():
    # When I make an API request with a rate limit and I am have no previous requests
    def foobar():
        pass

    c = Client(account_id="foo", api_key="bar")

    # Then I should not receive a API Rate Limit Timeout
    c._api_rate_limit_exceeded(foobar).should.be.false
Exemplo n.º 6
0
def test_api_rate_limit_exceeded_outside_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
Exemplo n.º 7
0
def test_delete_servers_failure():
    httpretty.register_uri(httpretty.DELETE,
                           NEW_RELIC_REGEX,
                           body=DELETE_SERVERS_FAILURE_SAMPLE,
                           status=200)
    # When I make an API request to delete a server
    c = Client(account_id="1", api_key="2")
    result = c.delete_servers(server_id="123456")

    # Then I should receive an array of failed deletions
    result.should.equal([{'server_id': '123456'}])
Exemplo n.º 8
0
def test_api_rate_limit_exceeded_outside_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
Exemplo n.º 9
0
def test_delete_applications():
    httpretty.register_uri(httpretty.POST,
                           NEW_RELIC_REGEX,
                           body=DELETE_APPLICATION_SUCCESS_SAMPLE,
                           status=200)
    # When I make an API request to view threshold values
    c = Client(account_id="1", api_key="2")

    # Then I should receive an array of Threshold values
    result = c.delete_applications({"app_id": "1234"})
    result.should.have.length_of(1)
Exemplo n.º 10
0
def test_delete_servers_failure():
    httpretty.register_uri(httpretty.DELETE,
                           NEW_RELIC_REGEX,
                           body=DELETE_SERVERS_FAILURE_SAMPLE,
                           status=200
                           )
    # When I make an API request to delete a server
    c = Client(account_id="1", api_key="2")
    result = c.delete_servers(server_id="123456")

    # Then I should receive an array of failed deletions
    result.should.equal([{'server_id': '123456'}])
Exemplo n.º 11
0
def test_get_metric_data():
    httpretty.register_uri(httpretty.GET,
                           NEW_RELIC_REGEX,
                           body=METRIC_DATA_SAMPLE,
                           status=200)
    # When I make an API request to get metric data
    c = Client(account_id="1", api_key="2")

    # Then I should receive an array of Metrics
    result = c.get_metric_data("foo", "bar", "baz", "foobar", "foobaz")
    result.should.be.a('list')
    result[0].should.be.a('pyrelic.Metric')
Exemplo n.º 12
0
def test_delete_applications():
    httpretty.register_uri(httpretty.POST,
                           NEW_RELIC_REGEX,
                           body=DELETE_APPLICATION_SUCCESS_SAMPLE,
                           status=200
                           )
    # When I make an API request to view threshold values
    c = Client(account_id="1", api_key="2")

    # Then I should receive an array of Threshold values
    result = c.delete_applications({"app_id": "1234"})
    result.should.have.length_of(1)
Exemplo n.º 13
0
def test_get_threshold_values():
    httpretty.register_uri(httpretty.GET,
                           NEW_RELIC_REGEX,
                           body=THRESHOLD_VALUES_SAMPLE,
                           status=200)
    # When I make an API request to view threshold values
    c = Client(account_id="1", api_key="2")

    # Then I should receive an array of Threshold values
    result = c.get_threshold_values("foo")
    result.should.be.a('list')
    result[0].should.be.a('pyrelic.Threshold')
Exemplo n.º 14
0
def test_view_applications():
    httpretty.register_uri(httpretty.GET, NEW_RELIC_REGEX,
                           body=VIEW_APPLICATIONS_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
    c.view_applications().should.be.an('list')
    c.view_applications()[0].should.be.an('pyrelic.Application')
Exemplo n.º 15
0
def test_api_rate_limit_exceeded_inside_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)
Exemplo n.º 16
0
def test_api_rate_limit_exceeded_inside_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)
Exemplo n.º 17
0
def test_get_threshold_values():
    httpretty.register_uri(httpretty.GET,
                           NEW_RELIC_REGEX,
                           body=THRESHOLD_VALUES_SAMPLE,
                           status=200
                           )
    # When I make an API request to view threshold values
    c = Client(account_id="1", api_key="2")

    # Then I should receive an array of Threshold values
    result = c.get_threshold_values("foo")
    result.should.be.a('list')
    result[0].should.be.a('pyrelic.Threshold')
Exemplo n.º 18
0
def test_get_metric_data():
    httpretty.register_uri(httpretty.GET,
                           NEW_RELIC_REGEX,
                           body=METRIC_DATA_SAMPLE,
                           status=200
                           )
    # When I make an API request to get metric data
    c = Client(account_id="1", api_key="2")

    # Then I should receive an array of Metrics
    result = c.get_metric_data("foo", "bar", "baz", "foobar", "foobaz")
    result.should.be.a('list')
    result[0].should.be.a('pyrelic.Metric')
Exemplo n.º 19
0
def test_delete_servers_success():
    """
    Client should be able to delete Servers
    """
    httpretty.register_uri(httpretty.DELETE,
                           NEW_RELIC_REGEX,
                           body=DELETE_SERVERS_SUCCESS_SAMPLE,
                           status=200)
    # When I make an API request to delete a server
    c = Client(account_id="1", api_key="2")
    result = c.delete_servers(server_id="123456")

    # Then I should receive an array of failed deletions
    result.should.equal([])
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
def test_delete_servers_success():
    """
    Client should be able to delete Servers
    """
    httpretty.register_uri(httpretty.DELETE,
                           NEW_RELIC_REGEX,
                           body=DELETE_SERVERS_SUCCESS_SAMPLE,
                           status=200
                           )
    # When I make an API request to delete a server
    c = Client(account_id="1", api_key="2")
    result = c.delete_servers(server_id="123456")

    # Then I should receive an array of failed deletions
    result.should.equal([])
Exemplo n.º 22
0
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)
Exemplo n.º 23
0
def test_handle_api_error_422():
    # When I make an API request and receive a 400
    c = Client(account_id="foo", api_key="bar")
    response = Mock(status_code=422)
    error = Mock(message="foo", response=response)

    # Then I should raise a NewRelicApiException
    c._handle_api_error.when.called_with(error)\
        .should.throw(NewRelicInvalidParameterException)
Exemplo n.º 24
0
def test_handle_api_error_403():
    """
    Client should raise API key error on HTTP 403
    """
    # When I make an API request and receive a 403
    c = Client(account_id="foo", api_key="bar")
    response = Mock(status_code=403)
    error = Mock(message="foo", response=response)

    # Then I should raise a NewRelicApiException
    c._handle_api_error.when.called_with(error)\
        .should.throw(NewRelicInvalidApiKeyException)
Exemplo n.º 25
0
def test_handle_api_error_404():
    """
    Client should raise Unknown Application error on HTTP 404
    """
    # When I make an API request and receive a 404
    c = Client(account_id="foo", api_key="bar")
    response = Mock(status_code=404)
    error = Mock(message="foo", response=response)

    # Then I should raise a NewRelicApiException
    c._handle_api_error.when.called_with(error)\
        .should.throw(NewRelicUnknownApplicationException)
Exemplo n.º 26
0
def test_notify_deployment_failure():
    """
    Client should fail to notify_deployment with bad data
    """
    httpretty.register_uri(httpretty.POST,
                           NEW_RELIC_REGEX,
                           body=NOTIFY_DEPLOYMENT_SUCCESS,
                           status=200)
    # When I make an API request to notify of deployment with no arguments
    c = Client(account_id="1", api_key="2")

    # Then I should receive a failure
    c.notify_deployment.when.called_with(None).should.throw(
        NewRelicInvalidParameterException)
Exemplo n.º 27
0
def test_notify_deployment_by_name_success():
    """
    Client should be able to notify deployments with application name
    """
    httpretty.register_uri(httpretty.POST,
                           NEW_RELIC_REGEX,
                           body=NOTIFY_DEPLOYMENT_SUCCESS,
                           status=200
                           )
    # When I make an API request to notify of deployment
    c = Client(account_id="1", api_key="2")

    # Then I should receive a valid response
    result = c.notify_deployment(application_name=123, description='description',
                                 revision='1.2.3', user='******',
                                 changelog='orange')

    result.should.be.an('dict')

    result.should.have.key('account-id')
    result['account-id'].should.equal('123')

    result.should.have.key('agent-id')
    result['agent-id'].should.equal('456')
Exemplo n.º 28
0
def test_view_applications():
    httpretty.register_uri(httpretty.GET,
                           NEW_RELIC_REGEX,
                           body=VIEW_APPLICATIONS_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
    c.view_applications().should.be.an('list')
    c.view_applications()[0].should.be.an('pyrelic.Application')