From 3c0005ddb01ce376feaf8035ba9d68404fdfd1d3 Mon Sep 17 00:00:00 2001 From: Arona Date: Sat, 23 May 2020 23:48:11 +0100 Subject: [PATCH] Initial port of duplicate testing Needs the latter half rewriting once we have an EventDetail POM --- RIGS/tests/pages.py | 19 ++++++ RIGS/tests/test_functional.py | 109 ---------------------------------- RIGS/tests/test_rigs.py | 105 +++++++++++++++++++++++++++++++- package.json | 7 ++- requirements.txt | 2 +- 5 files changed, 129 insertions(+), 113 deletions(-) diff --git a/RIGS/tests/pages.py b/RIGS/tests/pages.py index 857e5457..0ebeb381 100644 --- a/RIGS/tests/pages.py +++ b/RIGS/tests/pages.py @@ -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)') diff --git a/RIGS/tests/test_functional.py b/RIGS/tests/test_functional.py index 7b30c6c9..3f541231 100644 --- a/RIGS/tests/test_functional.py +++ b/RIGS/tests/test_functional.py @@ -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 diff --git a/RIGS/tests/test_rigs.py b/RIGS/tests/test_rigs.py index e34fce31..eb4cd0df 100644 --- a/RIGS/tests/test_rigs.py +++ b/RIGS/tests/test_rigs.py @@ -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) diff --git a/package.json b/package.json index 147cc61e..65f1f983 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,14 @@ "browser-sync": "^2.26.7", "gulp": "^4.0.2", "gulp-clean-css": "^4.2.0", + "gulp-flatten": "^0.4.0", "gulp-postcss": "^8.0.0", "gulp-sass": "^4.0.2", "gulp-sourcemaps": "^2.6.5", "gulp-terser": "^1.2.0", - "node-sass": "^4.13.1", - "gulp-flatten": "^0.4.0" + "node-sass": "^4.13.1" + }, + "scripts": { + "gulp": "gulp" } } diff --git a/requirements.txt b/requirements.txt index 569e0366..2a602d9c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ gunicorn==20.0.4 icalendar==4.0.4 lxml==4.5.0 premailer==3.6.1 -psycopg2==2.8.4 +psycopg2-binary==2.8.4 PyPDF2==1.26.0 PyPOM==2.2.0 pytz==2019.3