diff --git a/ns1/rest/zones.py b/ns1/rest/zones.py index f930fec..ce833b6 100644 --- a/ns1/rest/zones.py +++ b/ns1/rest/zones.py @@ -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): diff --git a/tests/unit/test_zone.py b/tests/unit/test_zone.py index 68f9923..fa8e8df 100644 --- a/tests/unit/test_zone.py +++ b/tests/unit/test_zone.py @@ -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"