Refactor date validation test

So close to killing test_functional.EventTest!
This commit is contained in:
2020-05-24 00:27:41 +01:00
parent 3c0005ddb0
commit cc225b2eb7
4 changed files with 48 additions and 116 deletions

View File

@@ -40,7 +40,7 @@ class FormPage(BasePage):
def submit(self):
previous_errors = self.errors
self.find_element(*self._submit_locator).click()
self.wait.until(lambda x: self.errors != previous_errors or self.success)
# self.wait.until(lambda x: self.errors != previous_errors or self.success) This breaks my date validation test... :D
@property
def errors(self):

View File

@@ -54,7 +54,7 @@ class CreateEvent(FormPage):
_is_rig_selector = (By.ID, 'is_rig-selector')
_bottom_save_selector = (By.XPATH, '//*[@id="main"]/form/div/div[6]/div/button')
_submit_locator = _bottom_save_selector
_submit_locator = (By.XPATH, "//button[@type='submit' and contains(., 'Save')]")
# TODO The ID is now no longer on the highest level element on the selector, annoyingly
_person_selector_selector = (By.XPATH, '//*[@id="main"]/form/div/div[3]/div[1]/div[2]/div[1]/div/div/div[1]/div')
_venue_selector_selector = (By.XPATH, '//*[@id="main"]/form/div/div[3]/div[1]/div[2]/div[1]/div/div/div[1]/div')
@@ -72,8 +72,8 @@ class CreateEvent(FormPage):
'name': (regions.TextBox, (By.ID, 'id_name')),
'start_date': (regions.DatePicker, (By.ID, 'id_start_date')),
'start_time': (regions.TimePicker, (By.ID, 'id_start_time')),
'end_date': (regions.DatePicker, (By.ID, 'id_start_date')),
'end_time': (regions.TimePicker, (By.ID, 'id_start_time')),
'end_date': (regions.DatePicker, (By.ID, 'id_end_date')),
'end_time': (regions.TimePicker, (By.ID, 'id_end_time')),
'access_at': (regions.DateTimePicker, (By.ID, 'id_access_at')),
'meet_at': (regions.DateTimePicker, (By.ID, 'id_meet_at')),
'dry_hire': (regions.CheckBox, (By.ID, 'id_dry_hire')),

View File

@@ -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")

View File

@@ -67,7 +67,7 @@ class TestRigboard(AutoLoginTest):
# Ideally get a response object to assert 200 on
class TEventCreate(AutoLoginTest):
class TestEventCreate(AutoLoginTest):
def setUp(self):
super().setUp()
self.client = models.Person.objects.create(name='Creation Test Person', email='god@functional.test')
@@ -149,6 +149,48 @@ class TEventCreate(AutoLoginTest):
self.assertFalse(modal.is_open)
# TODO
def test_date_validation(self):
self.wait.until(animation_is_finished())
self.assertFalse(self.page.is_expanded)
self.page.select_event_type("Rig")
self.wait.until(animation_is_finished())
self.assertTrue(self.page.is_expanded)
self.page.person_selector.toggle()
self.assertTrue(self.page.person_selector.is_open)
self.page.person_selector.search(self.client.name)
self.page.person_selector.set_option(self.client.name, True)
# TODO This should not be necessary, normally closes automatically
self.page.person_selector.toggle()
self.assertFalse(self.page.person_selector.is_open)
self.page.name = "Test Date Validation"
# Both dates, no times, end before start
self.page.start_date = datetime.date(2020, 1, 10)
self.page.end_date = datetime.date(2020, 1, 1)
# Expected to fail
self.page.submit()
self.assertFalse(self.page.success)
self.assertIn("can't finish before it has started", self.page.errors["General form errors"][0])
self.wait.until(animation_is_finished())
#end time before start
self.page.start_date = datetime.date(2020, 1, 1)
self.page.start_time = datetime.time(10)
self.page.end_time = datetime.time(9)
# Expected to fail
self.page.submit()
self.assertFalse(self.page.success)
self.assertIn("can't finish before it has started", self.page.errors["General form errors"][0])
# Fix it
self.page.end_time = datetime.time(23)
# Should work
self.page.submit()
self.assertTrue(self.page.success)
def test_event_item_creation(self):
self.wait.until(animation_is_finished())