mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-21 15:32:14 +00:00
Refactor date validation test
So close to killing test_functional.EventTest!
This commit is contained in:
@@ -63,117 +63,7 @@ class EventTest(LiveServerTestCase):
|
||||
submit.click()
|
||||
|
||||
self.assertEqual(self.live_server_url + n, self.browser.current_url)
|
||||
|
||||
def testDateValidation(self):
|
||||
self.browser.get(self.live_server_url + '/event/create/')
|
||||
# Gets redirected to login and back
|
||||
self.authenticate('/event/create/')
|
||||
|
||||
wait = WebDriverWait(self.browser, 3) # setup WebDriverWait to use later (to wait for animations)
|
||||
|
||||
wait.until(animation_is_finished())
|
||||
|
||||
# Click Rig button
|
||||
self.browser.find_element_by_xpath('//button[.="Rig"]').click()
|
||||
|
||||
form = self.browser.find_element_by_xpath('//*[@id="content"]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
|
||||
# Set title
|
||||
e = self.browser.find_element_by_id('id_name')
|
||||
e.send_keys('Test Event Name')
|
||||
|
||||
# Set person
|
||||
person = models.Person.objects.create(name='Date Validation Person', email='datevalidation@functional.test')
|
||||
person_select = form.find_element_by_xpath(
|
||||
'//button[@data-id="id_person"]')
|
||||
person_select.send_keys(person.name)
|
||||
person_dropped = form.find_element_by_xpath(
|
||||
'//ul[contains(@class, "dropdown-menu")]//span[contains(text(), "%s")]' % person.name)
|
||||
person_dropped.click()
|
||||
|
||||
# Both dates, no times, end before start
|
||||
self.browser.execute_script("document.getElementById('id_start_date').value='3015-04-24'")
|
||||
|
||||
self.browser.execute_script("document.getElementById('id_end_date').value='3015-04-23'")
|
||||
|
||||
# Attempt to save - should fail
|
||||
wait.until(animation_is_finished())
|
||||
save.click()
|
||||
|
||||
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)
|
||||
|
||||
# Same date, end time before start time
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
|
||||
self.browser.execute_script("document.getElementById('id_start_date').value='3015-04-24'")
|
||||
self.browser.execute_script("document.getElementById('id_end_date').value='3015-04-23'")
|
||||
|
||||
form.find_element_by_id('id_start_time').send_keys(Keys.DELETE)
|
||||
form.find_element_by_id('id_start_time').send_keys('06:59')
|
||||
|
||||
form.find_element_by_id('id_end_time').send_keys(Keys.DELETE)
|
||||
form.find_element_by_id('id_end_time').send_keys('06:00')
|
||||
|
||||
# Attempt to save - should fail
|
||||
save.click()
|
||||
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)
|
||||
|
||||
# Same date, end time before start time
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
|
||||
self.browser.execute_script("document.getElementById('id_start_date').value='3015-04-24'")
|
||||
self.browser.execute_script("document.getElementById('id_end_date').value='3015-04-24'")
|
||||
|
||||
form.find_element_by_id('id_start_time').send_keys(Keys.DELETE)
|
||||
form.find_element_by_id('id_start_time').send_keys('06:59')
|
||||
|
||||
form.find_element_by_id('id_end_time').send_keys(Keys.DELETE)
|
||||
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_xpath('/html/body/div[2]/div[1]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
|
||||
self.browser.execute_script("document.getElementById('id_start_date').value='3015-04-24'")
|
||||
self.browser.execute_script("document.getElementById('id_end_date').value=''")
|
||||
|
||||
form.find_element_by_id('id_start_time').send_keys(Keys.DELETE)
|
||||
form.find_element_by_id('id_start_time').send_keys('06:59')
|
||||
|
||||
form.find_element_by_id('id_end_time').send_keys(Keys.DELETE)
|
||||
form.find_element_by_id('id_end_time').send_keys('06:00')
|
||||
|
||||
# Attempt to save - should fail
|
||||
save.click()
|
||||
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)
|
||||
|
||||
# 2 dates, end after start
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
self.browser.execute_script("document.getElementById('id_start_date').value='3015-04-24'")
|
||||
self.browser.execute_script("document.getElementById('id_end_date').value='3015-04-26'")
|
||||
|
||||
self.browser.execute_script("document.getElementById('id_start_time').value=''")
|
||||
self.browser.execute_script("document.getElementById('id_end_time').value=''")
|
||||
|
||||
# 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("N%05d | Test Event Name" % event.pk, successTitle)
|
||||
|
||||
|
||||
def testEventDetail(self):
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
person = models.Person(name="Event Detail Person", email="eventdetail@person.tests.rigs", phone="123 123")
|
||||
|
||||
Reference in New Issue
Block a user