Init other tests, more rigs test faffery

This commit is contained in:
2020-05-21 21:19:53 +01:00
parent 5a3547ea74
commit c23d18cd45
8 changed files with 204 additions and 139 deletions

View File

@@ -181,3 +181,39 @@ class ErrorPage(Region):
for error in error_items: for error in error_items:
errors[error.field_name] = error.errors errors[error.field_name] = error.errors
return 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

0
RIGS/tests/__init__.py Normal file
View File

View File

@@ -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') _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') _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 = { form_items = {
'description': (regions.TextBox, (By.ID, 'id_description')), 'description': (regions.TextBox, (By.ID, 'id_description')),
@@ -95,6 +97,10 @@ class CreateEvent(FormPage):
def mic_selector(self): def mic_selector(self):
return regions.BootstrapSelectElement(self, self.find_element(*self._mic_selector_selector)) 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 @property
def success(self): def success(self):
return '/create' not in self.driver.current_url return '/create' not in self.driver.current_url

View File

@@ -93,144 +93,6 @@ class EventTest(LiveServerTestCase):
e = self.browser.find_element_by_id('id_name') e = self.browser.find_element_by_id('id_name')
e.send_keys('Test Event 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 # Set start date/time
form.find_element_by_id('id_start_date').send_keys('25/05/3015') 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') form.find_element_by_id('id_start_time').send_keys('06:59')

View File

@@ -17,7 +17,7 @@ from RIGS.tests import regions
import datetime import datetime
from datetime import date, time, timedelta from datetime import date, time, timedelta
from django.utils import timezone from django.utils import timezone
from selenium.webdriver.support.select import Select
class TestRigboard(AutoLoginTest): class TestRigboard(AutoLoginTest):
def setUp(self): def setUp(self):
@@ -105,6 +105,141 @@ class TestEventCreate(AutoLoginTest):
self.page.submit() self.page.submit()
self.assertTrue(self.page.success) 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) # TODO Testing of internal rig (approval system interface)
def test_non_rig_creation(self): def test_non_rig_creation(self):

0
users/tests/__init__.py Normal file
View File

View File

@@ -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',),
),
]

View File