-
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.
- Loading branch information
1 parent
ad176f4
commit e094b4a
Showing
16 changed files
with
248 additions
and
30 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.5 on 2017-03-02 13:59 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('foobar', '0019_auto_20170221_1547'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='account', | ||
name='email', | ||
field=models.EmailField(blank=True, max_length=254, null=True), | ||
), | ||
] |
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
body{ | ||
margin: 0; | ||
font-size: 26px; | ||
} | ||
.info { | ||
background: #dfd; | ||
padding: 10px; | ||
color: #333; | ||
text-align: center; | ||
} | ||
#header{ | ||
background: #a70d0d; | ||
font-size: 350%; | ||
padding: 2%; | ||
color: white; | ||
text-align: center; | ||
margin: auto; | ||
border-bottom: 5px solid #d34a4a; | ||
} | ||
.account_form{ | ||
font-size: 180%; | ||
width: 70%; | ||
margin: auto; | ||
padding-top: 5% | ||
} | ||
.account_form >*{ | ||
width: 100%; | ||
height: 40px; | ||
margin: 10px; | ||
outline-color: #a70d0d; | ||
} | ||
input{ | ||
font-size: 26px; | ||
} | ||
#submit_changes{ | ||
background: #a70d0d; | ||
color: white; | ||
border: none; | ||
padding: 5px; | ||
height: 60px; | ||
font-size: 100%; | ||
-webkit-appearance: none; | ||
border-radius: 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% extends 'profile/base_profile.html' %} | ||
{% load i18n %} | ||
{% block content %} | ||
<div class="account_form" style="text-align:center;">{% trans "Invalid QRcode" %} <br> {% trans "Login to get a new" %} </div> | ||
{% endblock %} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> | ||
<title>FooBar</title> | ||
<link rel="stylesheet" type="text/css" href="/static/css/profile.css"/> | ||
</head> | ||
<body> | ||
{% load i18n %} | ||
<div id="header" > | ||
{% trans "Profile Details" %} | ||
</div> | ||
{% block content %} | ||
{% endblock %} | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends 'profile/base_profile.html' %} | ||
{% load i18n %} | ||
{% block content %} | ||
<div style="width:100%; height:30px;"> | ||
{% if messages %} | ||
{% for message in messages %} | ||
<div class="info">{{ message }}</div> | ||
{% endfor %} | ||
{% endif %} | ||
</div> | ||
<form class="account_form" method="post" action=""> | ||
{% csrf_token %} | ||
{{ form }} | ||
<input type="submit" name="save_changes" value="{% trans 'Save' %} " id="submit_changes" value="{{ account_email }}"> | ||
</form> | ||
|
||
{% endblock %} |
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from .factories import AccountFactory, CardFactory | ||
from moneyed import Money | ||
from django.contrib.auth.models import User | ||
import uuid | ||
|
||
|
||
class FoobarAPITest(TestCase): | ||
|
@@ -27,19 +28,41 @@ def test_get_card(self): | |
self.assertGreater(obj2.date_used, date_used) | ||
|
||
def test_get_account(self): | ||
# Assure None when missing account | ||
id = uuid.uuid4() | ||
obj1 = api.get_account(account_id=id) | ||
self.assertIsNone(obj1) | ||
|
||
# Create an account | ||
account_obj = AccountFactory.create() | ||
obj2 = api.get_account(account_id=account_obj.id) | ||
|
||
self.assertIsNotNone(obj2) | ||
|
||
def test_get_account_by_card(self): | ||
# Retrieve an non-existent account | ||
obj1 = api.get_account(card_id=1337) | ||
obj1 = api.get_account_by_card(card_id=1337) | ||
self.assertIsNone(obj1) | ||
|
||
# Create an account | ||
CardFactory.create(number=1337) | ||
obj2 = api.get_account(card_id=1337) | ||
obj2 = api.get_account_by_card(card_id=1337) | ||
|
||
self.assertIsNotNone(obj2) | ||
|
||
account_objs = models.Account.objects.filter(id=obj2.id) | ||
self.assertEqual(account_objs.count(), 1) | ||
|
||
def test_update_account(self): | ||
account_obj = AccountFactory.create() | ||
api.update_account(account_id=account_obj.id, | ||
name='1337', | ||
email='[email protected]') | ||
account = api.get_account(account_id=account_obj.id) | ||
# Test that correct fields are updated | ||
self.assertEqual('1337', account.name) | ||
self.assertEqual('[email protected]', account.email) | ||
|
||
def test_purchase(self): | ||
account_obj = AccountFactory.create() | ||
wallet_obj = WalletFactory.create(owner_id=account_obj.id) | ||
|
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from wallet.tests.factories import WalletFactory, WalletTrxFactory | ||
from wallet.enums import TrxType | ||
from . import factories | ||
from django.core import signing | ||
|
||
|
||
class FoobarViewTest(TestCase): | ||
|
@@ -23,7 +24,7 @@ def setUp(self): | |
password=self.TESTUSER_PASS | ||
) | ||
|
||
@mock.patch('foobar.api.get_account') | ||
@mock.patch('foobar.api.get_account_by_card') | ||
def test_account_for_card(self, mock_get_account): | ||
url = reverse('account_for_card', kwargs={'card_id': 1337}) | ||
mock_get_account.return_value = None | ||
|
@@ -53,38 +54,65 @@ def test_wallet_management(self, mock_deposit_withdrawal, mock_correction): | |
) | ||
url = reverse('wallet_management', | ||
kwargs={'obj_id': wallet_obj.owner_id}) | ||
cl = self.client | ||
# Test that deposit or withdrawal | ||
# is not called if balance will get negative | ||
response = cl.post(url, | ||
{'deposit_or_withdrawal_1': ['SEK'], | ||
'save_deposit': ['Submit'], | ||
'comment': ['test'], | ||
'deposit_or_withdrawal_0': ['-3000']}) | ||
response = self.client.post(url, | ||
{'deposit_or_withdrawal_1': ['SEK'], | ||
'save_deposit': ['Submit'], | ||
'comment': ['test'], | ||
'deposit_or_withdrawal_0': ['-3000']}) | ||
mock_deposit_withdrawal.assert_not_called() | ||
# Test that page can be found | ||
response = cl.get(url) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
# Test that correction form post is correct and | ||
# calls function with correct params | ||
response = cl.post(url, | ||
{'save_correction': ['Submit'], | ||
'balance_1': ['SEK'], | ||
'comment': ['test'], | ||
'balance_0': ['1000']}) | ||
self.client.post(url, | ||
{'save_correction': ['Submit'], | ||
'balance_1': ['SEK'], | ||
'comment': ['test'], | ||
'balance_0': ['1000']}) | ||
mock_correction.assert_called_with(Money(1000, 'SEK'), | ||
wallet_obj.owner_id, | ||
self.user, | ||
'test') | ||
# Test that deposit or withdrawal form post is correct and | ||
# calls fucnction with correct params | ||
response = cl.post(url, | ||
{'deposit_or_withdrawal_1': ['SEK'], | ||
'save_deposit': ['Submit'], | ||
'comment': ['test'], | ||
'deposit_or_withdrawal_0': ['100']}) | ||
self.client.post(url, | ||
{'deposit_or_withdrawal_1': ['SEK'], | ||
'save_deposit': ['Submit'], | ||
'comment': ['test'], | ||
'deposit_or_withdrawal_0': ['100']}) | ||
mock_deposit_withdrawal.assert_called_with( | ||
Money(100, 'SEK'), | ||
wallet_obj.owner_id, | ||
self.user, | ||
'test') | ||
|
||
@mock.patch('foobar.api.update_account') | ||
def test_edit_profile(self, mock_update_account): | ||
account_obj = factories.AccountFactory.create() | ||
token = signing.dumps({'id': str(account_obj.id)}) | ||
url = reverse('edit_profile', kwargs={'token': token}) | ||
bad_token = reverse('edit_profile', kwargs={'token': 'bad'}) | ||
response1 = self.client.get(url) | ||
response2 = self.client.get(bad_token) | ||
|
||
# Assert that page can be found | ||
self.assertEqual(response1.status_code, 200) | ||
self.assertEqual(response2.status_code, 200) | ||
|
||
# Assure update_account not called when url with bad token send POST | ||
self.client.post(bad_token, {'name': 'foo', | ||
'email': '[email protected]', | ||
'save_changes': ['Submit']}) | ||
mock_update_account.assert_not_called() | ||
|
||
# Assure set_balance is called when token is valid | ||
token_data = signing.loads(token, max_age=1800) | ||
self.client.post(url, {'name': 'foo', | ||
'email': '[email protected]', | ||
'save_changes': ['Submit']}) | ||
mock_update_account.assert_called_with(token_data.get('id'), | ||
name='foo', | ||
email='[email protected]') |
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
Oops, something went wrong.