Last active
September 2, 2024 15:36
-
-
Save dmytrostriletskyi/37b90906e9ae124363fdfd3d4164690b to your computer and use it in GitHub Desktop.
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
from bdd import ( | |
case, | |
expect, | |
when, | |
) | |
class TestAccountService: | |
def test_transfer_money_with_insufficient_balance(self, enable_in_app_notifications, mock): | |
mock_send_in_app_notification = mock('app.notifications.in_app.send') | |
mock_send_email = mock('app.email.send') | |
receiver_account = AccountFactory() | |
with when('Sender account has insufficient balance'): | |
sender_account = AccountFactory(balance=0) | |
with database.managed_session() as session: | |
session.add_all([receiver_account, sender_account]) | |
with when('Pushing in-app notifications feature flag is enabled for sender account'): | |
enable_in_app_notifications(account=sender_account) | |
with case('Transfer money from one account to another'): | |
AccountService.transfer_money(from=sender_account, to=receiver_account, amount=100) | |
with expect('No transfers have been made'): | |
assert not sender_account.transfers | |
assert not receiver_account.transfers | |
with expect('Increase credit limit proposal is created'): | |
assert Proposal.get_last(account=sender_account, type=ProposalType.INCREASE_CREDIT_LIMIT) | |
with expect('Sender account receives insufficient balance in-app notification'): | |
mock_send_in_app_notification.assert_called_with( | |
account_id=sender_account.id, | |
type=InAppNotificationType.INSUFFICIENT_BALANCE, | |
expired_at=None, | |
) | |
with expect('Sender account receives insufficient balance e-mail'): | |
mock_send_email.assert_called_with( | |
account_id=sender_account.id, | |
type=EmailType.INSUFFICIENT_BALANCE, | |
expired_at=None, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment