mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-12 17:49:41 +00:00
Add tests for the client side authorisation
This commit is contained in:
@@ -231,6 +231,7 @@ class EventAuthorise(generic.UpdateView):
|
|||||||
success_template = 'RIGS/eventauthorisation_success.html'
|
success_template = 'RIGS/eventauthorisation_success.html'
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
self.object = form.save()
|
||||||
# TODO: send email confirmation
|
# TODO: send email confirmation
|
||||||
self.template_name = self.success_template
|
self.template_name = self.success_template
|
||||||
messages.add_message(self.request, messages.SUCCESS,
|
messages.add_message(self.request, messages.SUCCESS,
|
||||||
@@ -242,7 +243,7 @@ class EventAuthorise(generic.UpdateView):
|
|||||||
return models.Event.objects.select_related('organisation', 'person', 'venue').get(pk=self.kwargs['pk'])
|
return models.Event.objects.select_related('organisation', 'person', 'venue').get(pk=self.kwargs['pk'])
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
return self.event.authorisation
|
return getattr(self.event, 'authorisation', None)
|
||||||
|
|
||||||
def get_form_class(self):
|
def get_form_class(self):
|
||||||
if self.event.organisation is not None and self.event.organisation.union_account:
|
if self.event.organisation is not None and self.event.organisation.union_account:
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import re
|
|||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
|
||||||
import reversion
|
import reversion
|
||||||
from django.core import mail
|
from django.core import mail, signing
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.test import LiveServerTestCase
|
from django.http import HttpResponseBadRequest
|
||||||
|
from django.test import LiveServerTestCase, TestCase
|
||||||
from django.test.client import Client
|
from django.test.client import Client
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.common.exceptions import StaleElementReferenceException, WebDriverException
|
from selenium.common.exceptions import StaleElementReferenceException, WebDriverException
|
||||||
@@ -17,7 +19,6 @@ from RIGS import models
|
|||||||
|
|
||||||
|
|
||||||
class UserRegistrationTest(LiveServerTestCase):
|
class UserRegistrationTest(LiveServerTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.browser = webdriver.Firefox()
|
self.browser = webdriver.Firefox()
|
||||||
self.browser.implicitly_wait(3) # Set implicit wait session wide
|
self.browser.implicitly_wait(3) # Set implicit wait session wide
|
||||||
@@ -149,7 +150,6 @@ class UserRegistrationTest(LiveServerTestCase):
|
|||||||
|
|
||||||
|
|
||||||
class EventTest(LiveServerTestCase):
|
class EventTest(LiveServerTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.profile = models.Profile(
|
self.profile = models.Profile(
|
||||||
username="EventTest", first_name="Event", last_name="Test", initials="ETU", is_superuser=True)
|
username="EventTest", first_name="Event", last_name="Test", initials="ETU", is_superuser=True)
|
||||||
@@ -370,7 +370,8 @@ class EventTest(LiveServerTestCase):
|
|||||||
wait.until(animation_is_finished())
|
wait.until(animation_is_finished())
|
||||||
modal = self.browser.find_element_by_id("itemModal")
|
modal = self.browser.find_element_by_id("itemModal")
|
||||||
modal.find_element_by_id("item_name").send_keys("Test Item 1")
|
modal.find_element_by_id("item_name").send_keys("Test Item 1")
|
||||||
modal.find_element_by_id("item_description").send_keys("This is an item description\nthat for reasons unkown spans two lines")
|
modal.find_element_by_id("item_description").send_keys(
|
||||||
|
"This is an item description\nthat for reasons unkown spans two lines")
|
||||||
e = modal.find_element_by_id("item_quantity")
|
e = modal.find_element_by_id("item_quantity")
|
||||||
e.click()
|
e.click()
|
||||||
e.send_keys(Keys.UP)
|
e.send_keys(Keys.UP)
|
||||||
@@ -389,7 +390,8 @@ class EventTest(LiveServerTestCase):
|
|||||||
# See new item appear in table
|
# See new item appear in table
|
||||||
row = self.browser.find_element_by_id('item--1') # ID number is known, see above
|
row = self.browser.find_element_by_id('item--1') # ID number is known, see above
|
||||||
self.assertIn("Test Item 1", row.find_element_by_xpath('//span[@class="name"]').text)
|
self.assertIn("Test Item 1", row.find_element_by_xpath('//span[@class="name"]').text)
|
||||||
self.assertIn("This is an item description", row.find_element_by_xpath('//div[@class="item-description"]').text)
|
self.assertIn("This is an item description",
|
||||||
|
row.find_element_by_xpath('//div[@class="item-description"]').text)
|
||||||
self.assertEqual(u'£ 23.95', row.find_element_by_xpath('//tr[@id="item--1"]/td[2]').text)
|
self.assertEqual(u'£ 23.95', row.find_element_by_xpath('//tr[@id="item--1"]/td[2]').text)
|
||||||
self.assertEqual("2", row.find_element_by_xpath('//td[@class="quantity"]').text)
|
self.assertEqual("2", row.find_element_by_xpath('//td[@class="quantity"]').text)
|
||||||
self.assertEqual(u'£ 47.90', row.find_element_by_xpath('//tr[@id="item--1"]/td[4]').text)
|
self.assertEqual(u'£ 47.90', row.find_element_by_xpath('//tr[@id="item--1"]/td[4]').text)
|
||||||
@@ -438,7 +440,9 @@ class EventTest(LiveServerTestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def testEventDuplicate(self):
|
def testEventDuplicate(self):
|
||||||
testEvent = models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL, start_date=date.today() + timedelta(days=6), description="start future no end", purchase_order="TESTPO")
|
testEvent = models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL,
|
||||||
|
start_date=date.today() + timedelta(days=6),
|
||||||
|
description="start future no end", purchase_order="TESTPO")
|
||||||
|
|
||||||
item1 = models.EventItem(
|
item1 = models.EventItem(
|
||||||
event=testEvent,
|
event=testEvent,
|
||||||
@@ -465,7 +469,6 @@ class EventTest(LiveServerTestCase):
|
|||||||
'(//button[@type="submit"])[3]')
|
'(//button[@type="submit"])[3]')
|
||||||
form = self.browser.find_element_by_tag_name('form')
|
form = self.browser.find_element_by_tag_name('form')
|
||||||
|
|
||||||
|
|
||||||
# Check the items are visible
|
# Check the items are visible
|
||||||
table = self.browser.find_element_by_id('item-table') # ID number is known, see above
|
table = self.browser.find_element_by_id('item-table') # ID number is known, see above
|
||||||
self.assertIn("Test Item 1", table.text)
|
self.assertIn("Test Item 1", table.text)
|
||||||
@@ -479,7 +482,8 @@ class EventTest(LiveServerTestCase):
|
|||||||
wait.until(animation_is_finished())
|
wait.until(animation_is_finished())
|
||||||
modal = self.browser.find_element_by_id("itemModal")
|
modal = self.browser.find_element_by_id("itemModal")
|
||||||
modal.find_element_by_id("item_name").send_keys("Test Item 3")
|
modal.find_element_by_id("item_name").send_keys("Test Item 3")
|
||||||
modal.find_element_by_id("item_description").send_keys("This is an item description\nthat for reasons unkown spans two lines")
|
modal.find_element_by_id("item_description").send_keys(
|
||||||
|
"This is an item description\nthat for reasons unkown spans two lines")
|
||||||
e = modal.find_element_by_id("item_quantity")
|
e = modal.find_element_by_id("item_quantity")
|
||||||
e.click()
|
e.click()
|
||||||
e.send_keys(Keys.UP)
|
e.send_keys(Keys.UP)
|
||||||
@@ -492,7 +496,8 @@ class EventTest(LiveServerTestCase):
|
|||||||
save.click()
|
save.click()
|
||||||
|
|
||||||
self.assertNotIn("N0000%d" % testEvent.pk, self.browser.find_element_by_xpath('//h1').text)
|
self.assertNotIn("N0000%d" % testEvent.pk, self.browser.find_element_by_xpath('//h1').text)
|
||||||
self.assertNotIn("Event data duplicated but not yet saved", self.browser.find_element_by_id('content').text) # Check info message not visible
|
self.assertNotIn("Event data duplicated but not yet saved",
|
||||||
|
self.browser.find_element_by_id('content').text) # Check info message not visible
|
||||||
|
|
||||||
# Check the new items are visible
|
# Check the new items are visible
|
||||||
table = self.browser.find_element_by_id('item-table') # ID number is known, see above
|
table = self.browser.find_element_by_id('item-table') # ID number is known, see above
|
||||||
@@ -501,17 +506,17 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.assertIn("Test Item 3", table.text)
|
self.assertIn("Test Item 3", table.text)
|
||||||
|
|
||||||
infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..')
|
infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..')
|
||||||
self.assertIn("N0000%d"%testEvent.pk, infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text)
|
self.assertIn("N0000%d" % testEvent.pk,
|
||||||
|
infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text)
|
||||||
# Check the PO hasn't carried through
|
# Check the PO hasn't carried through
|
||||||
self.assertNotIn("TESTPO", infoPanel.find_element_by_xpath('//dt[text()="PO"]/following-sibling::dd[1]').text)
|
self.assertNotIn("TESTPO", infoPanel.find_element_by_xpath('//dt[text()="PO"]/following-sibling::dd[1]').text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.browser.get(self.live_server_url + '/event/' + str(testEvent.pk)) # Go back to the old event
|
self.browser.get(self.live_server_url + '/event/' + str(testEvent.pk)) # Go back to the old event
|
||||||
|
|
||||||
# Check that based-on hasn't crept into the old event
|
# Check that based-on hasn't crept into the old event
|
||||||
infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..')
|
infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..')
|
||||||
self.assertNotIn("N0000%d"%testEvent.pk, infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text)
|
self.assertNotIn("N0000%d" % testEvent.pk,
|
||||||
|
infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text)
|
||||||
# Check the PO remains on the old event
|
# Check the PO remains on the old event
|
||||||
self.assertIn("TESTPO", infoPanel.find_element_by_xpath('//dt[text()="PO"]/following-sibling::dd[1]').text)
|
self.assertIn("TESTPO", infoPanel.find_element_by_xpath('//dt[text()="PO"]/following-sibling::dd[1]').text)
|
||||||
|
|
||||||
@@ -553,7 +558,6 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.assertTrue(error.is_displayed())
|
self.assertTrue(error.is_displayed())
|
||||||
self.assertIn("can't finish before it has started", error.find_element_by_xpath('//dd[1]/ul/li').text)
|
self.assertIn("can't finish before it has started", error.find_element_by_xpath('//dd[1]/ul/li').text)
|
||||||
|
|
||||||
|
|
||||||
# Same date, end time before start time
|
# Same date, end time before start time
|
||||||
form = self.browser.find_element_by_tag_name('form')
|
form = self.browser.find_element_by_tag_name('form')
|
||||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||||
@@ -575,7 +579,6 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.assertTrue(error.is_displayed())
|
self.assertTrue(error.is_displayed())
|
||||||
self.assertIn("can't finish before it has started", error.find_element_by_xpath('//dd[1]/ul/li').text)
|
self.assertIn("can't finish before it has started", error.find_element_by_xpath('//dd[1]/ul/li').text)
|
||||||
|
|
||||||
|
|
||||||
# Same date, end time before start time
|
# Same date, end time before start time
|
||||||
form = self.browser.find_element_by_tag_name('form')
|
form = self.browser.find_element_by_tag_name('form')
|
||||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||||
@@ -591,7 +594,6 @@ class EventTest(LiveServerTestCase):
|
|||||||
form.find_element_by_id('id_end_time').clear()
|
form.find_element_by_id('id_end_time').clear()
|
||||||
form.find_element_by_id('id_end_time').send_keys('06:00')
|
form.find_element_by_id('id_end_time').send_keys('06:00')
|
||||||
|
|
||||||
|
|
||||||
# No end date, end time before start time
|
# No end date, end time before start time
|
||||||
form = self.browser.find_element_by_tag_name('form')
|
form = self.browser.find_element_by_tag_name('form')
|
||||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||||
@@ -612,7 +614,6 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.assertTrue(error.is_displayed())
|
self.assertTrue(error.is_displayed())
|
||||||
self.assertIn("can't finish before it has started", error.find_element_by_xpath('//dd[1]/ul/li').text)
|
self.assertIn("can't finish before it has started", error.find_element_by_xpath('//dd[1]/ul/li').text)
|
||||||
|
|
||||||
|
|
||||||
# 2 dates, end after start
|
# 2 dates, end after start
|
||||||
form = self.browser.find_element_by_tag_name('form')
|
form = self.browser.find_element_by_tag_name('form')
|
||||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||||
@@ -672,7 +673,8 @@ class EventTest(LiveServerTestCase):
|
|||||||
person = models.Person(name="Event Detail Person", email="eventdetail@person.tests.rigs", phone="123 123")
|
person = models.Person(name="Event Detail Person", email="eventdetail@person.tests.rigs", phone="123 123")
|
||||||
person.save()
|
person.save()
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
organisation = models.Organisation(name="Event Detail Organisation", email="eventdetail@organisation.tests.rigs", phone="123 456").save()
|
organisation = models.Organisation(name="Event Detail Organisation",
|
||||||
|
email="eventdetail@organisation.tests.rigs", phone="123 456").save()
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
venue = models.Venue(name="Event Detail Venue").save()
|
venue = models.Venue(name="Event Detail Venue").save()
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
@@ -702,20 +704,22 @@ class EventTest(LiveServerTestCase):
|
|||||||
order=2,
|
order=2,
|
||||||
).save()
|
).save()
|
||||||
|
|
||||||
|
|
||||||
self.browser.get(self.live_server_url + '/event/%d' % event.pk)
|
self.browser.get(self.live_server_url + '/event/%d' % event.pk)
|
||||||
self.authenticate('/event/%d/' % event.pk)
|
self.authenticate('/event/%d/' % event.pk)
|
||||||
self.assertIn("N%05d | %s" % (event.pk, event.name), self.browser.find_element_by_xpath('//h1').text)
|
self.assertIn("N%05d | %s" % (event.pk, event.name), self.browser.find_element_by_xpath('//h1').text)
|
||||||
|
|
||||||
personPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Contact Details")]/..')
|
personPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Contact Details")]/..')
|
||||||
self.assertEqual(person.name, personPanel.find_element_by_xpath('//dt[text()="Person"]/following-sibling::dd[1]').text)
|
self.assertEqual(person.name,
|
||||||
self.assertEqual(person.email, personPanel.find_element_by_xpath('//dt[text()="Email"]/following-sibling::dd[1]').text)
|
personPanel.find_element_by_xpath('//dt[text()="Person"]/following-sibling::dd[1]').text)
|
||||||
self.assertEqual(person.phone, personPanel.find_element_by_xpath('//dt[text()="Phone Number"]/following-sibling::dd[1]').text)
|
self.assertEqual(person.email,
|
||||||
|
personPanel.find_element_by_xpath('//dt[text()="Email"]/following-sibling::dd[1]').text)
|
||||||
|
self.assertEqual(person.phone,
|
||||||
|
personPanel.find_element_by_xpath('//dt[text()="Phone Number"]/following-sibling::dd[1]').text)
|
||||||
|
|
||||||
organisationPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Contact Details")]/..')
|
organisationPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Contact Details")]/..')
|
||||||
|
|
||||||
class IcalTest(LiveServerTestCase):
|
|
||||||
|
|
||||||
|
class IcalTest(LiveServerTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.all_events = set(range(1, 18))
|
self.all_events = set(range(1, 18))
|
||||||
self.current_events = (1, 2, 3, 6, 7, 8, 10, 11, 12, 14, 15, 16, 18)
|
self.current_events = (1, 2, 3, 6, 7, 8, 10, 11, 12, 14, 15, 16, 18)
|
||||||
@@ -728,30 +732,53 @@ class IcalTest(LiveServerTestCase):
|
|||||||
self.profile.save()
|
self.profile.save()
|
||||||
|
|
||||||
# produce 7 normal events - 5 current - 1 last week - 1 two years ago - 2 provisional - 2 confirmed - 3 booked
|
# produce 7 normal events - 5 current - 1 last week - 1 two years ago - 2 provisional - 2 confirmed - 3 booked
|
||||||
models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL, start_date=date.today() + timedelta(days=6), description="start future no end")
|
models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL,
|
||||||
models.Event.objects.create(name="TE E2", status=models.Event.PROVISIONAL, start_date=date.today(), description="start today no end")
|
start_date=date.today() + timedelta(days=6), description="start future no end")
|
||||||
models.Event.objects.create(name="TE E3", status=models.Event.CONFIRMED, start_date=date.today(), end_date=date.today(), description="start today with end today")
|
models.Event.objects.create(name="TE E2", status=models.Event.PROVISIONAL, start_date=date.today(),
|
||||||
models.Event.objects.create(name="TE E4", status=models.Event.CONFIRMED, start_date=date.today()-timedelta(weeks=104), description="start past 2 years no end")
|
description="start today no end")
|
||||||
models.Event.objects.create(name="TE E5", status=models.Event.BOOKED, start_date=date.today()-timedelta(days=7), end_date=date.today()-timedelta(days=1), description="start past 1 week with end past")
|
models.Event.objects.create(name="TE E3", status=models.Event.CONFIRMED, start_date=date.today(),
|
||||||
models.Event.objects.create(name="TE E6", status=models.Event.BOOKED, start_date=date.today()-timedelta(days=2), end_date=date.today()+timedelta(days=2), description="start past, end future")
|
end_date=date.today(), description="start today with end today")
|
||||||
models.Event.objects.create(name="TE E7", status=models.Event.BOOKED, start_date=date.today()+timedelta(days=2), end_date=date.today()+timedelta(days=2), description="start + end in future")
|
models.Event.objects.create(name="TE E4", status=models.Event.CONFIRMED,
|
||||||
|
start_date=date.today() - timedelta(weeks=104),
|
||||||
|
description="start past 2 years no end")
|
||||||
|
models.Event.objects.create(name="TE E5", status=models.Event.BOOKED,
|
||||||
|
start_date=date.today() - timedelta(days=7),
|
||||||
|
end_date=date.today() - timedelta(days=1),
|
||||||
|
description="start past 1 week with end past")
|
||||||
|
models.Event.objects.create(name="TE E6", status=models.Event.BOOKED,
|
||||||
|
start_date=date.today() - timedelta(days=2),
|
||||||
|
end_date=date.today() + timedelta(days=2), description="start past, end future")
|
||||||
|
models.Event.objects.create(name="TE E7", status=models.Event.BOOKED,
|
||||||
|
start_date=date.today() + timedelta(days=2),
|
||||||
|
end_date=date.today() + timedelta(days=2), description="start + end in future")
|
||||||
|
|
||||||
# 2 cancelled - 1 current
|
# 2 cancelled - 1 current
|
||||||
models.Event.objects.create(name="TE E8", start_date=date.today()+timedelta(days=2), end_date=date.today()+timedelta(days=2), status=models.Event.CANCELLED, description="cancelled in future")
|
models.Event.objects.create(name="TE E8", start_date=date.today() + timedelta(days=2),
|
||||||
models.Event.objects.create(name="TE E9", start_date=date.today()-timedelta(days=1), end_date=date.today()+timedelta(days=2), status=models.Event.CANCELLED, description="cancelled and started")
|
end_date=date.today() + timedelta(days=2), status=models.Event.CANCELLED,
|
||||||
|
description="cancelled in future")
|
||||||
|
models.Event.objects.create(name="TE E9", start_date=date.today() - timedelta(days=1),
|
||||||
|
end_date=date.today() + timedelta(days=2), status=models.Event.CANCELLED,
|
||||||
|
description="cancelled and started")
|
||||||
|
|
||||||
# 5 dry hire - 3 current - 1 cancelled
|
# 5 dry hire - 3 current - 1 cancelled
|
||||||
models.Event.objects.create(name="TE E10", start_date=date.today(), dry_hire=True, description="dryhire today")
|
models.Event.objects.create(name="TE E10", start_date=date.today(), dry_hire=True, description="dryhire today")
|
||||||
models.Event.objects.create(name="TE E11", start_date=date.today(), dry_hire=True, checked_in_by=self.profile, description="dryhire today, checked in")
|
models.Event.objects.create(name="TE E11", start_date=date.today(), dry_hire=True, checked_in_by=self.profile,
|
||||||
models.Event.objects.create(name="TE E12", start_date=date.today()-timedelta(days=1), dry_hire=True, status=models.Event.BOOKED, description="dryhire past")
|
description="dryhire today, checked in")
|
||||||
models.Event.objects.create(name="TE E13", start_date=date.today()-timedelta(days=2), dry_hire=True, checked_in_by=self.profile, description="dryhire past checked in")
|
models.Event.objects.create(name="TE E12", start_date=date.today() - timedelta(days=1), dry_hire=True,
|
||||||
models.Event.objects.create(name="TE E14", start_date=date.today(), dry_hire=True, status=models.Event.CANCELLED, description="dryhire today cancelled")
|
status=models.Event.BOOKED, description="dryhire past")
|
||||||
|
models.Event.objects.create(name="TE E13", start_date=date.today() - timedelta(days=2), dry_hire=True,
|
||||||
|
checked_in_by=self.profile, description="dryhire past checked in")
|
||||||
|
models.Event.objects.create(name="TE E14", start_date=date.today(), dry_hire=True,
|
||||||
|
status=models.Event.CANCELLED, description="dryhire today cancelled")
|
||||||
|
|
||||||
# 4 non rig - 3 current
|
# 4 non rig - 3 current
|
||||||
models.Event.objects.create(name="TE E15", start_date=date.today(), is_rig=False, description="non rig today")
|
models.Event.objects.create(name="TE E15", start_date=date.today(), is_rig=False, description="non rig today")
|
||||||
models.Event.objects.create(name="TE E16", start_date=date.today()+timedelta(days=1), is_rig=False, description="non rig tomorrow")
|
models.Event.objects.create(name="TE E16", start_date=date.today() + timedelta(days=1), is_rig=False,
|
||||||
models.Event.objects.create(name="TE E17", start_date=date.today()-timedelta(days=1), is_rig=False, description="non rig yesterday")
|
description="non rig tomorrow")
|
||||||
models.Event.objects.create(name="TE E18", start_date=date.today(), is_rig=False, status=models.Event.CANCELLED, description="non rig today cancelled")
|
models.Event.objects.create(name="TE E17", start_date=date.today() - timedelta(days=1), is_rig=False,
|
||||||
|
description="non rig yesterday")
|
||||||
|
models.Event.objects.create(name="TE E18", start_date=date.today(), is_rig=False, status=models.Event.CANCELLED,
|
||||||
|
description="non rig today cancelled")
|
||||||
|
|
||||||
self.browser = webdriver.Firefox()
|
self.browser = webdriver.Firefox()
|
||||||
self.browser.implicitly_wait(3) # Set implicit wait session wide
|
self.browser.implicitly_wait(3) # Set implicit wait session wide
|
||||||
@@ -785,7 +812,8 @@ class IcalTest(LiveServerTestCase):
|
|||||||
|
|
||||||
# Completes and comes back to /user/
|
# Completes and comes back to /user/
|
||||||
# Checks that no api key is displayed
|
# Checks that no api key is displayed
|
||||||
self.assertEqual("No API Key Generated", self.browser.find_element_by_xpath("//div[@id='content']/div/div/div[3]/dl[2]/dd").text)
|
self.assertEqual("No API Key Generated",
|
||||||
|
self.browser.find_element_by_xpath("//div[@id='content']/div/div/div[3]/dl[2]/dd").text)
|
||||||
self.assertEqual("No API Key Generated", self.browser.find_element_by_css_selector("pre").text)
|
self.assertEqual("No API Key Generated", self.browser.find_element_by_css_selector("pre").text)
|
||||||
|
|
||||||
# Now creates an API key, and check a URL is displayed one
|
# Now creates an API key, and check a URL is displayed one
|
||||||
@@ -802,7 +830,9 @@ class IcalTest(LiveServerTestCase):
|
|||||||
self.browser.find_element_by_xpath("//input[@value='confirmed']").click()
|
self.browser.find_element_by_xpath("//input[@value='confirmed']").click()
|
||||||
|
|
||||||
# and then check the url is correct
|
# and then check the url is correct
|
||||||
self.assertIn("rigs.ics?rig=false&non-rig=false&dry-hire=false&cancelled=true&provisional=false&confirmed=false", self.browser.find_element_by_id("cal-url").text)
|
self.assertIn(
|
||||||
|
"rigs.ics?rig=false&non-rig=false&dry-hire=false&cancelled=true&provisional=false&confirmed=false",
|
||||||
|
self.browser.find_element_by_id("cal-url").text)
|
||||||
|
|
||||||
# Awesome - all seems to work
|
# Awesome - all seems to work
|
||||||
|
|
||||||
@@ -815,8 +845,6 @@ class IcalTest(LiveServerTestCase):
|
|||||||
# Now creates an API key, and check a URL is displayed one
|
# Now creates an API key, and check a URL is displayed one
|
||||||
self.browser.find_element_by_link_text("Generate API Key").click()
|
self.browser.find_element_by_link_text("Generate API Key").click()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
c = Client()
|
c = Client()
|
||||||
|
|
||||||
# Default settings - should have all non-cancelled events
|
# Default settings - should have all non-cancelled events
|
||||||
@@ -836,7 +864,6 @@ class IcalTest(LiveServerTestCase):
|
|||||||
else:
|
else:
|
||||||
self.assertNotIn("TE E" + str(test) + " ", response.content)
|
self.assertNotIn("TE E" + str(test) + " ", response.content)
|
||||||
|
|
||||||
|
|
||||||
# Only dry hires
|
# Only dry hires
|
||||||
self.browser.find_element_by_xpath("//input[@value='rig']").click()
|
self.browser.find_element_by_xpath("//input[@value='rig']").click()
|
||||||
self.browser.find_element_by_xpath("//input[@value='non-rig']").click()
|
self.browser.find_element_by_xpath("//input[@value='non-rig']").click()
|
||||||
@@ -852,7 +879,6 @@ class IcalTest(LiveServerTestCase):
|
|||||||
else:
|
else:
|
||||||
self.assertNotIn("TE E" + str(test) + " ", response.content)
|
self.assertNotIn("TE E" + str(test) + " ", response.content)
|
||||||
|
|
||||||
|
|
||||||
# Only provisional rigs
|
# Only provisional rigs
|
||||||
self.browser.find_element_by_xpath("//input[@value='rig']").click()
|
self.browser.find_element_by_xpath("//input[@value='rig']").click()
|
||||||
self.browser.find_element_by_xpath("//input[@value='dry-hire']").click()
|
self.browser.find_element_by_xpath("//input[@value='dry-hire']").click()
|
||||||
@@ -903,8 +929,10 @@ class IcalTest(LiveServerTestCase):
|
|||||||
|
|
||||||
# Wow - that was a lot of tests
|
# Wow - that was a lot of tests
|
||||||
|
|
||||||
|
|
||||||
class animation_is_finished(object):
|
class animation_is_finished(object):
|
||||||
""" Checks if animation is done """
|
""" Checks if animation is done """
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -915,3 +943,87 @@ class animation_is_finished(object):
|
|||||||
import time
|
import time
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
return finished
|
return finished
|
||||||
|
|
||||||
|
|
||||||
|
class ClientEventAuthorisationTest(TestCase):
|
||||||
|
auth_data = {
|
||||||
|
'name': 'Test ABC',
|
||||||
|
'po': '1234ABCZXY',
|
||||||
|
'account_code': 'ABC TEST 12345',
|
||||||
|
'uni_id': 1234567890,
|
||||||
|
'tos': True
|
||||||
|
}
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
venue = models.Venue.objects.create(name='Authorisation Test Venue')
|
||||||
|
client = models.Person.objects.create(name='Authorisation Test Person', email='authorisation@functional.test')
|
||||||
|
organisation = models.Organisation.objects.create(name='Authorisation Test Organisation', union_account=False)
|
||||||
|
self.event = models.Event.objects.create(
|
||||||
|
name='Authorisation Test',
|
||||||
|
start_date=date.today(),
|
||||||
|
venue=venue,
|
||||||
|
person=client,
|
||||||
|
organisation=organisation,
|
||||||
|
)
|
||||||
|
self.hmac = signing.dumps({'pk': self.event.pk, 'email': 'authemail@function.test'})
|
||||||
|
self.url = reverse('event_authorise', kwargs={'pk': self.event.pk, 'hmac': self.hmac})
|
||||||
|
|
||||||
|
def test_requires_valid_hmac(self):
|
||||||
|
bad_hmac = self.hmac[:-1]
|
||||||
|
url = reverse('event_authorise', kwargs={'pk': self.event.pk, 'hmac': bad_hmac})
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertIsInstance(response, HttpResponseBadRequest)
|
||||||
|
# TODO: Add some form of sensbile user facing error
|
||||||
|
# self.assertIn(response.content, "new URL") # check there is some level of sane instruction
|
||||||
|
|
||||||
|
response = self.client.get(self.url)
|
||||||
|
self.assertContains(response, self.event.organisation.name)
|
||||||
|
|
||||||
|
def test_generic_validation(self):
|
||||||
|
response = self.client.get(self.url)
|
||||||
|
self.assertContains(response, "Terms of Hire")
|
||||||
|
|
||||||
|
response = self.client.post(self.url)
|
||||||
|
self.assertContains(response, "This field is required.", 4)
|
||||||
|
|
||||||
|
data = self.auth_data
|
||||||
|
data['amount'] = self.event.total + 1
|
||||||
|
|
||||||
|
response = self.client.post(self.url, data)
|
||||||
|
self.assertContains(response, "The amount authorised must equal the total for the event")
|
||||||
|
self.assertNotContains(response, "This field is required.")
|
||||||
|
|
||||||
|
data['amount'] = self.event.total
|
||||||
|
response = self.client.post(self.url, data)
|
||||||
|
self.assertContains(response, "Your event has been authorised")
|
||||||
|
|
||||||
|
self.event.refresh_from_db()
|
||||||
|
self.assertTrue(self.event.authorised)
|
||||||
|
self.assertEqual(self.event.authorisation.email, "authemail@function.test")
|
||||||
|
|
||||||
|
def test_internal_validation(self):
|
||||||
|
self.event.organisation.union_account = True
|
||||||
|
self.event.organisation.save()
|
||||||
|
|
||||||
|
response = self.client.get(self.url)
|
||||||
|
self.assertContains(response, "Account code")
|
||||||
|
self.assertContains(response, "University ID")
|
||||||
|
|
||||||
|
response = self.client.post(self.url)
|
||||||
|
self.assertContains(response, "This field is required.", 5)
|
||||||
|
|
||||||
|
data = self.auth_data
|
||||||
|
response = self.client.post(self.url, data)
|
||||||
|
self.assertContains(response, "Your event has been authorised.")
|
||||||
|
|
||||||
|
def test_duplicate_warning(self):
|
||||||
|
auth = models.EventAuthorisation.objects.create(event=self.event, name='Test ABC', email='dupe@functional.test',
|
||||||
|
po='ABC12345', amount=self.event.total)
|
||||||
|
response = self.client.get(self.url)
|
||||||
|
self.assertContains(response, 'This event has already been authorised.')
|
||||||
|
|
||||||
|
auth.amount += 1
|
||||||
|
auth.save()
|
||||||
|
|
||||||
|
response = self.client.get(self.url)
|
||||||
|
self.assertContains(response, 'amount has changed')
|
||||||
|
|||||||
@@ -341,28 +341,6 @@ class EventAuthorisationTestCase(TestCase):
|
|||||||
models.EventItem.objects.create(event=cls.event, name="Authorisation test item", quantity=2, cost=123.45,
|
models.EventItem.objects.create(event=cls.event, name="Authorisation test item", quantity=2, cost=123.45,
|
||||||
order=1)
|
order=1)
|
||||||
|
|
||||||
def test_validation(self):
|
|
||||||
auth = models.EventAuthorisation(event=self.event, email="authroisation@model.test.case", name="Test Auth")
|
|
||||||
|
|
||||||
auth.amount = self.event.total - 1
|
|
||||||
self.assertRaises(ValidationError, auth.clean)
|
|
||||||
auth.amount = self.event.total
|
|
||||||
|
|
||||||
# Test for externals first
|
|
||||||
self.assertRaises(ValidationError, auth.clean)
|
|
||||||
self.event.organisation = self.organisation
|
|
||||||
self.assertRaises(ValidationError, auth.clean)
|
|
||||||
auth.po = "TEST123"
|
|
||||||
self.assertIsNone(auth.clean())
|
|
||||||
|
|
||||||
auth.po = None
|
|
||||||
self.organisation.union_account = True
|
|
||||||
self.assertRaises(ValidationError, auth.clean)
|
|
||||||
auth.uni_id = "1234567"
|
|
||||||
self.assertRaises(ValidationError, auth.clean)
|
|
||||||
auth.account_code = "TST AUTH 12345"
|
|
||||||
self.assertIsNone(auth.clean())
|
|
||||||
|
|
||||||
def test_event_property(self):
|
def test_event_property(self):
|
||||||
auth1 = models.EventAuthorisation.objects.create(event=self.event, email="authroisation@model.test.case",
|
auth1 = models.EventAuthorisation.objects.create(event=self.event, email="authroisation@model.test.case",
|
||||||
name="Test Auth 1", amount=self.event.total - 1)
|
name="Test Auth 1", amount=self.event.total - 1)
|
||||||
@@ -370,11 +348,3 @@ class EventAuthorisationTestCase(TestCase):
|
|||||||
auth1.amount = self.event.total
|
auth1.amount = self.event.total
|
||||||
auth1.save()
|
auth1.save()
|
||||||
self.assertTrue(self.event.authorised)
|
self.assertTrue(self.event.authorised)
|
||||||
|
|
||||||
auth2 = models.EventAuthorisation.objects.create(event=self.event, email="authroisation@model.test.case",
|
|
||||||
name="Test Auth 2", amount=self.event.total - 1)
|
|
||||||
self.assertEqual(auth2.pk, self.event.authroisations.latest('created_at').pk)
|
|
||||||
self.assertFalse(self.event.authorised)
|
|
||||||
auth2.amount = self.event.total + 1
|
|
||||||
auth2.save()
|
|
||||||
self.assertTrue(self.event.authorised)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user