Reformat all the things

Python code is now formatted to PEP8

All other files are defined in .editorconfig as far as possible.
This commit is contained in:
Tom Price
2016-08-09 19:42:39 +01:00
parent 024f08562b
commit 567f899a39
75 changed files with 3606 additions and 2667 deletions

View File

@@ -17,10 +17,9 @@ from RIGS import models
class UserRegistrationTest(LiveServerTestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3) # Set implicit wait session wide
self.browser.implicitly_wait(3) # Set implicit wait session wide
os.environ['RECAPTCHA_TESTING'] = 'True'
def tearDown(self):
@@ -149,17 +148,17 @@ class UserRegistrationTest(LiveServerTestCase):
class EventTest(LiveServerTestCase):
def setUp(self):
self.profile = models.Profile(
username="EventTest", first_name="Event", last_name="Test", initials="ETU", is_superuser=True)
self.profile.set_password("EventTestPassword")
self.profile.save()
self.vatrate = models.VatRate.objects.create(start_at='2014-03-05',rate=0.20,comment='test1')
self.vatrate = models.VatRate.objects.create(
start_at='2014-03-05', rate=0.20, comment='test1')
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3) # Set implicit wait session wide
self.browser.implicitly_wait(3) # Set implicit wait session wide
self.browser.maximize_window()
os.environ['RECAPTCHA_TESTING'] = 'True'
@@ -203,7 +202,8 @@ class EventTest(LiveServerTestCase):
# Gets redirected to login and back
self.authenticate('/event/create/')
wait = WebDriverWait(self.browser, 10) #setup WebDriverWait to use later (to wait for animations)
# setup WebDriverWait to use later (to wait for animations)
wait = WebDriverWait(self.browser, 10)
wait.until(animation_is_finished())
@@ -229,7 +229,9 @@ class EventTest(LiveServerTestCase):
modal = self.browser.find_element_by_id('modal')
wait.until(animation_is_finished())
self.assertTrue(modal.is_displayed())
self.assertIn("Add Person", modal.find_element_by_tag_name('h3').text)
self.assertIn(
"Add Person",
modal.find_element_by_tag_name('h3').text)
# Fill person form out and submit
modal.find_element_by_xpath(
@@ -254,7 +256,9 @@ class EventTest(LiveServerTestCase):
wait.until(animation_is_finished())
self.assertTrue(modal.is_displayed())
self.assertIn("Add Person", modal.find_element_by_tag_name('h3').text)
self.assertIn(
"Add Person",
modal.find_element_by_tag_name('h3').text)
modal.find_element_by_xpath(
'//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Person 2")
@@ -290,7 +294,9 @@ class EventTest(LiveServerTestCase):
'//a[@data-target="#id_person" and contains(@href, "%s/edit/")]' % person1.pk).click()
wait.until(animation_is_finished())
self.assertTrue(modal.is_displayed())
self.assertIn("Edit Person", modal.find_element_by_tag_name('h3').text)
self.assertIn(
"Edit Person",
modal.find_element_by_tag_name('h3').text)
name = modal.find_element_by_xpath(
'//div[@id="modal"]//input[@id="id_name"]')
self.assertEqual(person1.name, name.get_attribute('value'))
@@ -313,7 +319,8 @@ class EventTest(LiveServerTestCase):
modal = self.browser.find_element_by_id('modal')
wait.until(animation_is_finished())
self.assertTrue(modal.is_displayed())
self.assertIn("Add Organisation", modal.find_element_by_tag_name('h3').text)
self.assertIn("Add Organisation",
modal.find_element_by_tag_name('h3').text)
modal.find_element_by_xpath(
'//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Organisation")
modal.find_element_by_xpath(
@@ -340,7 +347,9 @@ class EventTest(LiveServerTestCase):
modal = self.browser.find_element_by_id('modal')
wait.until(animation_is_finished())
self.assertTrue(modal.is_displayed())
self.assertIn("Add Venue", modal.find_element_by_tag_name('h3').text)
self.assertIn(
"Add Venue",
modal.find_element_by_tag_name('h3').text)
modal.find_element_by_xpath(
'//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Venue")
modal.find_element_by_xpath(
@@ -366,51 +375,72 @@ class EventTest(LiveServerTestCase):
form.find_element_by_id('id_end_time').send_keys('07:00')
# Add item
form.find_element_by_xpath('//button[contains(@class, "item-add")]').click()
form.find_element_by_xpath(
'//button[contains(@class, "item-add")]').click()
wait.until(animation_is_finished())
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_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.click()
e.send_keys(Keys.UP)
e.send_keys(Keys.UP)
e = modal.find_element_by_id("item_cost")
e.send_keys("23.95")
e.send_keys(Keys.ENTER) # enter submit
e.send_keys(Keys.ENTER) # enter submit
# Confirm item has been saved to json field
objectitems = self.browser.execute_script("return objectitems;")
self.assertEqual(1, len(objectitems))
testitem = objectitems["-1"]['fields'] # as we are deliberately creating this we know the ID
# as we are deliberately creating this we know the ID
testitem = objectitems["-1"]['fields']
self.assertEqual("Test Item 1", testitem['name'])
self.assertEqual("2", testitem['quantity']) # test a couple of "worse case" fields
# test a couple of "worse case" fields
self.assertEqual("2", testitem['quantity'])
# See new item appear in table
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("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("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)
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(
"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("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)
# Check totals
self.assertEqual("47.90", self.browser.find_element_by_id('sumtotal').text)
self.assertIn("(TBC)", self.browser.find_element_by_id('vat-rate').text)
self.assertEqual("9.58", self.browser.find_element_by_id('vat').text)
self.assertEqual("57.48", self.browser.find_element_by_id('total').text)
self.assertEqual(
"47.90", self.browser.find_element_by_id('sumtotal').text)
self.assertIn(
"(TBC)",
self.browser.find_element_by_id('vat-rate').text)
self.assertEqual(
"9.58", self.browser.find_element_by_id('vat').text)
self.assertEqual(
"57.48", self.browser.find_element_by_id('total').text)
# Attempt to save - missing title
save.click()
# See error
error = self.browser.find_element_by_xpath('//div[contains(@class, "alert-danger")]')
error = self.browser.find_element_by_xpath(
'//div[contains(@class, "alert-danger")]')
self.assertTrue(error.is_displayed())
# Should only have one error message
self.assertEqual("Name", error.find_element_by_xpath('//dt[1]').text)
self.assertEqual("This field is required.", error.find_element_by_xpath('//dd[1]/ul/li').text)
self.assertEqual(
"Name", error.find_element_by_xpath('//dt[1]').text)
self.assertEqual("This field is required.",
error.find_element_by_xpath('//dd[1]/ul/li').text)
# don't need error so close it
error.find_element_by_xpath('//div[contains(@class, "alert-danger")]//button[@class="close"]').click()
error.find_element_by_xpath(
'//div[contains(@class, "alert-danger")]//button[@class="close"]').click()
try:
self.assertFalse(error.is_displayed())
except StaleElementReferenceException:
@@ -431,84 +461,102 @@ class EventTest(LiveServerTestCase):
# See redirected to success page
successTitle = self.browser.find_element_by_xpath('//h1').text
event = models.Event.objects.get(name='Test Event Name')
self.assertIn("N0000%d | Test Event Name"%event.pk, successTitle)
self.assertIn("N0000%d | Test Event Name" % event.pk, successTitle)
except WebDriverException:
# This is a dirty workaround for wercker being a bit funny and not running it correctly.
# Waiting for wercker to get back to me about this
pass
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")
testEvent = models.Event.objects.create(
name="TE E1",
status=models.Event.PROVISIONAL,
start_date=date.today() +
timedelta(
days=6),
description="start future no end")
item1 = models.EventItem(
event=testEvent,
name="Test Item 1",
cost="10.00",
quantity="1",
order=1
).save()
event=testEvent,
name="Test Item 1",
cost="10.00",
quantity="1",
order=1
).save()
item2 = models.EventItem(
event=testEvent,
name="Test Item 2",
description="Foo",
cost="9.72",
quantity="3",
order=2,
).save()
event=testEvent,
name="Test Item 2",
description="Foo",
cost="9.72",
quantity="3",
order=2,
).save()
self.browser.get(self.live_server_url + '/event/' + str(testEvent.pk) + '/duplicate/')
self.browser.get(self.live_server_url + '/event/' +
str(testEvent.pk) + '/duplicate/')
self.authenticate('/event/' + str(testEvent.pk) + '/duplicate/')
wait = WebDriverWait(self.browser, 10) #setup WebDriverWait to use later (to wait for animations)
# setup WebDriverWait to use later (to wait for animations)
wait = WebDriverWait(self.browser, 10)
save = self.browser.find_element_by_xpath(
'(//button[@type="submit"])[3]')
form = self.browser.find_element_by_tag_name('form')
# 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 2", table.text)
# Add item
form.find_element_by_xpath('//button[contains(@class, "item-add")]').click()
form.find_element_by_xpath(
'//button[contains(@class, "item-add")]').click()
wait.until(animation_is_finished())
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_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.click()
e.send_keys(Keys.UP)
e.send_keys(Keys.UP)
e = modal.find_element_by_id("item_cost")
e.send_keys("23.95")
e.send_keys(Keys.ENTER) # enter submit
e.send_keys(Keys.ENTER) # enter submit
# Attempt to save
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)
# 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
self.assertIn("Test Item 1", table.text)
self.assertIn("Test Item 2", table.text)
self.assertIn("Test Item 3", table.text)
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)
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.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
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)
# Check that based-on hasn't crept into the old event
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)
# Check the items are as they were
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 2", table.text)
self.assertNotIn("Test Item 3", table.text)
@@ -518,7 +566,8 @@ class EventTest(LiveServerTestCase):
# Gets redirected to login and back
self.authenticate('/event/create/')
wait = WebDriverWait(self.browser, 10) #setup WebDriverWait to use later (to wait for animations)
# setup WebDriverWait to use later (to wait for animations)
wait = WebDriverWait(self.browser, 10)
wait.until(animation_is_finished())
@@ -526,7 +575,8 @@ class EventTest(LiveServerTestCase):
self.browser.find_element_by_xpath('//button[.="Rig"]').click()
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]')
# Set title
e = self.browser.find_element_by_id('id_name')
@@ -541,14 +591,16 @@ class EventTest(LiveServerTestCase):
# Attempt to save - should fail
save.click()
error = self.browser.find_element_by_xpath('//div[contains(@class, "alert-danger")]')
error = self.browser.find_element_by_xpath(
'//div[contains(@class, "alert-danger")]')
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
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]')
form.find_element_by_id('id_start_date').clear()
form.find_element_by_id('id_start_date').send_keys('3015-04-24')
@@ -563,14 +615,16 @@ class EventTest(LiveServerTestCase):
# Attempt to save - should fail
save.click()
error = self.browser.find_element_by_xpath('//div[contains(@class, "alert-danger")]')
error = self.browser.find_element_by_xpath(
'//div[contains(@class, "alert-danger")]')
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
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]')
form.find_element_by_id('id_start_date').clear()
form.find_element_by_id('id_start_date').send_keys('3015-04-24')
@@ -583,10 +637,10 @@ class EventTest(LiveServerTestCase):
form.find_element_by_id('id_end_time').clear()
form.find_element_by_id('id_end_time').send_keys('06:00')
# No end date, end time before start time
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]')
form.find_element_by_id('id_start_date').clear()
form.find_element_by_id('id_start_date').send_keys('3015-04-24')
@@ -600,14 +654,16 @@ class EventTest(LiveServerTestCase):
# Attempt to save - should fail
save.click()
error = self.browser.find_element_by_xpath('//div[contains(@class, "alert-danger")]')
error = self.browser.find_element_by_xpath(
'//div[contains(@class, "alert-danger")]')
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
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]')
form.find_element_by_id('id_start_date').clear()
form.find_element_by_id('id_start_date').send_keys('3015-04-24')
@@ -615,24 +671,26 @@ class EventTest(LiveServerTestCase):
form.find_element_by_id('id_end_date').send_keys('3015-04-26')
form.find_element_by_id('id_start_time').clear()
form.find_element_by_id('id_end_time').clear()
# Attempt to save - should succeed
save.click()
# See redirected to success page
successTitle = self.browser.find_element_by_xpath('//h1').text
event = models.Event.objects.get(name='Test Event Name')
self.assertIn("N0000%d | Test Event Name"%event.pk, successTitle)
self.assertIn("N0000%d | Test Event Name" % event.pk, successTitle)
def testRigNonRig(self):
self.browser.get(self.live_server_url + '/event/create/')
# Gets redirected to login and back
self.authenticate('/event/create/')
wait = WebDriverWait(self.browser, 10) #setup WebDriverWait to use later (to wait for animations)
self.browser.implicitly_wait(3) #Set session-long wait (only works for non-existant DOM objects)
# setup WebDriverWait to use later (to wait for animations)
wait = WebDriverWait(self.browser, 10)
# Set session-long wait (only works for non-existant DOM objects)
self.browser.implicitly_wait(3)
wait.until(animation_is_finished())
@@ -643,7 +701,8 @@ class EventTest(LiveServerTestCase):
self.browser.find_element_by_xpath('//button[.="Rig"]').click()
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]')
# Set title
e = self.browser.find_element_by_id('id_name')
@@ -655,16 +714,23 @@ class EventTest(LiveServerTestCase):
# Save the rig
save.click()
detail_panel = self.browser.find_element_by_xpath("//div[@id='content']/div/div[6]/div/div")
detail_panel = self.browser.find_element_by_xpath(
"//div[@id='content']/div/div[6]/div/div")
self.assertTrue(detail_panel.is_displayed())
self.assertIn("Event Detail", detail_panel.text)
def testEventDetail(self):
with transaction.atomic(), reversion.create_revision():
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()
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():
venue = models.Venue(name="Event Detail Venue").save()
with transaction.atomic(), reversion.create_revision():
@@ -694,59 +760,182 @@ class EventTest(LiveServerTestCase):
order=2,
).save()
self.browser.get(self.live_server_url + '/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.browser.get(self.live_server_url + '/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)
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.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)
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.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):
def setUp(self):
self.all_events = set(range(1, 18))
self.current_events = (1, 2, 3, 6, 7, 8, 10, 11, 12, 14, 15, 16, 18)
self.not_current_events = set(self.all_events) - set(self.current_events)
self.not_current_events = set(
self.all_events) - set(self.current_events)
self.vatrate = models.VatRate.objects.create(start_at='2014-03-05',rate=0.20,comment='test1')
self.vatrate = models.VatRate.objects.create(
start_at='2014-03-05', rate=0.20, comment='test1')
self.profile = models.Profile(
username="EventTest", first_name="Event", last_name="Test", initials="ETU", is_superuser=True)
self.profile.set_password("EventTestPassword")
self.profile.save()
# 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 E2", status=models.Event.PROVISIONAL, start_date=date.today(), description="start today 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 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")
# 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 E2",
status=models.Event.PROVISIONAL,
start_date=date.today(),
description="start today 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 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
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 E9", start_date=date.today()-timedelta(days=1), end_date=date.today()+timedelta(days=2), status=models.Event.CANCELLED, description="cancelled and started")
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 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
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 E12", start_date=date.today()-timedelta(days=1), dry_hire=True, 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")
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 E12",
start_date=date.today() -
timedelta(
days=1),
dry_hire=True,
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
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 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")
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 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.implicitly_wait(3) # Set implicit wait session wide
self.browser.implicitly_wait(3) # Set implicit wait session wide
os.environ['RECAPTCHA_TESTING'] = 'True'
def tearDown(self):
@@ -777,24 +966,34 @@ class IcalTest(LiveServerTestCase):
# Completes and comes back to /user/
# 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_css_selector("pre").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)
# Now creates an API key, and check a URL is displayed one
self.browser.find_element_by_link_text("Generate API Key").click()
self.assertIn("rigs.ics", self.browser.find_element_by_id("cal-url").text)
self.assertIn(
"rigs.ics",
self.browser.find_element_by_id("cal-url").text)
self.assertNotIn("?", self.browser.find_element_by_id("cal-url").text)
# Lets change everything so it's not the default value
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='dry-hire']").click()
self.browser.find_element_by_xpath("//input[@value='cancelled']").click()
self.browser.find_element_by_xpath("//input[@value='provisional']").click()
self.browser.find_element_by_xpath("//input[@value='confirmed']").click()
self.browser.find_element_by_xpath(
"//input[@value='dry-hire']").click()
self.browser.find_element_by_xpath(
"//input[@value='cancelled']").click()
self.browser.find_element_by_xpath(
"//input[@value='provisional']").click()
self.browser.find_element_by_xpath(
"//input[@value='confirmed']").click()
# 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
@@ -807,27 +1006,24 @@ class IcalTest(LiveServerTestCase):
# Now creates an API key, and check a URL is displayed one
self.browser.find_element_by_link_text("Generate API Key").click()
c = Client()
# Default settings - should have all non-cancelled events
# Get the ical file (can't do this in selanium because reasons)
icalUrl = self.browser.find_element_by_id("cal-url").text
response = c.get(icalUrl)
self.assertEqual(200, response.status_code)
#Check has entire file
# Check has entire file
self.assertIn("BEGIN:VCALENDAR", response.content)
self.assertIn("END:VCALENDAR", response.content)
expectedIn= [1,2,3,5,6,7,10,11,12,13,15,16,17]
for test in range(1,18):
expectedIn = [1, 2, 3, 5, 6, 7, 10, 11, 12, 13, 15, 16, 17]
for test in range(1, 18):
if test in expectedIn:
self.assertIn("TE E"+str(test)+" ", response.content)
self.assertIn("TE E" + str(test) + " ", response.content)
else:
self.assertNotIn("TE E"+str(test)+" ", response.content)
self.assertNotIn("TE E" + str(test) + " ", response.content)
# Only dry hires
self.browser.find_element_by_xpath("//input[@value='rig']").click()
@@ -837,66 +1033,72 @@ class IcalTest(LiveServerTestCase):
response = c.get(icalUrl)
self.assertEqual(200, response.status_code)
expectedIn= [10,11,12,13]
for test in range(1,18):
expectedIn = [10, 11, 12, 13]
for test in range(1, 18):
if test in expectedIn:
self.assertIn("TE E"+str(test)+" ", response.content)
self.assertIn("TE E" + str(test) + " ", response.content)
else:
self.assertNotIn("TE E"+str(test)+" ", response.content)
self.assertNotIn("TE E" + str(test) + " ", response.content)
# Only provisional rigs
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='confirmed']").click()
self.browser.find_element_by_xpath(
"//input[@value='dry-hire']").click()
self.browser.find_element_by_xpath(
"//input[@value='confirmed']").click()
icalUrl = self.browser.find_element_by_id("cal-url").text
response = c.get(icalUrl)
self.assertEqual(200, response.status_code)
expectedIn= [1,2]
for test in range(1,18):
expectedIn = [1, 2]
for test in range(1, 18):
if test in expectedIn:
self.assertIn("TE E"+str(test)+" ", response.content)
self.assertIn("TE E" + str(test) + " ", response.content)
else:
self.assertNotIn("TE E"+str(test)+" ", response.content)
self.assertNotIn("TE E" + str(test) + " ", response.content)
# Only cancelled non-rigs
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='provisional']").click()
self.browser.find_element_by_xpath("//input[@value='cancelled']").click()
self.browser.find_element_by_xpath(
"//input[@value='provisional']").click()
self.browser.find_element_by_xpath(
"//input[@value='cancelled']").click()
icalUrl = self.browser.find_element_by_id("cal-url").text
response = c.get(icalUrl)
self.assertEqual(200, response.status_code)
expectedIn= [18]
for test in range(1,18):
expectedIn = [18]
for test in range(1, 18):
if test in expectedIn:
self.assertIn("TE E"+str(test)+" ", response.content)
self.assertIn("TE E" + str(test) + " ", response.content)
else:
self.assertNotIn("TE E"+str(test)+" ", response.content)
self.assertNotIn("TE E" + str(test) + " ", response.content)
# Nothing selected
self.browser.find_element_by_xpath("//input[@value='non-rig']").click()
self.browser.find_element_by_xpath("//input[@value='cancelled']").click()
self.browser.find_element_by_xpath(
"//input[@value='cancelled']").click()
icalUrl = self.browser.find_element_by_id("cal-url").text
response = c.get(icalUrl)
self.assertEqual(200, response.status_code)
expectedIn= []
for test in range(1,18):
expectedIn = []
for test in range(1, 18):
if test in expectedIn:
self.assertIn("TE E"+str(test)+" ", response.content)
self.assertIn("TE E" + str(test) + " ", response.content)
else:
self.assertNotIn("TE E"+str(test)+" ", response.content)
# Wow - that was a lot of tests
self.assertNotIn("TE E" + str(test) + " ", response.content)
# Wow - that was a lot of tests
class animation_is_finished(object):
""" Checks if animation is done """
def __init__(self):
pass