Skip to content

Commit

Permalink
Merge pull request #113 from ns1/added_zone_version_calls
Browse files Browse the repository at this point in the history
Added rest calls for version handling
  • Loading branch information
apantelopoulosNS1 authored Jul 6, 2023
2 parents 7bffc63 + 16809ed commit 31b6b4f
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
65 changes: 65 additions & 0 deletions ns1/rest/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,71 @@ def search(
errback=errback,
)

def list_versions(
self,
zone,
callback=None,
errback=None
):
request = "{}/{}/versions".format(self.ROOT, zone)
return self._make_request(
"GET",
request,
params={},
callback=callback,
errback=errback,
)

def create_version(
self,
zone,
force=False,
callback=None,
errback=None):
request = "{}/{}/versions?force={}".format(
self.ROOT, zone, str.lower(str(force))
)
return self._make_request(
"PUT",
request,
params={},
callback=callback,
errback=errback,
)

def activate_version(
self,
zone,
version_id,
callback=None,
errback=None):
request = "{}/{}/versions/{}/activate".format(
self.ROOT, zone, str(version_id)
)
return self._make_request(
"POST",
request,
params={},
callback=callback,
errback=errback,
)

def delete_version(
self,
zone,
version_id,
callback=None,
errback=None):
request = "{}/{}/versions/{}".format(
self.ROOT, zone, str(version_id)
)
return self._make_request(
"DELETE",
request,
params={},
callback=callback,
errback=errback,
)

# successive pages just extend the list of zones
def zone_list_pagination(curr_json, next_json):
Expand Down
55 changes: 55 additions & 0 deletions tests/unit/test_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,61 @@ def test_rest_zone_retrieve(zones_config, zone, url):
)


@pytest.mark.parametrize("zone, url", [("test.zone", "zones/test.zone/versions")])
def test_rest_zone_version_list(zones_config, zone, url):
z = ns1.rest.zones.Zones(zones_config)
z._make_request = mock.MagicMock()
z.list_versions(zone)
z._make_request.assert_called_once_with(
"GET",
url,
params={},
callback=None,
errback=None
)


@pytest.mark.parametrize("zone, url", [("test.zone", "zones/test.zone/versions?force=false")])
def test_rest_zone_version_create(zones_config, zone, url):
z = ns1.rest.zones.Zones(zones_config)
z._make_request = mock.MagicMock()
z.create_version(zone)
z._make_request.assert_called_once_with(
"PUT",
url,
params={},
callback=None,
errback=None
)


@pytest.mark.parametrize("zone, id, url", [("test.zone", 15, "zones/test.zone/versions/15/activate")])
def test_rest_zone_version_activate(zones_config, zone, id, url):
z = ns1.rest.zones.Zones(zones_config)
z._make_request = mock.MagicMock()
z.activate_version(zone, id)
z._make_request.assert_called_once_with(
"POST",
url,
params={},
callback=None,
errback=None
)


@pytest.mark.parametrize("zone, id, url", [("test.zone", 15, "zones/test.zone/versions/15")])
def test_rest_zone_version_delete(zones_config, zone, id, url):
z = ns1.rest.zones.Zones(zones_config)
z._make_request = mock.MagicMock()
z.delete_version(zone, id)
z._make_request.assert_called_once_with(
"DELETE",
url,
params={},
callback=None,
errback=None
)

def test_rest_zone_buildbody(zones_config):
z = ns1.rest.zones.Zones(zones_config)
zone = "test.zone"
Expand Down

0 comments on commit 31b6b4f

Please sign in to comment.