This commit is contained in:
2020-05-24 19:24:51 +01:00
parent 928d5cd8e6
commit c9ea1bb75d
10 changed files with 72 additions and 59 deletions

View File

@@ -7,9 +7,11 @@ import pytz
from datetime import date, time, datetime, timedelta
from django.conf import settings
def create_datetime(year, month, day, hour, min):
tz = pytz.timezone(settings.TIME_ZONE)
return tz.localize(datetime(year, month, day, hour, min)).astimezone(pytz.utc)
tz = pytz.timezone(settings.TIME_ZONE)
return tz.localize(datetime(year, month, day, hour, min)).astimezone(pytz.utc)
def create_browser():
options = webdriver.ChromeOptions()

View File

@@ -149,6 +149,7 @@ class DateTimePicker(Region):
self.root.send_keys(Keys.TAB)
self.root.send_keys(time)
class SingleSelectPicker(Region):
@property
def value(self):

View File

@@ -8,7 +8,8 @@ from django.views.decorators.clickjacking import xframe_options_exempt
from django.contrib.auth.views import LoginView
from registration.backends.default.views import RegistrationView
from PyRIGS.decorators import permission_required_with_403
import RIGS, users
import RIGS
import users
from PyRIGS import views
urlpatterns = [

View File

@@ -83,7 +83,7 @@ class InvoicePrint(generic.View):
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = "filename=Invoice %05d - N%05d | %s.pdf" % (
invoice.pk, invoice.event.pk, escapedEventName)
invoice.pk, invoice.event.pk, escapedEventName)
response.write(pdfData)
return response
@@ -176,8 +176,8 @@ class InvoiceWaiting(generic.ListView):
# @todo find a way to select items
events = self.model.objects.filter(
(
Q(start_date__lte=datetime.date.today(), end_date__isnull=True) | # Starts before with no end
Q(end_date__lte=datetime.date.today()) # Has end date, finishes before
Q(start_date__lte=datetime.date.today(), end_date__isnull=True) | # Starts before with no end
Q(end_date__lte=datetime.date.today()) # Has end date, finishes before
) & Q(invoice__isnull=True) & # Has not already been invoiced
Q(is_rig=True) # Is a rig (not non-rig)

View File

@@ -9,6 +9,7 @@ from PyRIGS.tests.pages import BasePage, FormPage
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
class Index(BasePage):
URL_TEMPLATE = reverse('index')
@@ -47,34 +48,35 @@ class Rigboard(BasePage):
@property
def events(self):
return [self.EventListRow(self, i) for i in self.find_elements(*self._event_row_locator)]
class EventDetail(BasePage):
URL_TEMPLATE = 'event/{event_id}'
# TODO Refactor into regions to match template fragmentation
_event_name_selector = (By.XPATH, '//h1')
_person_panel_selector = (By.XPATH, '//div[contains(text(), "Contact Details")]/..')
_name_selector = (By.XPATH, '//dt[text()="Person"]/following-sibling::dd[1]')
_email_selector = (By.XPATH, '//dt[text()="Email"]/following-sibling::dd[1]')
_phone_selector = (By.XPATH, '//dt[text()="Phone Number"]/following-sibling::dd[1]')
@property
def event_name(self):
return self.find_element(*self._event_name_selector).text
@property
def name(self):
return self.find_element(*self._person_panel_selector).find_element(*self._name_selector).text
@property
def email(self):
return self.find_element(*self._person_panel_selector).find_element(*self._email_selector).text
@property
def phone(self):
return self.find_element(*self._person_panel_selector).find_element(*self._phone_selector).text
class CreateEvent(FormPage):
URL_TEMPLATE = reverse('event_create')
@@ -88,7 +90,7 @@ 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]')
@@ -115,11 +117,11 @@ 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
@@ -153,25 +155,27 @@ 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 EditEvent(CreateEvent):
URL_TEMPLATE = 'event/{event_id}/edit'
_submit_locator = (By.XPATH, '/html/body/div[1]/form/div/div[5]/div/button')
@property
def success(self):
return '/edit' 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')
_add_item_selector = (By.CSS_SELECTOR, '.btn-success')

View File

