mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Initial work on event create test reimpl
This commit is contained in:
@@ -4,6 +4,7 @@ from selenium.webdriver.support import expected_conditions
|
||||
from selenium.webdriver.remote.webelement import WebElement
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support.select import Select
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
import datetime
|
||||
|
||||
|
||||
@@ -33,10 +34,10 @@ class BootstrapSelectElement(Region):
|
||||
def toggle(self):
|
||||
original_state = self.is_open
|
||||
option_box = self.find_element(*self._option_box_locator)
|
||||
if original_state:
|
||||
self.wait.until(expected_conditions.invisibility_of_element_located(option_box))
|
||||
if not original_state:
|
||||
self.wait.until(expected_conditions.invisibility_of_element(option_box))
|
||||
else:
|
||||
self.wait.until(expected_conditions.visibility_of_element_located(option_box))
|
||||
self.wait.until(expected_conditions.visibility_of(option_box))
|
||||
return self.find_element(*self._main_button_locator).click()
|
||||
|
||||
def open(self):
|
||||
@@ -122,6 +123,31 @@ class DatePicker(Region):
|
||||
self.root.send_keys(value.strftime("%d%m%Y"))
|
||||
|
||||
|
||||
class TimePicker(Region):
|
||||
@property
|
||||
def value(self):
|
||||
return datetime.datetime.strptime(self.root.get_attribute("value"), "%H:%M")
|
||||
|
||||
def set_value(self, value):
|
||||
self.root.clear()
|
||||
self.root.send_keys(value.strftime("%H:%M"))
|
||||
|
||||
|
||||
class DateTimePicker(Region):
|
||||
@property
|
||||
def value(self):
|
||||
return datetime.datetime.strptime(self.root.get_attribute("value"), "%Y-%m-%d %H:%M")
|
||||
|
||||
def set_value(self, value):
|
||||
self.root.clear()
|
||||
|
||||
date = value.date().strftime("%d%m%Y")
|
||||
time = value.time().strftime("%H%M")
|
||||
|
||||
self.root.send_keys(date)
|
||||
self.root.send_keys(Keys.TAB)
|
||||
self.root.send_keys(time)
|
||||
|
||||
class SingleSelectPicker(Region):
|
||||
@property
|
||||
def value(self):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% load widget_tweaks %}
|
||||
<div class="col-md-6 mt-3">
|
||||
<div class="card form-hws form-is_rig {% if object.pk and not object.is_rig %}hidden{% endif %}">
|
||||
<div class="card form-hws form-is_rig {% if object.pk and not object.is_rig %}hidden{% endif %} mb-3">
|
||||
<div class="card-header">Contact Details</div>
|
||||
<div class="card-body">
|
||||
<div class="form-group" data-toggle="tooltip" title="The main contact for the event, can be left blank if purely an organisation">
|
||||
@@ -17,11 +17,11 @@
|
||||
</div>
|
||||
<div class="col-sm-3 col-md-5 col-lg-4 align-right">
|
||||
<div class="btn-group">
|
||||
<a href="{% url 'person_create' %}" class="btn btn-outline-success modal-href"
|
||||
<a href="{% url 'person_create' %}" class="btn btn-success modal-href"
|
||||
data-target="#{{ form.person.id_for_label }}">
|
||||
<span class="fas fa-plus"></span>
|
||||
</a>
|
||||
<a href="{% if form.person.value %}{% url 'person_update' form.person.value %}{% endif %}" class="btn btn-outline-warning modal-href" id="{{ form.person.id_for_label }}-update" data-target="#{{ form.person.id_for_label }}">
|
||||
<a href="{% if form.person.value %}{% url 'person_update' form.person.value %}{% endif %}" class="btn btn-warning modal-href" id="{{ form.person.id_for_label }}-update" data-target="#{{ form.person.id_for_label }}">
|
||||
<span class="fas fa-user-edit"></span>
|
||||
</a>
|
||||
</div>
|
||||
@@ -44,11 +44,11 @@
|
||||
</div>
|
||||
<div class="col-sm-3 col-md-5 col-lg-4 align-right">
|
||||
<div class="btn-group">
|
||||
<a href="{% url 'organisation_create' %}" class="btn btn-outline-success modal-href"
|
||||
<a href="{% url 'organisation_create' %}" class="btn btn-success modal-href"
|
||||
data-target="#{{ form.organisation.id_for_label }}">
|
||||
<span class="fas fa-plus"></span>
|
||||
</a>
|
||||
<a href="{% if form.organisation.value %}{% url 'organisation_update' form.organisation.value %}{% endif %}" class="btn btn-outline-warning modal-href" id="{{ form.organisation.id_for_label }}-update" data-target="#{{ form.organisation.id_for_label }}">
|
||||
<a href="{% if form.organisation.value %}{% url 'organisation_update' form.organisation.value %}{% endif %}" class="btn btn-warning modal-href" id="{{ form.organisation.id_for_label }}-update" data-target="#{{ form.organisation.id_for_label }}">
|
||||
<span class="fas fa-edit"></span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
</div>
|
||||
<div class="col-sm-3 col-md-5 col-lg-4 align-right">
|
||||
<div class="btn-group">
|
||||
<a href="{% url 'venue_create' %}" class="btn btn-default modal-href"
|
||||
<a href="{% url 'venue_create' %}" class="btn btn-success modal-href"
|
||||
data-target="#{{ form.venue.id_for_label }}">
|
||||
<span class="fas fa-plus"></span>
|
||||
</a>
|
||||
<a href="{% if object.venue %}{% url 'venue_update' object.venue.pk %}{% endif %}" class="btn btn-default modal-href" id="{{ form.venue.id_for_label }}-update" data-target="#{{ form.venue.id_for_label }}">
|
||||
<a href="{% if object.venue %}{% url 'venue_update' object.venue.pk %}{% endif %}" class="btn btn-warning modal-href" id="{{ form.venue.id_for_label }}-update" data-target="#{{ form.venue.id_for_label }}">
|
||||
<span class="fas fa-edit"></span>
|
||||
</a>
|
||||
</div>
|
||||
@@ -63,19 +63,10 @@
|
||||
<div class="col-sm-12 col-md-7" data-toggle="tooltip" title="End date of event, leave blank if unknown or same as start date">
|
||||
{% render_field form.end_date class+="form-control" %}
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-5" data-toggle="tooltip" title="End time of event, leave blank if unknown">
|
||||
<div class="col-sm-12 col-md-4" data-toggle="tooltip" title="End time of event, leave blank if unknown">
|
||||
{% render_field form.end_time class+="form-control" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-offset-7 col-md-5">
|
||||
<div class="btn-group btn-group-justified">
|
||||
<btn class="btn btn-default btn-xs" onclick="setTime23Hours()">23:00</btn>
|
||||
<btn class="btn btn-default btn-xs" onclick="setTime02Hours()">02:00</btn>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -47,6 +47,58 @@ class Rigboard(BasePage):
|
||||
return [self.EventListRow(self, i) for i in self.find_elements(*self._event_row_locator)]
|
||||
|
||||
|
||||
class CreateEvent(FormPage):
|
||||
URL_TEMPLATE = reverse('event_create')
|
||||
|
||||
_is_rig_selector = (By.ID, 'is_rig-selector')
|
||||
_bottom_save_selector = (By.XPATH, '//*[@id="main"]/form/div/div[6]/div/button')
|
||||
_submit_locator = _bottom_save_selector
|
||||
# TODO The ID is now no longer on the highest level element on the selector, annoyingly
|
||||
_person_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')
|
||||
|
||||
form_items = {
|
||||
'description': (regions.TextBox, (By.ID, 'id_description')),
|
||||
|
||||
'name': (regions.TextBox, (By.ID, 'id_name')),
|
||||
'start_date': (regions.DatePicker, (By.ID, 'id_start_date')),
|
||||
'start_time': (regions.TimePicker, (By.ID, 'id_start_time')),
|
||||
'end_date': (regions.DatePicker, (By.ID, 'id_start_date')),
|
||||
'end_time': (regions.TimePicker, (By.ID, 'id_start_time')),
|
||||
'access_at': (regions.DateTimePicker, (By.ID, 'id_access_at')),
|
||||
'meet_at': (regions.DateTimePicker, (By.ID, 'id_meet_at')),
|
||||
'dry_hire': (regions.CheckBox, (By.ID, 'id_dry_hire')),
|
||||
'status': (regions.SingleSelectPicker, (By.ID, 'id_status')),
|
||||
'collected_by': (regions.TextBox, (By.ID, 'id_collector')),
|
||||
'po': (regions.TextBox, (By.ID, 'id_purchase_order')),
|
||||
|
||||
'notes': (regions.TextBox, (By.ID, 'id_notes'))
|
||||
}
|
||||
|
||||
def select_event_type(self, type_name):
|
||||
self.find_element(By.XPATH, '//button[.="' + type_name + '"]').click()
|
||||
|
||||
@property
|
||||
def is_expanded(self):
|
||||
return self.find_element(*self._bottom_save_selector).is_displayed()
|
||||
|
||||
@property
|
||||
def person_selector(self):
|
||||
return regions.BootstrapSelectElement(self, self.find_element(*self._person_selector_selector))
|
||||
|
||||
@property
|
||||
def venue_selector(self):
|
||||
return regions.BootstrapSelectElement(self, self.find_element(*self._venue_selector_selector))
|
||||
|
||||
@property
|
||||
def mic_selector(self):
|
||||
return regions.BootstrapSelectElement(self, self.find_element(*self._mic_selector_selector))
|
||||
|
||||
@property
|
||||
def success(self):
|
||||
return '/create' not in self.driver.current_url
|
||||
|
||||
class GenericList(BasePage):
|
||||
_search_selector = (By.CSS_SELECTOR, 'div.input-group:nth-child(2) > input:nth-child(1)')
|
||||
_search_go_selector = (By.ID, 'id_search')
|
||||
|
||||
@@ -14,14 +14,15 @@ from selenium.webdriver.support.ui import WebDriverWait
|
||||
from PyRIGS.tests.base import animation_is_finished
|
||||
from PyRIGS.tests import base
|
||||
from RIGS.tests import regions
|
||||
from datetime import date, time, datetime, timedelta
|
||||
import datetime
|
||||
from datetime import date, time, timedelta
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
class TestRigboard(AutoLoginTest):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
client = models.Person.objects.create(name='Duplicate Test Person', email='duplicate@functional.test')
|
||||
client = models.Person.objects.create(name='Rigboard Test Person', email='rigboard@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),
|
||||
@@ -64,3 +65,56 @@ class TestRigboard(AutoLoginTest):
|
||||
self.page.add()
|
||||
self.assertIn('create', self.driver.current_url)
|
||||
# Ideally get a response object to assert 200 on
|
||||
|
||||
|
||||
class TestEventCreate(AutoLoginTest):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.client = models.Person.objects.create(name='Creation Test Person', email='god@functional.test')
|
||||
self.vatrate = models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
self.page = pages.CreateEvent(self.driver, self.live_server_url).open()
|
||||
self.wait = WebDriverWait(self.driver, 5)
|
||||
|
||||
def test_rig_creation(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)
|
||||
|
||||
self.page.person_selector.toggle()
|
||||
self.assertTrue(self.page.person_selector.is_open)
|
||||
self.page.person_selector.search(self.client.name)
|
||||
self.page.person_selector.set_option(self.client.name, True)
|
||||
# TODO This should not be necessary, normally closes automatically
|
||||
self.page.person_selector.toggle()
|
||||
self.assertFalse(self.page.person_selector.is_open)
|
||||
|
||||
self.page.name = "Test Rig"
|
||||
self.page.start_date = datetime.date(2015, 1, 1)
|
||||
self.page.start_time = datetime.time(10)
|
||||
self.page.end_date = datetime.date(2015, 1, 10)
|
||||
self.page.access_at = datetime.datetime(2015, 1, 1, 9)
|
||||
self.page.dry_hire = True
|
||||
self.page.status = "Booked"
|
||||
self.page.collected_by = "Fred"
|
||||
self.page.po = "1234"
|
||||
self.page.notes = "A note!"
|
||||
|
||||
# TODO Test validation with some wrong data
|
||||
self.page.submit()
|
||||
self.assertTrue(self.page.success)
|
||||
|
||||
# TODO Testing of internal rig (approval system interface)
|
||||
|
||||
def test_non_rig_creation(self):
|
||||
self.wait.until(animation_is_finished())
|
||||
self.assertFalse(self.page.is_expanded)
|
||||
self.page.select_event_type("Non-Rig")
|
||||
self.wait.until(animation_is_finished())
|
||||
self.assertTrue(self.page.is_expanded)
|
||||
|
||||
# self.assertFalse(self.page.person_selector.is_displayed())
|
||||
|
||||
def test_subhire_creation(self):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user