From c23d18cd4506f1f99593e4e7f5f6d545e0334c18 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Thu, 21 May 2020 21:19:53 +0100 Subject: [PATCH] Init other tests, more rigs test faffery --- PyRIGS/tests/regions.py | 36 +++++++ RIGS/tests/__init__.py | 0 RIGS/tests/pages.py | 6 ++ RIGS/tests/test_functional.py | 138 -------------------------- RIGS/tests/test_rigs.py | 137 ++++++++++++++++++++++++- users/tests/__init__.py | 0 versioning/migrations/0001_initial.py | 26 +++++ versioning/tests/__init__.py | 0 8 files changed, 204 insertions(+), 139 deletions(-) create mode 100644 RIGS/tests/__init__.py create mode 100644 users/tests/__init__.py create mode 100644 versioning/migrations/0001_initial.py create mode 100644 versioning/tests/__init__.py diff --git a/PyRIGS/tests/regions.py b/PyRIGS/tests/regions.py index f6e784ec..eaba96aa 100644 --- a/PyRIGS/tests/regions.py +++ b/PyRIGS/tests/regions.py @@ -181,3 +181,39 @@ class ErrorPage(Region): for error in error_items: errors[error.field_name] = error.errors return errors + + +class Modal(Region): + _submit_locator = (By.CSS_SELECTOR, '.btn-primary') + _header_selector = (By.TAG_NAME, 'h3') + + form_items = { + 'name': (TextBox, (By.ID, 'id_name')) + } + + @property + def header(self): + return self.find_element(*self._header_selector).text + + @property + def is_open(self): + return self.root.is_displayed() + + def submit(self): + self.root.find_element(*self._submit_locator).click() + + def __getattr__(self, name): + if name in self.form_items: + element = self.form_items[name] + form_element = element[0](self, self.find_element(*element[1])) + return form_element.value + else: + return super().__getattribute__(name) + + def __setattr__(self, name, value): + if name in self.form_items: + element = self.form_items[name] + form_element = element[0](self, self.find_element(*element[1])) + form_element.set_value(value) + else: + self.__dict__[name] = value diff --git a/RIGS/tests/__init__.py b/RIGS/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/RIGS/tests/pages.py b/RIGS/tests/pages.py index 37f31c99..7c4718a8 100644 --- a/RIGS/tests/pages.py +++ b/RIGS/tests/pages.py @@ -58,6 +58,8 @@ class CreateEvent(FormPage): _venue_selector_selector = (By.XPATH, '//*[@id="main"]/form/div/div[3]/div[1]/div[2]/div[1]/div/div/div[1]/div') _mic_selector_selector = (By.XPATH, '//*[@id="form-hws"]/div[7]/div[1]/div/div') + _add_person_selector = (By.XPATH, '//a[@data-target="#id_person" and contains(@href, "add")]') + form_items = { 'description': (regions.TextBox, (By.ID, 'id_description')), @@ -95,6 +97,10 @@ class CreateEvent(FormPage): def mic_selector(self): return regions.BootstrapSelectElement(self, self.find_element(*self._mic_selector_selector)) + def add_person(self): + self.find_element(*self._add_person_selector).click() + return regions.Modal(self, self.driver.find_element_by_id('modal')) + @property def success(self): return '/create' not in self.driver.current_url diff --git a/RIGS/tests/test_functional.py b/RIGS/tests/test_functional.py index 0d0db6d1..69843c35 100644 --- a/RIGS/tests/test_functional.py +++ b/RIGS/tests/test_functional.py @@ -93,144 +93,6 @@ class EventTest(LiveServerTestCase): e = self.browser.find_element_by_id('id_name') e.send_keys('Test Event Name') - # Create new person - wait.until(animation_is_finished()) - add_person_button = self.browser.find_element_by_xpath( - '//a[@data-target="#id_person" and contains(@href, "add")]') - add_person_button.click() - - # See modal has opened - 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) - - # Fill person form out and submit - modal.find_element_by_xpath( - '//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Person 1") - modal.find_element_by_xpath( - '//div[@id="modal"]//input[@type="submit"]').click() - wait.until(animation_is_finished()) - self.assertFalse(modal.is_displayed()) - - # See new person selected - person1 = models.Person.objects.get(name="Test Person 1") - self.assertEqual(person1.name, form.find_element_by_xpath( - '//button[@data-id="id_person"]/span').text) - # and backend - option = form.find_element_by_xpath( - '//select[@id="id_person"]//option[@selected="selected"]') - self.assertEqual(person1.pk, int(option.get_attribute("value"))) - - # Change mind and add another - wait.until(animation_is_finished()) - add_person_button.click() - - wait.until(animation_is_finished()) - self.assertTrue(modal.is_displayed()) - 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") - modal.find_element_by_xpath( - '//div[@id="modal"]//input[@type="submit"]').click() - wait.until(animation_is_finished()) - self.assertFalse(modal.is_displayed()) - - person2 = models.Person.objects.get(name="Test Person 2") - self.assertEqual(person2.name, form.find_element_by_xpath( - '//button[@data-id="id_person"]/span').text) - # Have to do this explcitly to force the wait for it to update - option = form.find_element_by_xpath( - '//select[@id="id_person"]//option[@selected="selected"]') - self.assertEqual(person2.pk, int(option.get_attribute("value"))) - - # Was right the first time, change it back - person_select = form.find_element_by_xpath( - '//button[@data-id="id_person"]') - person_select.send_keys(person1.name) - person_dropped = form.find_element_by_xpath( - '//ul[contains(@class, "dropdown-menu")]//span[contains(text(), "%s")]' % person1.name) - person_dropped.click() - - self.assertEqual(person1.name, form.find_element_by_xpath( - '//button[@data-id="id_person"]/span').text) - option = form.find_element_by_xpath( - '//select[@id="id_person"]//option[@selected="selected"]') - self.assertEqual(person1.pk, int(option.get_attribute("value"))) - - # Edit Person 1 to have a better name - form.find_element_by_xpath( - '//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) - name = modal.find_element_by_xpath( - '//div[@id="modal"]//input[@id="id_name"]') - self.assertEqual(person1.name, name.get_attribute('value')) - name.clear() - name.send_keys('Rig ' + person1.name) - name.send_keys(Keys.ENTER) - - wait.until(animation_is_finished()) - - self.assertFalse(modal.is_displayed()) - person1 = models.Person.objects.get(pk=person1.pk) - self.assertEqual(person1.name, form.find_element_by_xpath( - '//button[@data-id="id_person"]/span').text) - - # Create organisation - wait.until(animation_is_finished()) - add_button = self.browser.find_element_by_xpath( - '//a[@data-target="#id_organisation" and contains(@href, "add")]') - add_button.click() - 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) - modal.find_element_by_xpath( - '//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Organisation") - modal.find_element_by_xpath( - '//div[@id="modal"]//input[@type="submit"]').click() - - # See it is selected - wait.until(animation_is_finished()) - self.assertFalse(modal.is_displayed()) - obj = models.Organisation.objects.get(name="Test Organisation") - self.assertEqual(obj.name, form.find_element_by_xpath( - '//button[@data-id="id_organisation"]/span').text) - # and backend - option = form.find_element_by_xpath( - '//select[@id="id_organisation"]//option[@selected="selected"]') - self.assertEqual(obj.pk, int(option.get_attribute("value"))) - - # Create venue - wait.until(animation_is_finished()) - add_button = self.browser.find_element_by_xpath( - '//a[@data-target="#id_venue" and contains(@href, "add")]') - wait.until(animation_is_finished()) - add_button.click() - wait.until(animation_is_finished()) - 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) - modal.find_element_by_xpath( - '//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Venue") - modal.find_element_by_xpath( - '//div[@id="modal"]//input[@type="submit"]').click() - - # See it is selected - wait.until(animation_is_finished()) - self.assertFalse(modal.is_displayed()) - obj = models.Venue.objects.get(name="Test Venue") - self.assertEqual(obj.name, form.find_element_by_xpath( - '//button[@data-id="id_venue"]/span').text) - # and backend - option = form.find_element_by_xpath( - '//select[@id="id_venue"]//option[@selected="selected"]') - self.assertEqual(obj.pk, int(option.get_attribute("value"))) - # Set start date/time form.find_element_by_id('id_start_date').send_keys('25/05/3015') form.find_element_by_id('id_start_time').send_keys('06:59') diff --git a/RIGS/tests/test_rigs.py b/RIGS/tests/test_rigs.py index 373e6e83..237497b5 100644 --- a/RIGS/tests/test_rigs.py +++ b/RIGS/tests/test_rigs.py @@ -17,7 +17,7 @@ from RIGS.tests import regions import datetime from datetime import date, time, timedelta from django.utils import timezone - +from selenium.webdriver.support.select import Select class TestRigboard(AutoLoginTest): def setUp(self): @@ -105,6 +105,141 @@ class TestEventCreate(AutoLoginTest): self.page.submit() self.assertTrue(self.page.success) + # TODO + def test_modals(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) + # Create new person + modal = self.page.add_person() + # animation_is_finished doesn't work for whatever reason... + self.wait.until(EC.visibility_of_element_located((By.ID, 'modal'))) + self.assertTrue(modal.is_open) + self.assertIn("Add Person", modal.header) + + # Fill person form out and submit + person_name = "Test Person" + modal.name = person_name + modal.submit() + self.wait.until(EC.invisibility_of_element_located((By.ID, 'modal'))) + self.assertFalse(modal.is_open) + + # See new person selected + select_element = self.driver.find_element(By.ID,'id_person') + select_object = Select(select_element) + + person1 = models.Person.objects.get(name=person_name) + self.assertEqual(person1.name, select_object.first_selected_option.text) + # and backend + # self.assertEqual(person1.pk, int(self.page.person_selector.get_attribute("value"))) + + # Change mind and add another + self.wait.until(animation_is_finished()) + modal = self.page.add_person() + self.wait.until(EC.visibility_of_element_located((By.ID, 'modal'))) + self.assertTrue(modal.is_open) + self.assertIn("Add Person", modal.header) + + person_name = "Test Person 2" + modal.name = person_name + modal.submit() + self.wait.until(EC.invisibility_of_element_located((By.ID, 'modal'))) + self.assertFalse(modal.is_open) + + person2 = models.Person.objects.get(name=person_name) + options = list((x for x in self.page.person_selector.options if x.selected)) + self.assertTrue(len(options) == 1) + self.assertEqual(person2.name, options[0].name) + # and backend + # self.assertEqual(person1.pk, int(self.page.person_selector.get_attribute("value"))) + + # Was right the first time, change it back + self.page.person_selector.search(person1.name) + # TODO Check multiple cannot be selected? Is that necessary? + self.page.person_selector.set_option(person1.name, True) + + options = list((x for x in self.page.person_selector.options if x.selected)) + self.assertTrue(len(options) == 1) + self.assertEqual(person2.name, options[0].name) + # and backend + # self.assertEqual(person1.pk, int(self.page.person_selector.get_attribute("value"))) + + pass + + # Edit Person 1 to have a better name + form.find_element_by_xpath( + '//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) + name = modal.find_element_by_xpath( + '//div[@id="modal"]//input[@id="id_name"]') + self.assertEqual(person1.name, name.get_attribute('value')) + name.clear() + name.send_keys('Rig ' + person1.name) + name.send_keys(Keys.ENTER) + + wait.until(animation_is_finished()) + + self.assertFalse(modal.is_displayed()) + person1 = models.Person.objects.get(pk=person1.pk) + self.assertEqual(person1.name, form.find_element_by_xpath( + '//button[@data-id="id_person"]/span').text) + + # Create organisation + wait.until(animation_is_finished()) + add_button = self.browser.find_element_by_xpath( + '//a[@data-target="#id_organisation" and contains(@href, "add")]') + add_button.click() + 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) + modal.find_element_by_xpath( + '//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Organisation") + modal.find_element_by_xpath( + '//div[@id="modal"]//input[@type="submit"]').click() + + # See it is selected + wait.until(animation_is_finished()) + self.assertFalse(modal.is_displayed()) + obj = models.Organisation.objects.get(name="Test Organisation") + self.assertEqual(obj.name, form.find_element_by_xpath( + '//button[@data-id="id_organisation"]/span').text) + # and backend + option = form.find_element_by_xpath( + '//select[@id="id_organisation"]//option[@selected="selected"]') + self.assertEqual(obj.pk, int(option.get_attribute("value"))) + + # Create venue + wait.until(animation_is_finished()) + add_button = self.browser.find_element_by_xpath( + '//a[@data-target="#id_venue" and contains(@href, "add")]') + wait.until(animation_is_finished()) + add_button.click() + wait.until(animation_is_finished()) + 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) + modal.find_element_by_xpath( + '//div[@id="modal"]//input[@id="id_name"]').send_keys("Test Venue") + modal.find_element_by_xpath( + '//div[@id="modal"]//input[@type="submit"]').click() + + # See it is selected + wait.until(animation_is_finished()) + self.assertFalse(modal.is_displayed()) + obj = models.Venue.objects.get(name="Test Venue") + self.assertEqual(obj.name, form.find_element_by_xpath( + '//button[@data-id="id_venue"]/span').text) + # and backend + option = form.find_element_by_xpath( + '//select[@id="id_venue"]//option[@selected="selected"]') + self.assertEqual(obj.pk, int(option.get_attribute("value"))) + # TODO Testing of internal rig (approval system interface) def test_non_rig_creation(self): diff --git a/users/tests/__init__.py b/users/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/versioning/migrations/0001_initial.py b/versioning/migrations/0001_initial.py new file mode 100644 index 00000000..8db79f2c --- /dev/null +++ b/versioning/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# Generated by Django 3.0.3 on 2020-05-21 01:41 + +from django.db import migrations + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('reversion', '0001_squashed_0004_auto_20160611_1202'), + ] + + operations = [ + migrations.CreateModel( + name='RIGSVersion', + fields=[ + ], + options={ + 'proxy': True, + 'indexes': [], + 'constraints': [], + }, + bases=('reversion.version',), + ), + ] diff --git a/versioning/tests/__init__.py b/versioning/tests/__init__.py new file mode 100644 index 00000000..e69de29b