Skip to content
Snippets Groups Projects
Commit 531324ce authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unit tests for voucher_type_price views

parent f6f913ec
No related branches found
No related tags found
1 merge request!112Resolve "voucher types"
Pipeline #
...@@ -6,7 +6,7 @@ from django.contrib.auth.models import User ...@@ -6,7 +6,7 @@ from django.contrib.auth.models import User
from web.models import Location, AppointmentType, StudySubject, Worker, Visit, Appointment, ConfigurationItem, \ from web.models import Location, AppointmentType, StudySubject, Worker, Visit, Appointment, ConfigurationItem, \
Language, ContactAttempt, FlyingTeam, Availability, Subject, Study, StudyColumns, StudyNotificationParameters, \ Language, ContactAttempt, FlyingTeam, Availability, Subject, Study, StudyColumns, StudyNotificationParameters, \
VoucherType VoucherType, VoucherTypePrice
from web.models.constants import REDCAP_TOKEN_CONFIGURATION_TYPE, REDCAP_BASE_URL_CONFIGURATION_TYPE, \ from web.models.constants import REDCAP_TOKEN_CONFIGURATION_TYPE, REDCAP_BASE_URL_CONFIGURATION_TYPE, \
SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL, CONTACT_TYPES_PHONE, \ SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL, CONTACT_TYPES_PHONE, \
MONDAY_AS_DAY_OF_WEEK, COUNTRY_AFGHANISTAN_ID MONDAY_AS_DAY_OF_WEEK, COUNTRY_AFGHANISTAN_ID
...@@ -31,6 +31,13 @@ def create_voucher_type(): ...@@ -31,6 +31,13 @@ def create_voucher_type():
return VoucherType.objects.create(code="X", study=get_test_study()) return VoucherType.objects.create(code="X", study=get_test_study())
def create_voucher_type_price():
return VoucherTypePrice.objects.create(voucher_type=create_voucher_type(),
price=12.34,
start_date=get_today_midnight_date(),
end_date=get_today_midnight_date())
def create_empty_study_columns(): def create_empty_study_columns():
study_columns = StudyColumns.objects.create( study_columns = StudyColumns.objects.create(
postponed=False, postponed=False,
...@@ -238,7 +245,9 @@ def get_resource_path(filename): ...@@ -238,7 +245,9 @@ def get_resource_path(filename):
def format_form_field(value): def format_form_field(value):
if isinstance(value, datetime.datetime): if isinstance(value, datetime.date):
return value.strftime('%Y-%m-%d')
elif isinstance(value, datetime.datetime):
return value.strftime('%Y-%m-%d %H:%M') return value.strftime('%Y-%m-%d %H:%M')
else: else:
return value return value
......
import logging
from django.urls import reverse
from web.forms.forms import VoucherTypePriceForm
from web.models import VoucherType, VoucherTypePrice
from web.tests.functions import create_voucher_type, create_voucher_type_price, format_form_field
from .. import LoggedInTestCase
logger = logging.getLogger(__name__)
class VoucherTypePriceViewTests(LoggedInTestCase):
def setUp(self):
super(VoucherTypePriceViewTests, self).setUp()
self.voucher_type = create_voucher_type()
def test_render_add_voucher_type_price_request(self):
url = reverse('web.views.voucher_type_price_add', kwargs={'voucher_type_id': self.voucher_type.id})
response = self.client.get(url
)
self.assertEqual(response.status_code, 200)
def test_render_edit_voucher_type_price_request(self):
voucher_type_price = create_voucher_type_price()
url = reverse('web.views.voucher_type_price_edit',
kwargs={'pk': voucher_type_price.id, 'voucher_type_id': self.voucher_type.id})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_add_voucher_type_price(self):
form_data = {
'price': "11.0",
'start_date': "2017-01-01",
'end_date': "2018-01-01"
}
url = reverse('web.views.voucher_type_price_add', kwargs={'voucher_type_id': self.voucher_type.id})
response = self.client.post(url, data=form_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(1, VoucherType.objects.all().count())
def test_edit_voucher_type_price(self):
voucher_type_price = create_voucher_type_price()
form = VoucherTypePriceForm(instance=voucher_type_price)
form_data = {}
for key, value in form.initial.items():
if value is not None:
form_data['{}'.format(key)] = format_form_field(value)
form_data['price'] = 90.50
url = reverse('web.views.voucher_type_price_edit',
kwargs={'pk': voucher_type_price.id, 'voucher_type_id': voucher_type_price.voucher_type.id})
response = self.client.post(url, data=form_data)
self.assertEqual(90.50, VoucherTypePrice.objects.get(id=voucher_type_price.id).price)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment