def test_delete_zone(
        self,
        client,
        initial_apikey_data,
        zone_data,
        admin_apikey_integration
    ):
        res = client.post(
            "/api/v1/servers/localhost/zones",
            headers=admin_apikey_integration,
            data=json.dumps(zone_data),
            content_type="application/json"
        )
        data = res.get_json(force=True)
        data['rrsets'] = []

        validate_zone(data)
        assert res.status_code == 201

        zone_url_format = "/api/v1/servers/localhost/zones/{0}"
        zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
        res = client.delete(
            zone_url,
            headers=admin_apikey_integration
        )

        assert res.status_code == 204
    def test_get_multiple_zones(self, client, initial_data, zone_data,
                                basic_auth_admin_headers):
        res = client.post("/api/v1/pdnsadmin/zones",
                          headers=basic_auth_admin_headers,
                          data=json.dumps(zone_data),
                          content_type="application/json")
        data = res.get_json(force=True)
        data['rrsets'] = []

        validate_zone(data)
        assert res.status_code == 201

        res = client.get("/api/v1/pdnsadmin/zones",
                         headers=basic_auth_admin_headers)
        data = res.get_json(force=True)
        fake_domain = namedtuple("Domain", data[0].keys())(*data[0].values())
        domain_schema = DomainSchema(many=True)

        json.dumps(domain_schema.dump([fake_domain]))
        assert res.status_code == 200

        zone_url_format = "/api/v1/pdnsadmin/zones/{0}"
        zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
        res = client.delete(zone_url, headers=basic_auth_admin_headers)

        assert res.status_code == 204
Esempio n. 3
0
    def test_create_zone(
        self,
        client,
        common_data_mock,
        zone_data,
        admin_apikey,
        created_zone_data
    ):
        with patch('app.lib.helper.requests.request') as mock_post, \
             patch('app.blueprints.api.Domain') as mock_domain:
            mock_post.return_value.status_code = 201
            mock_post.return_value.content = json.dumps(created_zone_data)
            mock_post.return_value.headers = {}
            mock_domain.return_value.update.return_value = True

            res = client.post(
                "/api/v1/servers/localhost/zones",
                headers=admin_apikey,
                data=json.dumps(zone_data),
                content_type="application/json"
            )
            data = res.get_json(force=True)
            data['rrsets'] = []

            validate_zone(data)
            assert res.status_code == 201
    def test_delete_zone(self, client, initial_data, zone_data,
                         basic_auth_admin_headers):
        res = client.post("/api/v1/pdnsadmin/zones",
                          headers=basic_auth_admin_headers,
                          data=json.dumps(zone_data),
                          content_type="application/json")
        data = res.get_json(force=True)
        data['rrsets'] = []

        validate_zone(data)
        assert res.status_code == 201

        zone_url_format = "/api/v1/pdnsadmin/zones/{0}"
        zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
        res = client.delete(zone_url, headers=basic_auth_admin_headers)

        assert res.status_code == 204