transaction: Add 'savepoint=True' explicitly in tests, if used.

We create savepoint at a couple of places in backend tests
to avoid rollback due to error raised within test's transaction.

This commit explicitly adds 'savepoint=True' at those places.
This commit is contained in:
Prakhar Pratyush
2024-11-22 00:25:41 +05:30
committed by Tim Abbott
parent fdcd518e26
commit 62b3e49075
2 changed files with 3 additions and 3 deletions

View File

@@ -1462,10 +1462,10 @@ Output:
"invite_only": orjson.dumps(invite_only).decode(),
}
post_data.update(extra_post_data)
# We wrap the API call with a 'transaction.atomic()' context
# We wrap the API call with a 'transaction.atomic' context
# manager as it helps us with NOT rolling back the entire
# test transaction due to error responses.
with transaction.atomic():
with transaction.atomic(savepoint=True):
result = self.api_post(
user,
"/api/v1/users/me/subscriptions",

View File

@@ -4124,7 +4124,7 @@ class SubscriptionRestApiTest(ZulipTestCase):
def thunk2() -> HttpResponse:
raise JsonableError("random failure")
with transaction.atomic(), self.assertRaises(JsonableError):
with transaction.atomic(savepoint=True), self.assertRaises(JsonableError):
# The atomic() wrapper helps to avoid JsonableError breaking
# the test's transaction.
compose_views([thunk1, thunk2])