diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2017-07-12 12:52:43 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2017-07-12 12:52:43 +0200 |
commit | e9bb1a6626eafa162efdb24817073c1b9755eee0 (patch) | |
tree | ff869002127f3b0e2478d85a32716340eec3b096 /talerbank/app/tests.py | |
parent | 7293a1870c4d45a9a94a759cf51d45c7a4a334a8 (diff) | |
download | bank-e9bb1a6626eafa162efdb24817073c1b9755eee0.tar.gz bank-e9bb1a6626eafa162efdb24817073c1b9755eee0.tar.bz2 bank-e9bb1a6626eafa162efdb24817073c1b9755eee0.zip |
Unifying all tests in one file.
Diffstat (limited to 'talerbank/app/tests.py')
-rw-r--r-- | talerbank/app/tests.py | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py index 092d21c..5ccc660 100644 --- a/talerbank/app/tests.py +++ b/talerbank/app/tests.py @@ -57,6 +57,31 @@ class RegisterTestCase(TestCase): self.assertEqual(200, response.status_code) +class RegisterWrongCurrencyTestCase(TestCase): + """User registration""" + + # Activating this user with a faulty currency. + def setUp(self): + bank = User.objects.create_user(username='Bank') + ba = BankAccount(user=bank, currency="XYZ") + ba.account_no = 1 + ba.save() + + def tearDown(self): + clearDb() + + def test_register(self): + c = Client() + response = c.post(reverse("register", urlconf=urls), + {"username": "test_register", + "password": "test_register"}, + follow=True) + # A currency mismatch is expected when the 100 KUDOS will be + # attempted to be given to the new user. + # This scenario expects a 500 Internal server error response to + # be returned. + self.assertEqual(500, response.status_code) + class LoginTestCase(TestCase): """User login""" @@ -78,6 +103,15 @@ class LoginTestCase(TestCase): follow=True) self.assertIn(("/profile", 302), response.redirect_chain) + # Send wrong password + response = c.post(reverse("login", urlconf=urls), + {"username": "test_user", + "password": "test_passwordoo"}, + follow=True) + # The current logic -- django's default -- returns 200 OK + # even when the login didn't succeed. + # So the test here ensures that the bank just doesn't crash. + self.assertEqual(200, response.status_code) class AmountTestCase(TestCase): @@ -89,6 +123,19 @@ class AmountTestCase(TestCase): self.assertEqual(1, amounts.amount_cmp(a2, a1)) self.assertEqual(0, amounts.amount_cmp(a1, _a1)) + # Trying to compare amount of different currencies + def test_cmp_diff_curr(self): + a1 = dict(value=1, fraction=0, currency="X") + a2 = dict(value=2, fraction=0, currency="Y") + try: + amounts.amount_cmp(a1, a2) + except amounts.CurrencyMismatchException: + self.assertTrue(True) + return + # Should never get here + self.assertTrue(False) + + class AddIncomingTestCase(TestCase): """Test money transfer's API""" @@ -138,6 +185,23 @@ class AddIncomingTestCase(TestCase): follow=True, **{"HTTP_X_TALER_BANK_USERNAME": "user_user", "HTTP_X_TALER_BANK_PASSWORD": "user_password"}) self.assertEqual(406, response.status_code) + # Try to go debit + data = '{"auth": {"type": "basic"}, \ + "credit_account": 1, \ + "wtid": "TESTWTID", \ + "exchange_url": "https://exchange.test", \ + "amount": \ + {"value": 50, \ + "fraction": 1, \ + "currency": "%s"}}' \ + % settings.TALER_CURRENCY + response = c.post(reverse("add-incoming", urlconf=urls), + data=data, + content_type="application/json", + follow=True, **{"HTTP_X_TALER_BANK_USERNAME": "user_user", "HTTP_X_TALER_BANK_PASSWORD": "user_password"}) + self.assertEqual(403, response.status_code) + + class HistoryTestCase(TestCase): def setUp(self): @@ -169,7 +233,7 @@ class HistoryTestCase(TestCase): **{"HTTP_X_TALER_BANK_USERNAME": "User", "HTTP_X_TALER_BANK_PASSWORD": "Password"}) self.assertEqual(200, response.status_code) - # Get a delta=+1 record in the middle of the list: FAILS + # Get a delta=+1 record in the middle of the list response = c.get(reverse("history", urlconf=urls), {"auth": "basic", "delta": "+1", "start": "5"}, **{"HTTP_X_TALER_BANK_USERNAME": "User", "HTTP_X_TALER_BANK_PASSWORD": "Password"}) data = response.content.decode("utf-8") @@ -204,8 +268,7 @@ class HistoryTestCase(TestCase): self.assertEqual(404, response.status_code) -# This tests whether a bank account goes red and then -## goes green again +# This tests whether a bank account goes debit and then goes >=0 again class DebitTestCase(TestCase): def setUp(self): |