Simple test: we can query the account-read page

This commit is contained in:
Martin Pépin 2017-05-23 20:38:53 +01:00
parent 74135f8877
commit 3a69c3371f

57
kfet/tests/test_views.py Normal file
View file

@ -0,0 +1,57 @@
from decimal import Decimal
from django.test import TestCase, Client
from django.contrib.auth.models import User
from django.utils import timezone
from ..models import Account, OperationGroup, Checkout, Operation
class AccountTests(TestCase):
"""Account related views"""
def setUp(self):
# A user and its account
self.user = User.objects.create_user(username="foobar", password="foo")
acc = Account.objects.create(
trigramme="FOO", cofprofile=self.user.profile
)
# Dummy operations and operation groups
checkout = Checkout.objects.create(
created_by=acc, name="checkout",
valid_from=timezone.now(),
valid_to=timezone.now() + timezone.timedelta(days=365)
)
opeg_data = [
(timezone.now(), Decimal('10')),
(timezone.now() - timezone.timedelta(days=3), Decimal('3')),
]
OperationGroup.objects.bulk_create([
OperationGroup(
on_acc=acc, checkout=checkout, at=at, is_cof=False,
amount=amount
)
for (at, amount) in opeg_data
])
self.operation_groups = OperationGroup.objects.order_by("-amount")
Operation.objects.create(
group=self.operation_groups[0],
type=Operation.PURCHASE,
amount=Decimal('10')
)
Operation.objects.create(
group=self.operation_groups[1],
type=Operation.PURCHASE,
amount=Decimal('3')
)
def test_account_read(self):
"""We can query the "Accout - Read" page."""
client = Client()
self.assertTrue(client.login(
username="foobar",
password="foo"
))
resp = client.get("/k-fet/accounts/FOO")
self.assertEqual(200, resp.status_code)