mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-22 16:02:16 +00:00
Fix tests after form split
This commit is contained in:
@@ -43,15 +43,22 @@ def venue(db):
|
|||||||
|
|
||||||
@pytest.fixture # TODO parameterise with Event sizes
|
@pytest.fixture # TODO parameterise with Event sizes
|
||||||
def checklist(basic_event, venue, admin_user, ra):
|
def checklist(basic_event, venue, admin_user, ra):
|
||||||
checklist = models.EventChecklist.objects.create(event=basic_event, power_mic=admin_user, safe_parking=False,
|
checklist = models.EventChecklist.objects.create(event=basic_event, safe_parking=False,
|
||||||
safe_packing=False, exits=False, trip_hazard=False, warning_signs=False,
|
safe_packing=False, exits=False, trip_hazard=False, warning_signs=False,
|
||||||
ear_plugs=False, hs_location="Locked away safely",
|
ear_plugs=False, hs_location="Locked away safely",
|
||||||
extinguishers_location="Somewhere, I forgot", earthing=False, pat=False,
|
extinguishers_location="Somewhere, I forgot",
|
||||||
date=timezone.now(), venue=venue)
|
date=timezone.now(), venue=venue)
|
||||||
yield checklist
|
yield checklist
|
||||||
checklist.delete()
|
checklist.delete()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def power_test(basic_event, venue, admin_user, ra):
|
||||||
|
power_test = models.PowerTestRecord.objects.create(event=basic_event, venue=venue)
|
||||||
|
yield power_test
|
||||||
|
power_test.delete()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def many_events(db, admin_user, scope="class"):
|
def many_events(db, admin_user, scope="class"):
|
||||||
many_events = {
|
many_events = {
|
||||||
|
|||||||
@@ -230,11 +230,6 @@ class CreateEventChecklist(FormPage):
|
|||||||
URL_TEMPLATE = 'event/{event_id}/checklist'
|
URL_TEMPLATE = 'event/{event_id}/checklist'
|
||||||
|
|
||||||
_submit_locator = (By.XPATH, "//button[@type='submit' and contains(., 'Save')]")
|
_submit_locator = (By.XPATH, "//button[@type='submit' and contains(., 'Save')]")
|
||||||
_power_mic_selector = (By.XPATH, "//div[select[@id='id_power_mic']]")
|
|
||||||
_add_vehicle_locator = (By.XPATH, "//button[contains(., 'Vehicle')]")
|
|
||||||
_add_crew_locator = (By.XPATH, "//button[contains(., 'Crew')]")
|
|
||||||
_vehicle_row_locator = ('xpath', "//tr[@id[starts-with(., 'vehicle') and not(contains(.,'new'))]]")
|
|
||||||
_crew_row_locator = ('xpath', "//tr[@id[starts-with(., 'crew') and not(contains(.,'new'))]]")
|
|
||||||
|
|
||||||
form_items = {
|
form_items = {
|
||||||
'safe_parking': (regions.CheckBox, (By.ID, 'id_safe_parking')),
|
'safe_parking': (regions.CheckBox, (By.ID, 'id_safe_parking')),
|
||||||
@@ -245,6 +240,20 @@ class CreateEventChecklist(FormPage):
|
|||||||
'ear_plugs': (regions.CheckBox, (By.ID, 'id_ear_plugs')),
|
'ear_plugs': (regions.CheckBox, (By.ID, 'id_ear_plugs')),
|
||||||
'hs_location': (regions.TextBox, (By.ID, 'id_hs_location')),
|
'hs_location': (regions.TextBox, (By.ID, 'id_hs_location')),
|
||||||
'extinguishers_location': (regions.TextBox, (By.ID, 'id_extinguishers_location')),
|
'extinguishers_location': (regions.TextBox, (By.ID, 'id_extinguishers_location')),
|
||||||
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def success(self):
|
||||||
|
return '{event_id}' not in self.driver.current_url
|
||||||
|
|
||||||
|
|
||||||
|
class CreatePowerTestRecord(FormPage):
|
||||||
|
URL_TEMPLATE = 'event/{event_id}/power'
|
||||||
|
|
||||||
|
_submit_locator = (By.XPATH, "//button[@type='submit' and contains(., 'Save')]")
|
||||||
|
_power_mic_selector = (By.XPATH, "//div[select[@id='id_power_mic']]")
|
||||||
|
|
||||||
|
form_items = {
|
||||||
'rcds': (regions.CheckBox, (By.ID, 'id_rcds')),
|
'rcds': (regions.CheckBox, (By.ID, 'id_rcds')),
|
||||||
'supply_test': (regions.CheckBox, (By.ID, 'id_supply_test')),
|
'supply_test': (regions.CheckBox, (By.ID, 'id_supply_test')),
|
||||||
'earthing': (regions.CheckBox, (By.ID, 'id_earthing')),
|
'earthing': (regions.CheckBox, (By.ID, 'id_earthing')),
|
||||||
@@ -263,58 +272,10 @@ class CreateEventChecklist(FormPage):
|
|||||||
'w1_earth_fault': (regions.TextBox, (By.ID, 'id_w1_earth_fault')),
|
'w1_earth_fault': (regions.TextBox, (By.ID, 'id_w1_earth_fault')),
|
||||||
}
|
}
|
||||||
|
|
||||||
def add_vehicle(self):
|
|
||||||
self.find_element(*self._add_vehicle_locator).click()
|
|
||||||
|
|
||||||
def add_crew(self):
|
|
||||||
self.find_element(*self._add_crew_locator).click()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def power_mic(self):
|
def power_mic(self):
|
||||||
return regions.BootstrapSelectElement(self, self.find_element(*self._power_mic_selector))
|
return regions.BootstrapSelectElement(self, self.find_element(*self._power_mic_selector))
|
||||||
|
|
||||||
@property
|
|
||||||
def vehicles(self):
|
|
||||||
return [self.VehicleRow(self, el) for el in self.find_elements(*self._vehicle_row_locator)]
|
|
||||||
|
|
||||||
class VehicleRow(Region):
|
|
||||||
_name_locator = ('xpath', ".//input")
|
|
||||||
_select_locator = ('xpath', ".//div[contains(@class,'bootstrap-select')]/..")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
return regions.TextBox(self, self.root.find_element(*self._name_locator))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def vehicle(self):
|
|
||||||
return regions.BootstrapSelectElement(self, self.root.find_element(*self._select_locator))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def crew(self):
|
|
||||||
return [self.CrewRow(self, el) for el in self.find_elements(*self._crew_row_locator)]
|
|
||||||
|
|
||||||
class CrewRow(Region):
|
|
||||||
_select_locator = ('xpath', ".//div[contains(@class,'bootstrap-select')]/..")
|
|
||||||
_start_time_locator = ('xpath', ".//input[@name[starts-with(., 'start') and not(contains(.,'new'))]]")
|
|
||||||
_end_time_locator = ('xpath', ".//input[@name[starts-with(., 'end') and not(contains(.,'new'))]]")
|
|
||||||
_role_locator = ('xpath', ".//input[@name[starts-with(., 'role') and not(contains(.,'new'))]]")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def crewmember(self):
|
|
||||||
return regions.BootstrapSelectElement(self, self.root.find_element(*self._select_locator))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def start_time(self):
|
|
||||||
return regions.DateTimePicker(self, self.root.find_element(*self._start_time_locator))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def end_time(self):
|
|
||||||
return regions.DateTimePicker(self, self.root.find_element(*self._end_time_locator))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def role(self):
|
|
||||||
return regions.TextBox(self, self.root.find_element(*self._role_locator))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self):
|
def success(self):
|
||||||
return '{event_id}' not in self.driver.current_url
|
return '{event_id}' not in self.driver.current_url
|
||||||
|
|||||||
@@ -676,14 +676,6 @@ def small_ec(page, admin_user):
|
|||||||
page.ear_plugs = True
|
page.ear_plugs = True
|
||||||
page.hs_location = "The Moon"
|
page.hs_location = "The Moon"
|
||||||
page.extinguishers_location = "With the rest of the fire"
|
page.extinguishers_location = "With the rest of the fire"
|
||||||
# If we do this first the search fails, for ... reasons
|
|
||||||
page.power_mic.search(admin_user.name)
|
|
||||||
page.power_mic.toggle()
|
|
||||||
assert not page.power_mic.is_open
|
|
||||||
page.earthing = True
|
|
||||||
page.rcds = True
|
|
||||||
page.supply_test = True
|
|
||||||
page.pat = True
|
|
||||||
|
|
||||||
|
|
||||||
def test_ec_create_small(logged_in_browser, live_server, admin_user, ra):
|
def test_ec_create_small(logged_in_browser, live_server, admin_user, ra):
|
||||||
@@ -704,14 +696,15 @@ def test_ec_create_medium(logged_in_browser, live_server, admin_user, medium_ra)
|
|||||||
page.ear_plugs = True
|
page.ear_plugs = True
|
||||||
page.hs_location = "Death Valley"
|
page.hs_location = "Death Valley"
|
||||||
page.extinguishers_location = "With the rest of the fire"
|
page.extinguishers_location = "With the rest of the fire"
|
||||||
# If we do this first the search fails, for ... reasons
|
|
||||||
page.power_mic.search(admin_user.name)
|
|
||||||
page.power_mic.toggle()
|
|
||||||
assert not page.power_mic.is_open
|
|
||||||
|
|
||||||
# Gotta scroll to make the button clickable
|
# Gotta scroll to make the button clickable
|
||||||
logged_in_browser.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
logged_in_browser.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
||||||
|
page.submit()
|
||||||
|
assert page.success
|
||||||
|
|
||||||
|
|
||||||
|
def test_power_checklist(logged_in_browser, live_server, admin_user, power_test, medium_ra):
|
||||||
|
page = pages.CreatePowerTestRecord(logged_in_browser.driver, live_server.url, event_id=medium_ra.event.pk).open()
|
||||||
page.earthing = True
|
page.earthing = True
|
||||||
page.pat = True
|
page.pat = True
|
||||||
page.source_rcd = True
|
page.source_rcd = True
|
||||||
@@ -726,56 +719,15 @@ def test_ec_create_medium(logged_in_browser, live_server, admin_user, medium_ra)
|
|||||||
page.w1_polarity = True
|
page.w1_polarity = True
|
||||||
page.w1_voltage = 240
|
page.w1_voltage = 240
|
||||||
page.w1_earth_fault = "0.42"
|
page.w1_earth_fault = "0.42"
|
||||||
|
# If we do this first the search fails, for ... reasons
|
||||||
|
page.power_mic.search(admin_user.name)
|
||||||
|
page.power_mic.toggle()
|
||||||
|
assert not page.power_mic.is_open
|
||||||
|
|
||||||
page.submit()
|
page.submit()
|
||||||
assert page.success
|
assert page.success
|
||||||
|
|
||||||
|
|
||||||
def test_ec_create_vehicle(logged_in_browser, live_server, admin_user, checklist):
|
|
||||||
page = pages.EditEventChecklist(logged_in_browser.driver, live_server.url, pk=checklist.pk).open()
|
|
||||||
small_ec(page, admin_user)
|
|
||||||
page.add_vehicle()
|
|
||||||
assert len(page.vehicles) == 1
|
|
||||||
vehicle_name = 'Brian'
|
|
||||||
page.vehicles[0].name.set_value(vehicle_name)
|
|
||||||
# Appears we're moving too fast for javascript...
|
|
||||||
t.sleep(1)
|
|
||||||
page.vehicles[0].vehicle.search(admin_user.first_name)
|
|
||||||
t.sleep(1)
|
|
||||||
page.submit()
|
|
||||||
assert page.success
|
|
||||||
# Check data is correct
|
|
||||||
checklist.refresh_from_db()
|
|
||||||
vehicle = models.EventChecklistVehicle.objects.get(checklist=checklist.pk)
|
|
||||||
assert vehicle_name == vehicle.vehicle
|
|
||||||
|
|
||||||
|
|
||||||
# TODO Test validation of end before start
|
|
||||||
def test_ec_create_crew(logged_in_browser, live_server, admin_user, checklist):
|
|
||||||
page = pages.EditEventChecklist(logged_in_browser.driver, live_server.url, pk=checklist.pk).open()
|
|
||||||
small_ec(page, admin_user)
|
|
||||||
page.add_crew()
|
|
||||||
assert len(page.crew) == 1
|
|
||||||
role = "MIC"
|
|
||||||
start_time = timezone.make_aware(datetime.datetime(2015, 1, 1, 9, 0))
|
|
||||||
end_time = timezone.make_aware(datetime.datetime(2015, 1, 1, 10, 30))
|
|
||||||
crew = page.crew[0]
|
|
||||||
t.sleep(2)
|
|
||||||
crew.crewmember.search(admin_user.first_name)
|
|
||||||
t.sleep(2)
|
|
||||||
crew.role.set_value(role)
|
|
||||||
crew.start_time.set_value(start_time)
|
|
||||||
crew.end_time.set_value(end_time)
|
|
||||||
page.submit()
|
|
||||||
assert page.success
|
|
||||||
# Check data is correct
|
|
||||||
crew_obj = models.EventChecklistCrew.objects.get(checklist=checklist.pk)
|
|
||||||
assert admin_user.pk == crew_obj.crewmember.pk
|
|
||||||
assert role == crew_obj.role
|
|
||||||
assert start_time == crew_obj.start
|
|
||||||
assert end_time == crew_obj.end
|
|
||||||
|
|
||||||
|
|
||||||
# TODO Can I loop through all the boolean fields and test them at once?
|
# TODO Can I loop through all the boolean fields and test them at once?
|
||||||
def test_ra_creation(logged_in_browser, live_server, admin_user, basic_event):
|
def test_ra_creation(logged_in_browser, live_server, admin_user, basic_event):
|
||||||
page = pages.CreateRiskAssessment(logged_in_browser.driver, live_server.url, event_id=basic_event.pk).open()
|
page = pages.CreateRiskAssessment(logged_in_browser.driver, live_server.url, event_id=basic_event.pk).open()
|
||||||
|
|||||||
Reference in New Issue
Block a user