-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not crash when the scanned card is not associated with any account
- Loading branch information
Showing
2 changed files
with
45 additions
and
10 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,19 +1,50 @@ | ||
from django.test import TestCase | ||
from wallet.tests.factories import WalletFactory, WalletTrxFactory | ||
from wallet.enums import TrxType | ||
from unittest import mock | ||
from moneyed import Money | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from unittest import mock | ||
from wallet.tests.factories import WalletFactory, WalletTrxFactory | ||
from wallet.enums import TrxType | ||
from . import factories | ||
|
||
|
||
class FoobarViewTest(TestCase): | ||
TESTUSER_NAME = 'the_baconator' | ||
TESTUSER_PASS = '123' | ||
|
||
def setUp(self): | ||
self.user = User.objects.create_superuser( | ||
self.TESTUSER_NAME, | ||
'[email protected]', | ||
self.TESTUSER_PASS | ||
) | ||
self.client.login( | ||
username=self.TESTUSER_NAME, | ||
password=self.TESTUSER_PASS | ||
) | ||
|
||
@mock.patch('foobar.api.get_account') | ||
def test_account_for_card(self, mock_get_account): | ||
url = reverse('account_for_card', kwargs={'card_id': 1337}) | ||
mock_get_account.return_value = None | ||
response = self.client.get(url, follow=True) | ||
self.assertRedirects( | ||
response, | ||
reverse('admin:foobar_account_changelist') | ||
) | ||
self.assertEqual(len(response.context['messages']), 1) | ||
account = factories.AccountFactory() | ||
mock_get_account.return_value = account | ||
response = self.client.get(url, follow=True) | ||
self.assertRedirects( | ||
response, | ||
reverse('admin:foobar_account_change', args=(account.id,)) | ||
) | ||
self.assertEqual(len(response.context['messages']), 0) | ||
|
||
@mock.patch('foobar.api.calculate_correction') | ||
@mock.patch('foobar.api.make_deposit_or_withdrawal') | ||
def test_wallet_management(self, mock_deposit_withdrawal, mock_correction): | ||
user = User.objects.create_superuser( | ||
'the_baconator', '[email protected]', '123' | ||
) | ||
wallet_obj = WalletFactory.create() | ||
WalletTrxFactory.create( | ||
wallet=wallet_obj, | ||
|
@@ -23,7 +54,6 @@ def test_wallet_management(self, mock_deposit_withdrawal, mock_correction): | |
url = reverse('wallet_management', | ||
kwargs={'obj_id': wallet_obj.owner_id}) | ||
cl = self.client | ||
cl.login(username='the_baconator', password='123') | ||
# Test that deposit or withdrawal | ||
# is not called if balance will get negative | ||
response = cl.post(url, | ||
|
@@ -44,7 +74,7 @@ def test_wallet_management(self, mock_deposit_withdrawal, mock_correction): | |
'balance_0': ['1000']}) | ||
mock_correction.assert_called_with(Money(1000, 'SEK'), | ||
wallet_obj.owner_id, | ||
user, | ||
self.user, | ||
'test') | ||
# Test that deposit or withdrawal form post is correct and | ||
# calls fucnction with correct params | ||
|
@@ -56,5 +86,5 @@ def test_wallet_management(self, mock_deposit_withdrawal, mock_correction): | |
mock_deposit_withdrawal.assert_called_with( | ||
Money(100, 'SEK'), | ||
wallet_obj.owner_id, | ||
user, | ||
self.user, | ||
'test') |
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