Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INT-131: support monitoring regions and jobtypes endpoint #55

Merged
merged 6 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ns1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ def notifylists(self):

return ns1.rest.monitoring.NotifyLists(self.config)

def monitoring_jobtypes(self):
"""
Return a new raw REST interface to monitoring jobtypes resources

:rtype: :py:class:`ns1.rest.monitoring.JobTypes`
"""
import ns1.rest.monitoring

return ns1.rest.monitoring.JobTypes(self.config)

def monitoring_regions(self):
"""
Return a new raw REST interface to monitoring regions resources

:rtype: :py:class:`ns1.rest.monitoring.Regions`
"""
import ns1.rest.monitoring

return ns1.rest.monitoring.Regions(self.config)

def plan(self):
"""
Return a new raw REST interface to account plan
Expand Down
22 changes: 22 additions & 0 deletions ns1/rest/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,25 @@ def delete(self, nlid, callback=None, errback=None):
callback=callback,
errback=errback,
)


class JobTypes(resource.BaseResource):

ROOT = "monitoring/jobtypes"
PASSTHRU_FIELDS = []

def list(self, callback=None, errback=None):
return self._make_request(
"GET", self.ROOT, callback=callback, errback=errback,
)


class Regions(resource.BaseResource):

ROOT = "monitoring/regions"
PASSTHRU_FIELDS = []

def list(self, callback=None, errback=None):
return self._make_request(
"GET", self.ROOT, callback=callback, errback=errback,
)
69 changes: 69 additions & 0 deletions tests/unit/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import pytest

from ns1 import NS1
from ns1.rest.account import Plan
from ns1.rest.apikey import APIKey
from ns1.rest.data import Feed, Source
from ns1.rest.ipam import (
Addresses,
Networks,
Reservations,
Scopegroups,
Scopes,
Optiondefs,
)
from ns1.rest.monitoring import JobTypes, Monitors, NotifyLists, Regions
from ns1.rest.records import Records
from ns1.rest.stats import Stats
from ns1.rest.team import Team
from ns1.rest.user import User
from ns1.rest.zones import Zones


@pytest.fixture
def ns1_config(config):
config.loadFromDict(
{
"endpoint": "api.nsone.net",
"default_key": "test1",
"keys": {
"test1": {
"key": "key-1",
"desc": "test key number 1",
"writeLock": True,
}
},
}
)

return config


@pytest.mark.parametrize(
"method, want",
[
("zones", Zones),
("records", Records),
("addresses", Addresses),
("networks", Networks),
("scope_groups", Scopegroups),
("reservations", Reservations),
("scopes", Scopes),
("optiondefs", Optiondefs),
("stats", Stats),
("datasource", Source),
("datafeed", Feed),
("monitors", Monitors),
("notifylists", NotifyLists),
("monitoring_jobtypes", JobTypes),
("monitoring_regions", Regions),
("plan", Plan),
("team", Team),
("user", User),
("apikey", APIKey),
],
)
def test_rest_interface(ns1_config, method, want):
client = NS1(config=ns1_config)
got = getattr(client, method)()
assert isinstance(got, want)
144 changes: 144 additions & 0 deletions tests/unit/test_monitoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import ns1.rest.monitoring
import pytest

try: # Python 3.3 +
import unittest.mock as mock
except ImportError:
import mock


@pytest.fixture
def monitoring_config(config):
config.loadFromDict(
{
"endpoint": "api.nsone.net",
"default_key": "test1",
"keys": {
"test1": {
"key": "key-1",
"desc": "test key number 1",
"writeLock": True,
}
},
}
)

return config


@pytest.mark.parametrize(
"op, args, method, url, kwargs",
[
(
"list",
None,
"GET",
"monitoring/jobs",
{"callback": None, "errback": None},
),
(
"create",
[{}],
"PUT",
"monitoring/jobs",
{"body": {}, "callback": None, "errback": None},
),
(
"retrieve",
["my-job-id"],
"GET",
"monitoring/jobs/my-job-id",
{"callback": None, "errback": None},
),
(
"update",
["my-job-id", {}],
"POST",
"monitoring/jobs/my-job-id",
{"body": {}, "callback": None, "errback": None},
),
(
"delete",
["my-job-id"],
"DELETE",
"monitoring/jobs/my-job-id",
{"callback": None, "errback": None},
),
],
)
def test_rest_monitoring_monitors(
monitoring_config, op, args, method, url, kwargs
):
m = ns1.rest.monitoring.Monitors(monitoring_config)
m._make_request = mock.MagicMock()
operation = getattr(m, op)
if args is not None:
operation(*args)
else:
operation()
m._make_request.assert_called_once_with(method, url, **kwargs)


@pytest.mark.parametrize(
"op, args, method, url, kwargs",
[
("list", None, "GET", "lists", {"callback": None, "errback": None}),
(
"create",
[{}],
"PUT",
"lists",
{"body": {}, "callback": None, "errback": None},
),
(
"retrieve",
["my-list-id"],
"GET",
"lists/my-list-id",
{"callback": None, "errback": None},
),
(
"update",
["my-list-id", {}],
"POST",
"lists/my-list-id",
{"body": {}, "callback": None, "errback": None},
),
(
"delete",
["my-list-id"],
"DELETE",
"lists/my-list-id",
{"callback": None, "errback": None},
),
],
)
def test_rest_monitoring_notifylists(
monitoring_config, op, args, method, url, kwargs
):
m = ns1.rest.monitoring.NotifyLists(monitoring_config)
m._make_request = mock.MagicMock()
operation = getattr(m, op)
if args is not None:
operation(*args)
else:
operation()
m._make_request.assert_called_once_with(method, url, **kwargs)


def test_rest_monitoring_jobtypes(monitoring_config):
m = ns1.rest.monitoring.JobTypes(monitoring_config)
m._make_request = mock.MagicMock()
m.list()
m._make_request.assert_called_once_with(
"GET", "monitoring/jobtypes", callback=None, errback=None
)


def test_rest_monitoring_regions(monitoring_config):
m = ns1.rest.monitoring.Regions(monitoring_config)
m._make_request = mock.MagicMock()
m.list()
m._make_request.assert_called_once_with(
"GET", "monitoring/regions", callback=None, errback=None
)