Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion strr-api/src/strr_api/resources/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def create_application(application_number: Optional[str] = None):
http_status=HTTPStatus.BAD_REQUEST,
)

if request.method == "PUT" and existing_registration_id != registration_id:
# An existing application must already be a renewal of this registration, whether it's saved by PUT or
# POST; otherwise a regular draft could be turned into a renewal past the window and in-progress checks
if application is not None and existing_registration_id != registration_id:
return error_response(
message=ErrorMessage.REGISTRATION_ID_MISMATCH.value,
http_status=HTTPStatus.BAD_REQUEST,
Expand Down
24 changes: 24 additions & 0 deletions strr-api/tests/unit/resources/test_renewal_window_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest

from strr_api.enums.enum import ApplicationType, ErrorMessage
from strr_api.models import Application
from tests.integration.application_seed import host_renewal_application_json
from tests.shared_test_constants import MOCK_INVOICE_RESPONSE
Expand All @@ -31,6 +32,29 @@ def test_new_renewal_draft_is_refused_before_window(mock_invoice, client, renewa
assert Application.query.filter_by(registration_id=registration.id).count() == 0


@pytest.mark.parametrize("days_to_expiry", [200, -(3 * 365 + 60)]) # before the window opens; after it closes
@pytest.mark.parametrize("method", ["post", "put"])
def test_regular_draft_cannot_become_renewal_outside_window(
client, renewal_headers, make_registration, days_to_expiry, method
):
with open(HOST_REGISTRATION) as f:
base_json = json.load(f)
draft_headers = {**renewal_headers, "isDraft": True}
rv = client.post("/applications", json=base_json, headers=draft_headers)
assert rv.status_code == HTTPStatus.OK
number = rv.json["header"]["applicationNumber"]
registration = make_registration(days_to_expiry)
payload = host_renewal_application_json(registration.id, base_json=base_json)

rv = getattr(client, method)(f"/applications/{number}", json=payload, headers=draft_headers)

assert rv.status_code == HTTPStatus.BAD_REQUEST
assert rv.json["message"] == ErrorMessage.REGISTRATION_ID_MISMATCH.value
application = Application.find_by_application_number(number)
assert application.type == ApplicationType.REGISTRATION.value
assert application.registration_id is None


@pytest.mark.parametrize(
"expiry_shift_days, error_code",
[
Expand Down