Commit 7c644bad authored by rexxnor's avatar rexxnor

improved test coverage and fixed a missing slash

parent b60745b2
......@@ -6,6 +6,7 @@ from django.utils import timezone
from django.test import TestCase
from django.test import Client
from django.contrib.auth.views import LoginView
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from prepaid.models import Card, Charge, Transaction, Report
from prepaid.views import chargecard, buydrink, checkbalance, CurrentReport
......@@ -305,61 +306,101 @@ class TestCheckBalance(TestCase):
self.assertTemplateUsed('balance.html.j2')
self.assertEqual(float(self.card3.current_balance), 40)
#class TestGenerateReport(TestCase):
# """
# Tests the monthly report
# """
# @classmethod
# def setUpClass(cls):
# super().setUpClass()
#
# @classmethod
# def tearDownClass(cls):
# super().tearDownClass()
#
# @classmethod
# def setUp(cls):
# """
# Create objects for tests
# """
# today = timezone.now()
# first = today.replace(day=1)
# last_month = first - timezone.timedelta(days=1) #- datetime.timedelta(days=1)
#
# cls.card4 = \
# Card.objects.create(username=4,
# current_balance=100,
# pin_hash=
# "f33ae3bc9a22cd7564990a794789954409977013966fb1a8f43c35776b833a95")
# cls.card4.save()
# cls.transaction = Transaction.objects.create(username=Card.objects.get(username=4),
# amount=20,
# date_time=last_month)
# cls.transaction.save()
# cls.charge = Charge.objects.create(username=Card.objects.get(username=4),
# amount=50,
# date_time=last_month)
#
# def test_availibility(self):
# """
# Test if report is rendered correctly without error
# """
# client = Client()
# response = client.get('/currentreport/')
# self.assertEqual(response.status_code, 200)
# self.assertTemplateUsed('currentreport.html.j2')
#
# def test_report_values(self):
# """
# Test if report values are correct
# """
# client = Client()
# response = client.get('/currentreport/')
# self.assertEqual(response.status_code, 200)
# self.assertTemplateUsed('currentreport.html.j2')
# self.assertContains(response, str("100.0"))
# self.assertContains(response, str("20.0"))
# self.assertContains(response, str("50.0"))
class TestGenerateReport(TestCase):
"""
Tests the monthly report
"""
@classmethod
def setUpClass(cls):
super().setUpClass()
@classmethod
def tearDownClass(cls):
super().tearDownClass()
@classmethod
def setUp(cls):
"""
Create objects for tests
"""
today = timezone.now()
first = today.replace(day=1)
last_month = first - timezone.timedelta(days=1) #- datetime.timedelta(days=1)
cls.last_month = last_month
cls.card4 = \
Card.objects.create(username=4,
current_balance=100,
password=
"f33ae3bc9a22cd7564990a794789954409977013966fb1a8f43c35776b833a95")
cls.card4.save()
cls.transaction = Transaction.objects.create(username=Card.objects.get(username=4),
amount=20,
date_time=last_month)
cls.transaction.save()
cls.charge = Charge.objects.create(username=Card.objects.get(username=4),
amount=50,
date_time=last_month)
cls.admin = User.objects.create_superuser('admin',
'myemail@test.com',
'mrGPfaG3N978ob8QGQTZMMjjmM8jJxKs')
def test_availibility(self):
"""
Test if report is rendered correctly without error
"""
client = Client()
client.login(username='admin', password='mrGPfaG3N978ob8QGQTZMMjjmM8jJxKs')
response = client.get('/admin/prepaid/report/currentreport/')
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed('currentreport.html.j2')
def test_report_values(self):
"""
Test if report values are correct
"""
client = Client()
client.login(username='admin', password='mrGPfaG3N978ob8QGQTZMMjjmM8jJxKs')
response = client.get('/admin/prepaid/report/currentreport/')
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed('currentreport.html.j2')
self.assertContains(response, str("100.0"))
self.assertContains(response, str("20.0"))
self.assertContains(response, str("50.0"))
def test_report_commit(self):
"""
Test if report is commited correctly
"""
client = Client()
client.login(username='admin', password='mrGPfaG3N978ob8QGQTZMMjjmM8jJxKs')
response = client.post('/admin/prepaid/report/currentreport/')
self.assertRedirects(response, '/admin/prepaid/report/periodreport/1/', target_status_code=200)
self.assertTemplateUsed('periodreport.html.j2')
def test_month_archive_view(self):
"""
Test the month archive view
"""
client = Client()
client.login(username='admin', password='mrGPfaG3N978ob8QGQTZMMjjmM8jJxKs')
response = client.get('/admin/prepaid/report/monthlyreport/%s/%s/' %
(self.last_month.year, self.last_month.month))
self.assertTemplateUsed('prepaid/transaction_archive_month.html')
self.assertContains(response, str("20.0"))
self.assertContains(response, str("50.0"))
def test_year_archive_view(self):
"""
Test the year archive view
"""
client = Client()
client.login(username='admin', password='mrGPfaG3N978ob8QGQTZMMjjmM8jJxKs')
response = client.get('/admin/prepaid/report/yearlyreport/%s/' %
(self.last_month.year))
self.assertTemplateUsed('prepaid/transaction_archive_year.html')
self.assertContains(response, str("20.0"))
self.assertContains(response, str("50.0"))
class TestGenericViews(TestCase):
"""
......
......@@ -368,4 +368,4 @@ class CurrentReport(TemplateView):
charge.save()
# Redirect to the periodreport view
return redirect('../periodreport/%d' % report.report_id)
return redirect('../periodreport/%d/' % report.report_id)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment