-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d74a2be
commit c0926ea
Showing
6 changed files
with
51 additions
and
40 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
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
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
24 changes: 3 additions & 21 deletions
24
django_project_base/notifications/tests/api/test_remainig_license.py
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,31 +1,13 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
from django_project_base.licensing.logic import LogAccessService | ||
from django_project_base.licensing.models import LicenseAccessUse | ||
from django_project_base.notifications.base.enums import ChannelIdentifier | ||
from django_project_base.notifications.tests.notifications_transaction_test_case import NotificationsTransactionTestCase | ||
|
||
|
||
class TestRemainingLicense(NotificationsTransactionTestCase): | ||
def test_remaining_license(self): | ||
used_amount = 10 | ||
mail = self.create_notification_email_object().send() | ||
LicenseAccessUse.objects.create( | ||
type=LicenseAccessUse.UseType.USE, | ||
user_id=str(self.test_user.pk), | ||
content_type_object_id=str(mail.pk), | ||
content_type=ContentType.objects.get_for_model(mail._meta.model), | ||
amount=-100, | ||
comment=dict(comment="", count=10, item_price=1, sender=""), | ||
) | ||
LicenseAccessUse.objects.create( | ||
type=LicenseAccessUse.UseType.USE, | ||
user_id=str(self.test_user.pk), | ||
content_type_object_id=str(mail.pk), | ||
content_type=ContentType.objects.get_for_model(mail._meta.model), | ||
amount=used_amount, | ||
comment=dict(comment="", count=10, item_price=1, sender=""), | ||
) | ||
log_service = LogAccessService() | ||
usage = log_service.report(user=self.test_user) | ||
credit = log_service._user_access_user_inflow(self.test_user.pk) | ||
self.assertEqual(credit - used_amount, usage["remaining_credit"]) | ||
channel = ChannelIdentifier.channel(mail.required_channels.split(",")[0], ensure_dlr_user=False) | ||
self.assertEqual(credit - channel.notification_price, usage["remaining_credit"]) |
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
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