test: add test for duplicate port constraint
This commit is contained in:
parent
fa002ce0f2
commit
114b141e2a
1 changed files with 31 additions and 0 deletions
|
|
@ -83,6 +83,37 @@ def test_reassign_blueprint_anytime(user_client_with_blueprints) -> None:
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_server_duplicate_port(user_client_with_blueprints) -> None:
|
||||||
|
client, data = user_client_with_blueprints
|
||||||
|
|
||||||
|
# Create the first server
|
||||||
|
response = client.post(
|
||||||
|
"/servers",
|
||||||
|
data={"name": "server-1", "port": "27015", "blueprint_id": str(data["blueprint_id"])},
|
||||||
|
headers={"X-CSRF-Token": "test-token"},
|
||||||
|
)
|
||||||
|
assert response.status_code == 302
|
||||||
|
|
||||||
|
# Try to create a second server with the same port
|
||||||
|
response = client.post(
|
||||||
|
"/servers",
|
||||||
|
data={"name": "server-2", "port": "27015", "blueprint_id": str(data["blueprint_id"])},
|
||||||
|
headers={"X-CSRF-Token": "test-token"},
|
||||||
|
)
|
||||||
|
assert response.status_code == 409
|
||||||
|
assert b"port already in use" in response.data
|
||||||
|
|
||||||
|
# Verify the second server was not created by checking how many servers exist
|
||||||
|
from sqlalchemy import select
|
||||||
|
from l4d2web.db import session_scope
|
||||||
|
from l4d2web.models import Server
|
||||||
|
|
||||||
|
with session_scope() as session:
|
||||||
|
servers = session.scalars(select(Server)).all()
|
||||||
|
assert len(servers) == 1
|
||||||
|
assert servers[0].name == "server-1"
|
||||||
|
|
||||||
|
|
||||||
def test_lifecycle_form_creates_queued_job(user_client_with_blueprints) -> None:
|
def test_lifecycle_form_creates_queued_job(user_client_with_blueprints) -> None:
|
||||||
client, data = user_client_with_blueprints
|
client, data = user_client_with_blueprints
|
||||||
create_response = client.post(
|
create_response = client.post(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue