-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent sentry errors for on premise subscriptions (#2948)
- Loading branch information
1 parent
7d16197
commit 6f830e2
Showing
2 changed files
with
30 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import json | ||
from datetime import datetime, timedelta | ||
from typing import Type | ||
from unittest import TestCase, mock | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from _pytest.logging import LogCaptureFixture | ||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.core import mail | ||
from django.db.models import Model | ||
from django.urls import reverse | ||
from freezegun import freeze_time | ||
from pytz import UTC | ||
|
@@ -718,24 +721,35 @@ def test_when_cancelled_subscription_is_renewed_then_subscription_activated_and_ | |
# and | ||
assert not mail.outbox | ||
|
||
def test_when_chargebee_webhook_received_with_unknown_subscription_id_then_404( | ||
self, | ||
): | ||
# Given | ||
data = { | ||
"content": { | ||
"subscription": {"status": "active", "id": "some-random-id"}, | ||
"customer": {"email": self.cb_user.email}, | ||
} | ||
|
||
def test_when_chargebee_webhook_received_with_unknown_subscription_id_then_200( | ||
api_client: APIClient, caplog: LogCaptureFixture, django_user_model: Type[Model] | ||
): | ||
# Given | ||
subscription_id = "some-random-id" | ||
cb_user = django_user_model.objects.create(email="[email protected]", is_staff=True) | ||
api_client.force_authenticate(cb_user) | ||
|
||
data = { | ||
"content": { | ||
"subscription": {"status": "active", "id": subscription_id}, | ||
"customer": {"email": cb_user.email}, | ||
} | ||
} | ||
url = reverse("api-v1:chargebee-webhook") | ||
|
||
# When | ||
res = self.client.post( | ||
self.url, data=json.dumps(data), content_type="application/json" | ||
) | ||
# When | ||
res = api_client.post(url, data=json.dumps(data), content_type="application/json") | ||
|
||
# Then | ||
assert res.status_code == status.HTTP_200_OK | ||
# Then | ||
assert res.status_code == status.HTTP_200_OK | ||
|
||
assert len(caplog.records) == 1 | ||
assert caplog.record_tuples[0] == ( | ||
"organisations.views", | ||
30, | ||
f"Couldn't get unique subscription for ChargeBee id {subscription_id}", | ||
) | ||
|
||
|
||
@pytest.mark.django_db | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6f830e2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-staging – ./frontend
flagsmith-frontend-staging-flagsmith.vercel.app
flagsmith-frontend-staging-git-main-flagsmith.vercel.app
staging.flagsmith.com
flagsmith-staging-frontend.vercel.app
6f830e2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./docs
docs.bullet-train.io
docs-flagsmith.vercel.app
docs.flagsmith.com
docs-git-main-flagsmith.vercel.app
6f830e2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-preview – ./frontend
flagsmith-frontend-preview-git-main-flagsmith.vercel.app
flagsmith-frontend-production-native.vercel.app
flagsmith-frontend-preview-flagsmith.vercel.app