Initial port of duplicate testing

Needs the latter half rewriting once we have an EventDetail POM
This commit is contained in:
2020-05-23 23:48:11 +01:00
parent 8ffb5ab23e
commit 3c0005ddb0
5 changed files with 129 additions and 113 deletions

View File

@@ -62,6 +62,9 @@ class CreateEvent(FormPage):
_add_person_selector = (By.XPATH, '//a[@data-target="#id_person" and contains(@href, "add")]')
_add_item_selector = (By.XPATH, '//button[contains(@class, "item-add")]')
_event_table_selector = (By.ID, 'item-table')
_warning_selector = (By.XPATH, '/html/body/div[1]/div[1]')
form_items = {
'description': (regions.TextBox, (By.ID, 'id_description')),
@@ -86,6 +89,14 @@ class CreateEvent(FormPage):
def item_row(self, ID):
return rigs_regions.ItemRow(self, self.find_element(By.ID, "item-" + ID))
@property
def item_table(self):
return self.find_element(*self._event_table_selector)
@property
def warning(self):
return self.find_element(*self._warning_selector).text
@property
def is_expanded(self):
@@ -116,6 +127,14 @@ class CreateEvent(FormPage):
@property
def success(self):
return '/create' not in self.driver.current_url
class DuplicateEvent(CreateEvent):
URL_TEMPLATE = 'event/{event_id}/duplicate'
_submit_locator = (By.XPATH, '/html/body/div[1]/form/div/div[5]/div/button')
@property
def success(self):
return '/duplicate' not in self.driver.current_url
class GenericList(BasePage):
_search_selector = (By.CSS_SELECTOR, 'div.input-group:nth-child(2) > input:nth-child(1)')

View File

@@ -64,115 +64,6 @@ class EventTest(LiveServerTestCase):
self.assertEqual(self.live_server_url + n, self.browser.current_url)
def testEventDuplicate(self):
client = models.Person.objects.create(name='Duplicate Test Person', email='duplicate@functional.test')
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',
person=client,
auth_request_by=self.profile,
auth_request_at=self.create_datetime(2015, 0o6, 0o4, 10, 00),
auth_request_to="some@email.address")
item1 = models.EventItem(
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()
self.browser.get(self.live_server_url + '/event/' + str(testEvent.pk) + '/duplicate/')
self.authenticate('/event/' + str(testEvent.pk) + '/duplicate/')
wait = WebDriverWait(self.browser, 3) # setup WebDriverWait to use later (to wait for animations)
save = self.browser.find_element_by_xpath(
'(//button[@type="submit"])[3]')
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
# Check the items are visible
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)
# Check the info message is visible
self.assertIn("Event data duplicated but not yet saved", self.browser.find_element_by_id('content').text)
# Add item
form.find_element_by_xpath('//button[contains(@class, "item-add")]').click()
modal = self.browser.find_element_by_id("itemModal")
wait.until(animation_is_finished())
# See modal has opened
self.assertTrue(modal.is_displayed())
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 unknown 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
# Attempt to save
save.click()
newEvent = models.Event.objects.latest('pk')
self.assertEqual(newEvent.auth_request_to, None)
self.assertEqual(newEvent.auth_request_by, None)
self.assertEqual(newEvent.auth_request_at, None)
self.assertFalse(hasattr(newEvent, 'authorised'))
self.assertNotIn("N%05d" % 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
# Check the new items are visible
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)
# Check the PO hasn't carried through
self.assertNotIn("TESTPO", infoPanel.find_element_by_xpath('//dt[text()="PO"]/following-sibling::dd[1]').text)
self.assertIn("N%05d" % 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
# 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 PO remains on the old event
self.assertIn("TESTPO", infoPanel.find_element_by_xpath('//dt[text()="PO"]/following-sibling::dd[1]').text)
self.assertNotIn("N%05d" % 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
self.assertIn("Test Item 1", table.text)
self.assertIn("Test Item 2", table.text)
self.assertNotIn("Test Item 3", table.text)
def testDateValidation(self):
self.browser.get(self.live_server_url + '/event/create/')
# Gets redirected to login and back

View File

@@ -67,7 +67,7 @@ class TestRigboard(AutoLoginTest):
# Ideally get a response object to assert 200 on
class TestEventCreate(AutoLoginTest):
class TEventCreate(AutoLoginTest):
def setUp(self):
super().setUp()
self.client = models.Person.objects.create(name='Creation Test Person', email='god@functional.test')
@@ -239,3 +239,106 @@ class TestEventCreate(AutoLoginTest):
def test_subhire_creation(self):
pass
class TestEventDuplicate(AutoLoginTest):
def setUp(self):
super().setUp()
self.client = models.Person.objects.create(name='Duplicate Test Person', email='duplicate@functional.test')
self.vatrate = models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
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',
person=self.client,
auth_request_by=self.profile,
auth_request_at=base.create_datetime(2015, 0o6, 0o4, 10, 00),
auth_request_to="some@email.address")
item1 = models.EventItem(
event=self.testEvent,
name="Test Item 1",
cost="10.00",
quantity="1",
order=1
).save()
item2 = models.EventItem(
event=self.testEvent,
name="Test Item 2",
description="Foo",
cost="9.72",
quantity="3",
order=2,
).save()
self.page = pages.DuplicateEvent(self.driver, self.live_server_url, event_id=self.testEvent.pk).open()
self.wait = WebDriverWait(self.driver, 5)
def test_rig_duplicate(self):
table = self.page.item_table
self.assertIn("Test Item 1", table.text)
self.assertIn("Test Item 2", table.text)
# Check the info message is visible
self.assertIn("Event data duplicated but not yet saved", self.page.warning)
modal = self.page.add_event_item()
self.wait.until(animation_is_finished())
# See modal has opened
self.assertTrue(modal.is_open)
self.assertIn(self.testEvent.name, modal.header)
modal.name = "Test Item 3"
modal.description = "This is an item description\nthat for reasons unknown spans two lines"
modal.quantity = "2"
modal.price = "23.95"
modal.submit()
self.wait.until(animation_is_finished())
# Attempt to save
ActionChains(self.driver).move_to_element(table).perform()
self.page.submit()
# TODO Rewrite when EventDetail page is implemented
newEvent = models.Event.objects.latest('pk')
self.assertEqual(newEvent.auth_request_to, None)
self.assertEqual(newEvent.auth_request_by, None)
self.assertEqual(newEvent.auth_request_at, None)
self.assertFalse(hasattr(newEvent, 'authorised'))
self.assertNotIn("N%05d" % self.testEvent.pk, self.driver.find_element_by_xpath('//h1').text)
self.assertNotIn("Event data duplicated but not yet saved", self.page.warning) # Check info message not visible
# Check the new items are visible
table = self.page.item_table
self.assertIn("Test Item 1", table.text)
self.assertIn("Test Item 2", table.text)
self.assertIn("Test Item 3", table.text)
infoPanel = self.driver.find_element_by_xpath('//div[contains(text(), "Event Info")]/..')
self.assertIn("N0000%d" % self.testEvent.pk,
infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text)
# Check the PO hasn't carried through
self.assertNotIn("TESTPO", infoPanel.find_element_by_xpath('//dt[text()="PO"]/following-sibling::dd[1]').text)
self.assertIn("N%05d" % self.testEvent.pk,
infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text)
self.driver.get(self.live_server_url + '/event/' + str(self.testEvent.pk)) # Go back to the old event
# Check that based-on hasn't crept into the old event
infoPanel = self.driver.find_element_by_xpath('//div[contains(text(), "Event Info")]/..')
self.assertNotIn("N0000%d" % self.testEvent.pk,
infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text)
# 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.assertNotIn("N%05d" % self.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.page.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)