test(campaigns): add EntityNotFoundError and reject-clears-approval coverage
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
"""Tests for the campaign manager-approval workflow."""
|
||||
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from app.models.campaign import Campaign, CampaignTest
|
||||
@@ -70,6 +72,12 @@ class TestSubmitCampaignForApproval:
|
||||
submitter_id=admin_user.id, submitter_role="admin",
|
||||
)
|
||||
|
||||
def test_submit_nonexistent_campaign_raises(self, db, admin_user):
|
||||
with pytest.raises(EntityNotFoundError):
|
||||
submit_campaign_for_approval(
|
||||
db, str(uuid.uuid4()), submitter_id=admin_user.id, submitter_role="admin",
|
||||
)
|
||||
|
||||
|
||||
class TestApproveCampaign:
|
||||
def test_approve_sets_start_date_and_activates(self, db, draft_campaign_with_test, admin_user):
|
||||
@@ -101,6 +109,12 @@ class TestApproveCampaign:
|
||||
approver_id=admin_user.id, start_date="2026-08-01T00:00:00",
|
||||
)
|
||||
|
||||
def test_approve_nonexistent_campaign_raises(self, db, admin_user):
|
||||
with pytest.raises(EntityNotFoundError):
|
||||
approve_campaign(
|
||||
db, str(uuid.uuid4()), approver_id=admin_user.id, start_date="2026-08-01T00:00:00",
|
||||
)
|
||||
|
||||
|
||||
class TestRejectCampaign:
|
||||
def test_reject_returns_to_draft_with_reason(self, db, draft_campaign_with_test, admin_user):
|
||||
@@ -126,3 +140,31 @@ class TestRejectCampaign:
|
||||
def test_reject_non_pending_raises(self, db, draft_campaign_with_test, admin_user):
|
||||
with pytest.raises(BusinessRuleViolation, match="pending approval"):
|
||||
reject_campaign(db, str(draft_campaign_with_test.id), rejecter_id=admin_user.id, reason="No")
|
||||
|
||||
def test_reject_clears_prior_approval_fields(self, db, draft_campaign_with_test, admin_user):
|
||||
submit_campaign_for_approval(
|
||||
db, str(draft_campaign_with_test.id), submitter_id=admin_user.id, submitter_role="admin",
|
||||
)
|
||||
db.commit()
|
||||
approve_campaign(
|
||||
db, str(draft_campaign_with_test.id),
|
||||
approver_id=admin_user.id, start_date="2026-08-01T00:00:00",
|
||||
)
|
||||
db.commit()
|
||||
# Simulate the campaign being sent back into the approval queue
|
||||
# (e.g. after a modification request) so reject_campaign has
|
||||
# approved_by/approved_at to clear.
|
||||
draft_campaign_with_test.status = "pending_approval"
|
||||
db.commit()
|
||||
|
||||
campaign = reject_campaign(
|
||||
db, str(draft_campaign_with_test.id),
|
||||
rejecter_id=admin_user.id, reason="Needs rework",
|
||||
)
|
||||
assert campaign.status == "draft"
|
||||
assert campaign.approved_by is None
|
||||
assert campaign.approved_at is None
|
||||
|
||||
def test_reject_nonexistent_campaign_raises(self, db, admin_user):
|
||||
with pytest.raises(EntityNotFoundError):
|
||||
reject_campaign(db, str(uuid.uuid4()), rejecter_id=admin_user.id, reason="No")
|
||||
|
||||
Reference in New Issue
Block a user