mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
* remove log file writing from migration * run tests on mysql * fix tests (pt.1) * fix tests (pt.2) * fix all user_id errors in tests * Fix geocode typo * More test changes for mysql id issues * Add coverage config that defines coverage db should go inside test folder * update docs * fix mysql user * fix tests cli * add mysql collate settings * docs * fix sync * fix sync * docs * remove debug output * remove XXX * interim commit to move to dev box * mv db local, rm after run * updates for 724 * note layer error message and work around * fix travis * chown tests * more travis fixes * travis: touch Ctl/dev/.env * write coverage report to ./coverage * clean up docs * formatting Co-authored-by: Stefan Pratter <stefan@20c.com> Co-authored-by: Elliot Frank <elliot@20c.com>
84 lines
2.4 KiB
Python
84 lines
2.4 KiB
Python
import py.test
|
|
import pytest
|
|
import json
|
|
|
|
from rest_framework.test import APIClient
|
|
from django.test import Client, TestCase
|
|
|
|
from peeringdb_server import maintenance, settings
|
|
from peeringdb_server.models import REFTAG_MAP, User
|
|
import peeringdb_server.views as views
|
|
|
|
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("/api/org/{}".format(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()
|