Files
peeringdb-peeringdb/tests/test_maintenance.py
Stefan Pratter 2e8788b595 Support 202210 (#1286)
* Allow REALPEER to overwrite GHOSTPEER netixlan entry, if asn and IPv6/v4 addresses matches the IX-F Members Export information #983

* Lightweight user notification mechanism #758

* do not allow affiliation with a deleted organisation #953

* Improve readability when users have special permissions #659

* fix advanced search export when api-cache exist and no filters were supplied #1153

* Ops: Throttle strings with "Response size" should be renamed "Repeated request" #1168

* allow ixlan prefix to be changed / deleted regardless of existence of netixlans in the address space #924

* linting

* poetry relock

* remove debug code

* linting

* fixed Reset IX-F suggestions link non-functional #1253

* solved UI shows own email when viewing affiliation requests for an organization #1250

* Adjust "Add Facility" menu to include newly defined fields #1091

* Footer "Global System Statistics" should be cached within django instance, not updated with every page load #1283

* linting

* django-handleref to 1.1.0 and relock poetry

* GLOBAL_STATS_CACHE_DURATION default to 900 seconds

* remove vscode and idea

* remove Ctl/dev/docker-compose.debug.yml

* remove unsused variable

* rename STATS to __STATS

* linting

* regen docs
2022-11-08 11:25:32 -06:00

83 lines
2.4 KiB
Python

import json
import pytest
from django.test import Client, TestCase
from rest_framework.test import APIClient
import peeringdb_server.views as views
from peeringdb_server import maintenance, settings
from peeringdb_server.models import REFTAG_MAP, User
from .util import ClientCase
class TestMaintenanceMode(ClientCase):
@classmethod
def setUpTestData(cls):
super().setUpTestData()
cls.superuser = User.objects.create_user(
"su", "su@localhost", "su", is_superuser=True
)
cls.org = REFTAG_MAP["org"].objects.create(name="Test Org", status="ok")
@pytest.fixture(autouse=True)
def init_lockfile(self, tmpdir):
settings.MAINTENANCE_MODE_LOCKFILE = str(tmpdir.join("maintenance.lock"))
def test_signup(self):
"""
user signup should be blocked during maintenance
"""
maintenance.on()
client = Client()
resp = client.post("/register", data={})
assert resp.status_code == 503
assert "maintenance mode" in resp.content.decode()
maintenance.off()
def test_api(self):
"""
test that maintenance mode on blocks all write ops to the rest api
"""
# set maintenance on
maintenance.on()
# init api client
self.client = APIClient()
self.client.force_authenticate(self.superuser)
err_str = "in maintenance mode"
# GET requests should work as expected
r = self.client.get(f"/api/org/{self.org.id}", format="json")
content = json.loads(r.content)
assert r.status_code == 200
# POST should be blocked
r = self.client.post(
"/api/net", {"org_id": 1, "name": "Test net", "asn": 9000000}, format="json"
)
content = json.loads(r.content)
assert r.status_code == 503
assert err_str in content["meta"]["error"]
net = {"id": 1}
# PUT should be blocked
r = self.client.put("/api/net/{}".format(net["id"]), net, format="json")
content = json.loads(r.content)
assert r.status_code == 503
assert err_str in content["meta"]["error"]
# DELETE should be blocked
r = self.client.delete("/api/net/{}".format(net["id"]), {}, format="json")
content = json.loads(r.content)
assert r.status_code == 503
assert err_str in content["meta"]["error"]
# set maintenance mode off
maintenance.off()