@@ -28,6 +28,7 @@ from django.conf import settings
import sys
class IcalTest(LiveServerTestCase):
def setUp(self):
self.all_events = set(range(1, 18))
@@ -415,6 +416,7 @@ class TECEventAuthorisationTest(TestCase):
self.assertEqual(self.event.auth_request_to, 'client@functional.test')
self.assertIsNotNone(self.event.auth_request_at)
class SearchTest(LiveServerTestCase):
def setUp(self):
self.profile = models.Profile(

View File

@@ -20,19 +20,20 @@ from django.utils import timezone
from selenium.webdriver.common.action_chains import ActionChains
from django.db import transaction
class BaseRigboardTest(AutoLoginTest):
def setUp(self):
self.vatrate = models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
super().setUp()
self.client = models.Person.objects.create(name='Rigboard Test Person', email='rigboard@functional.test')
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")
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,
@@ -50,7 +51,7 @@ class BaseRigboardTest(AutoLoginTest):
order=2,
).save()
self.wait = WebDriverWait(self.driver, 5)
def select_event_type(self, event_type):
self.wait.until(animation_is_finished())
self.assertFalse(self.page.is_expanded)
@@ -58,17 +59,18 @@ class BaseRigboardTest(AutoLoginTest):
self.wait.until(animation_is_finished())
self.assertTrue(self.page.is_expanded)
class TestRigboard(BaseRigboardTest):
def setUp(self):
super().setUp()
self.testEvent2 = models.Event.objects.create(name="TE E2", status=models.Event.PROVISIONAL,
start_date=date.today() + timedelta(days=8),
description="start future no end, later",
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")
start_date=date.today() + timedelta(days=8),
description="start future no end, later",
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")
self.page = pages.Rigboard(self.driver, self.live_server_url).open()
def test_buttons(self):
@@ -163,10 +165,10 @@ class TestEventCreate(BaseRigboardTest):
self.assertEqual(self.page.person_selector.options[1].name, person_name)
# TODO
def test_date_validation(self):
self.select_event_type("Rig")
self.page.person_selector.toggle()
self.assertTrue(self.page.person_selector.is_open)
self.page.person_selector.search(self.client.name)
@@ -184,17 +186,17 @@ class TestEventCreate(BaseRigboardTest):
self.assertFalse(self.page.success)
self.assertIn("can't finish before it has started", self.page.errors["General form errors"][0])
self.wait.until(animation_is_finished())
#end time before start
# end time before start
self.page.start_date = datetime.date(2020, 1, 1)
self.page.start_time = datetime.time(10)
self.page.end_time = datetime.time(9)
# Expected to fail
self.page.submit()
self.assertFalse(self.page.success)
self.assertIn("can't finish before it has started", self.page.errors["General form errors"][0])
# Fix it
self.page.end_time = datetime.time(23)
@@ -283,18 +285,18 @@ class TestEventCreate(BaseRigboardTest):
def test_subhire_creation(self):
pass
class TestEventDuplicate(BaseRigboardTest):
def setUp(self):
super().setUp()
self.page = pages.DuplicateEvent(self.driver, self.live_server_url, event_id=self.testEvent.pk).open()
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)
@@ -311,10 +313,10 @@ class TestEventDuplicate(BaseRigboardTest):
modal.submit()
self.wait.until(animation_is_finished())
# Attempt to save
# 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')
@@ -359,16 +361,16 @@ class TestEventDuplicate(BaseRigboardTest):
self.assertIn("Test Item 1", table.text)
self.assertIn("Test Item 2", table.text)
self.assertNotIn("Test Item 3", table.text)
class TestEventEdit(BaseRigboardTest):
def setUp(self):
super().setUp()
self.page = pages.EditEvent(self.driver, self.live_server_url, event_id=self.testEvent.pk).open()
def test_rig_edit(self):
self.page.name = "Edited Event"
modal = self.page.add_event_item()
self.wait.until(animation_is_finished())
# See modal has opened
@@ -382,25 +384,25 @@ class TestEventEdit(BaseRigboardTest):
modal.submit()
self.wait.until(animation_is_finished())
# Attempt to save
# Attempt to save
ActionChains(self.driver).move_to_element(self.page.item_table).perform()
self.page.submit()
self.assertTrue(self.page.success)
self.page = pages.EventDetail(self.driver, self.live_server_url, event_id=self.testEvent.pk).open()
self.assertIn(self.page.event_name, self.testEvent.name)
self.assertEqual(self.page.name, self.testEvent.person.name)
# Check the new items are visible
table = self.page.item_table
self.assertIn("Test Item 3", table.text)
class TestEventDetail(BaseRigboardTest):
def setUp(self):
super().setUp()
self.page = pages.EventDetail(self.driver, self.live_server_url, event_id=self.testEvent.pk).open()
def test_rig_detail(self):
self.assertIn("N%05d | %s" % (self.testEvent.pk, self.testEvent.name), self.page.event_name)
self.assertEqual(person.name, self.page.name)

View File

@@ -300,6 +300,7 @@ class ActivityTable(versioning.ActivityTable):
return context
class CableTypeList(generic.ListView):
model = models.CableType
template_name = 'cable_type_list.html'

View File

@@ -185,4 +185,3 @@ class UserRegistrationTest(LiveServerTestCase):
self.assertEqual(profileObject.email, 'test@example.com')
# All is well

View File

@@ -194,6 +194,8 @@ class RIGSVersionTestCase(TestCase):
self.assertTrue(diffs[0].new is None)
# Unit Tests
class TestVersioningViews(TestCase):
@classmethod
def setUpTestData(cls):
@@ -273,5 +275,4 @@ class TestVersioningViews(TestCase):
self.assertEqual(response.status_code, 200)
#Functional Tests
# Functional Tests