mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 13:32:15 +00:00
Start on new tests
This commit is contained in:
@@ -3,7 +3,13 @@ from selenium import webdriver
|
||||
from RIGS import models as rigsmodels
|
||||
from . import pages
|
||||
import os
|
||||
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)
|
||||
|
||||
def create_browser():
|
||||
options = webdriver.ChromeOptions()
|
||||
|
||||
@@ -32,12 +32,12 @@ class BootstrapSelectElement(Region):
|
||||
|
||||
def toggle(self):
|
||||
original_state = self.is_open
|
||||
return self.find_element(*self._main_button_locator).click()
|
||||
option_box = self.find_element(*self._option_box_locator)
|
||||
if original_state:
|
||||
self.wait.until(expected_conditions.invisibility_of_element_located(option_box))
|
||||
else:
|
||||
self.wait.until(expected_conditions.visibility_of_element_located(option_box))
|
||||
return self.find_element(*self._main_button_locator).click()
|
||||
|
||||
def open(self):
|
||||
if not self.is_open:
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for event in events %}
|
||||
<tr {% include 'partials/event_table_colour.html' %}>
|
||||
<tr {% include 'partials/event_table_colour.html' %} id="event_row">
|
||||
<!---Number-->
|
||||
<th scope="row">{{ event.pk }}</th>
|
||||
<th scope="row" id="event_number">{{ event.pk }}</th>
|
||||
<!--Dates-->
|
||||
<td>
|
||||
<td id="event_dates">
|
||||
<div><strong>{{ event.start_date|date:"D d/m/Y" }}</strong></div>
|
||||
{% if event.end_date and event.end_date != event.start_date %}
|
||||
<div><strong>{{ event.end_date|date:"D d/m/Y" }}</strong></div>
|
||||
@@ -45,7 +45,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<!---Details-->
|
||||
<td>
|
||||
<td id="event_details">
|
||||
<h4>
|
||||
<a href="{% url 'event_detail' event.pk %}">
|
||||
{{ event.name }}
|
||||
@@ -71,7 +71,7 @@
|
||||
{% include 'partials/event_status.html' %}
|
||||
</td>
|
||||
<!---MIC-->
|
||||
<td>
|
||||
<td id="event_mic">
|
||||
{% if event.mic %}
|
||||
<div class="media">
|
||||
{% if perms.RIGS.view_profile %}
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
<h4 class="list-group-item-heading">Quick Links</h4>
|
||||
</div>
|
||||
<div class="list-group list-group-flush">
|
||||
<a class="list-group-item list-group-item-action" href="https://forum.nottinghamtec.co.uk" target="_blank"><i class="fas fa-comment-alt"></i> TEC Forum</a>
|
||||
<a class="list-group-item list-group-item-action" href="//members.nottinghamtec.co.uk/wiki" target="_blank"><i class="fas fa-pen-square"></i> TEC Wiki</a>
|
||||
<a class="list-group-item list-group-item-action" href="https://forum.nottinghamtec.co.uk" target="_blank" rel="noopener noreferrer"><i class="fas fa-comment-alt"></i> TEC Forum</a>
|
||||
<a class="list-group-item list-group-item-action" href="//members.nottinghamtec.co.uk/wiki" target="_blank" rel="noopener noreferrer"><i class="fas fa-pen-square"></i> TEC Wiki</a>
|
||||
{% if perms.RIGS.view_event %}
|
||||
<a class="list-group-item list-group-item-action" href="//members.nottinghamtec.co.uk/price" target="_blank"><i class="fas fa-pound-sign"></i> Price List</a>
|
||||
{% endif %}
|
||||
|
||||
54
RIGS/tests/pages.py
Normal file
54
RIGS/tests/pages.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from pypom import Page, Region
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions
|
||||
from selenium.webdriver import Chrome
|
||||
from django.urls import reverse
|
||||
from PyRIGS.tests import regions
|
||||
from PyRIGS.tests.pages import BasePage, FormPage
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
|
||||
class Index(BasePage):
|
||||
URL_TEMPLATE = reverse('index')
|
||||
|
||||
|
||||
class Rigboard(BasePage):
|
||||
URL_TEMPLATE = reverse('rigboard')
|
||||
|
||||
_add_item_selector = (By.CSS_SELECTOR, 'a.btn:nth-child(2)')
|
||||
_event_row_locator = (By.ID, 'event_row')
|
||||
|
||||
def add(self):
|
||||
self.find_element(*self._add_item_selector).click()
|
||||
|
||||
class EventListRow(Region):
|
||||
_event_number_locator = (By.ID, "event_number")
|
||||
_event_dates_locator = (By.ID, "event_dates")
|
||||
_event_details_locator = (By.ID, "event_details")
|
||||
_event_mic_locator = (By.ID, "event_mic")
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.find_element(*self._event_number_locator).text
|
||||
|
||||
@property
|
||||
def dates(self):
|
||||
return self.find_element(*self._event_dates_locator).text
|
||||
|
||||
@property
|
||||
def details(self):
|
||||
return self.find_element(*self._event_details_locator).text
|
||||
|
||||
@property
|
||||
def mic(self):
|
||||
return self.find_element(*self._event_mic_locator).text
|
||||
|
||||
@property
|
||||
def events(self):
|
||||
return [self.EventListRow(self, i) for i in self.find_elements(*self._event_row_locator)]
|
||||
|
||||
|
||||
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')
|
||||
|
||||
12
RIGS/tests/regions.py
Normal file
12
RIGS/tests/regions.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from pypom import Region
|
||||
from selenium.webdriver.common.by import By
|
||||
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
|
||||
import datetime
|
||||
|
||||
|
||||
class Header(Region):
|
||||
def find_link(self, link_text):
|
||||
return self.driver.find_element_by_partial_link_text(link_text)
|
||||
@@ -64,19 +64,6 @@ class EventTest(LiveServerTestCase):
|
||||
|
||||
self.assertEqual(self.live_server_url + n, self.browser.current_url)
|
||||
|
||||
def testRigboardButtons(self):
|
||||
# Requests address
|
||||
self.browser.get(self.live_server_url + '/rigboard/')
|
||||
# Gets redirected to login
|
||||
self.authenticate('/rigboard/')
|
||||
|
||||
# Completes and comes back to rigboard
|
||||
# Clicks add new
|
||||
self.browser.find_element_by_partial_link_text("New").click()
|
||||
self.assertEqual(
|
||||
self.live_server_url + '/event/create/', self.browser.current_url)
|
||||
self.browser.get(self.live_server_url + '/rigboard/')
|
||||
|
||||
def testRigCreate(self):
|
||||
# Requests address
|
||||
self.browser.get(self.live_server_url + '/event/create/')
|
||||
@@ -1061,7 +1048,6 @@ 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(
|
||||
|
||||
66
RIGS/tests/test_rigs.py
Normal file
66
RIGS/tests/test_rigs.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from . import pages
|
||||
from django.core.management import call_command
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from urllib.parse import urlparse
|
||||
from PyRIGS.tests.base import BaseTest, AutoLoginTest
|
||||
from RIGS import models, urls
|
||||
from reversion import revisions as reversion
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
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
|
||||
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')
|
||||
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),
|
||||
description="start future no end",
|
||||
purchase_order='TESTPO',
|
||||
person=client,
|
||||
auth_request_by=self.profile,
|
||||
auth_request_at=base.create_datetime(2015, 0o6, 0o4, 10, 00),
|
||||
auth_request_to="some@email.address")
|
||||
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=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):
|
||||
header = regions.Header(self.page, self.driver.find_element(By.CSS_SELECTOR, '.navbar'))
|
||||
# TODO Switch to checking reversed links (difficult because of arguments)
|
||||
header.find_link("Rigboard").click()
|
||||
self.assertEqual(
|
||||
self.live_server_url + '/rigboard/', self.driver.current_url)
|
||||
header.find_link("Archive").click()
|
||||
self.assertEqual(
|
||||
self.live_server_url + '/event/archive/', self.driver.current_url)
|
||||
# TODO - This fails for some reason
|
||||
# header.find_link("New").click()
|
||||
# self.assertEqual(
|
||||
# self.live_server_url + '/event/create/', self.driver.current_url)
|
||||
|
||||
def test_event_order(self):
|
||||
self.assertIn(self.testEvent.start_date.strftime('%a %d/%m/%Y'), self.page.events[0].dates)
|
||||
self.assertIn(self.testEvent2.start_date.strftime('%a %d/%m/%Y'), self.page.events[1].dates)
|
||||
|
||||
def test_add_button(self):
|
||||
self.page.add()
|
||||
self.assertIn('create', self.driver.current_url)
|
||||
# Ideally get a response object to assert 200 on
|
||||
@@ -22,6 +22,7 @@
|
||||
{{ object.status }}
|
||||
</span>
|
||||
</h4>
|
||||
<dl>
|
||||
{% if object.serial_number %}
|
||||
<dt>Serial Number: </dt>
|
||||
<dd>{{ object.serial_number }}</dd>
|
||||
@@ -30,7 +31,7 @@
|
||||
<dt>Comments: </dt>
|
||||
<dd class="dont-break-out">{{ object.comments|linebreaksbr }}<dd>
|
||||
{% endif %}
|
||||
|
||||
</dl>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col px-0">
|
||||
<a href="{% url 'asset_create' %}" class="btn btn-success float-right my-3">New <i class="fas fa-plus"></i></a>
|
||||
<a href="{% url 'asset_create' %}" class="btn btn-success float-right my-3">New <span class="fas fa-plus"></span></a>
|
||||
</div>
|
||||
{% include 'partials/asset_list_table.html' %}
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block titleheader %}
|
||||
<a class="nav navbar-brand navbar-left" href="/"><i class="fas fa-arrow-circle-left" style="vertical-align: middle !important;"></i> RIGS</a>
|
||||
<a class="nav navbar-brand navbar-left" href="/"><span class="fas fa-arrow-circle-left" style="vertical-align: middle !important;"></span> RIGS</a>
|
||||
<a class="nav navbar-brand" href="{% url 'asset_index' %}">Assets</a>
|
||||
{% endblock %}
|
||||
|
||||
@@ -13,23 +13,23 @@
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Assets</a>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="{% url 'asset_list' %}"><i class="fas fa-list"></i> List Assets</a>
|
||||
<a class="dropdown-item" href="{% url 'asset_list' %}"><span class="fas fa-list"></span> List Assets</a>
|
||||
{% if perms.assets.add_asset %}
|
||||
<a class="dropdown-item" href="{% url 'asset_create' %}"><i class="fas fa-plus"></i> Create Asset</a>
|
||||
<a class="dropdown-item" href="{% url 'asset_create' %}"><span class="fas fa-plus"></span> Create Asset</a>
|
||||
{% endif %}
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="{% url 'cable_type_list' %}"><i class="fas fa-list"></i> List Cable Types</a>
|
||||
<a class="dropdown-item" href="{% url 'cable_type_list' %}"><span class="fas fa-list"></span> List Cable Types</a>
|
||||
{% if perms.assets.add_cable_type %}
|
||||
<a class="dropdown-item" href="{% url 'cable_type_create' %}"><i class="fas fa-plus"></i> Create Cable Type</a>
|
||||
<a class="dropdown-item" href="{% url 'cable_type_create' %}"><span class="fas fa-plus"></span> Create Cable Type</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</li>
|
||||
<div class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Suppliers</a>
|
||||
<ul class="dropdown-menu">
|
||||
<a class="dropdown-item" href="{% url 'supplier_list' %}"><i class="fas fa-list"></i> List Suppliers</a>
|
||||
<a class="dropdown-item" href="{% url 'supplier_list' %}"><span class="fas fa-list"></span> List Suppliers</a>
|
||||
{% if perms.assets.add_supplier %}
|
||||
<a class="dropdown-item" href="{% url 'supplier_create' %}"><i class="fas fa-plus"></i> Create Supplier</a>
|
||||
<a class="dropdown-item" href="{% url 'supplier_create' %}"><span class="fas fa-plus"></span> Create Supplier</a>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -11,21 +11,21 @@
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Cable Type</th>
|
||||
<th>Circuits</th>
|
||||
<th>Cores</th>
|
||||
<th>Quick Links</th>
|
||||
<th scope="col">Cable Type</th>
|
||||
<th scope="col">Circuits</th>
|
||||
<th scope="col">Cores</th>
|
||||
<th scope="col">Quick Links</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in object_list %}
|
||||
<tr>
|
||||
<td>{{ item }}</td>
|
||||
<th scope="row">{{ item }}</th>
|
||||
<td>{{ item.circuits }}</td>
|
||||
<td>{{ item.cores }}</td>
|
||||
<td>
|
||||
<a href="{% url 'cable_type_detail' item.pk %}" class="btn btn-default"><i class="glyphicon glyphicon-eye-open"></i> View</a>
|
||||
<a href="{% url 'cable_type_update' item.pk %}" class="btn btn-default"><i class="glyphicon glyphicon-edit"></i> Edit</a>
|
||||
<a href="{% url 'cable_type_detail' item.pk %}" class="btn btn-primary"><span class="fas fas-eye-open"></span> View</a>
|
||||
<a href="{% url 'cable_type_update' item.pk %}" class="btn btn-warning"><span class="fas fas-edit"></span> Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
0
versioning/migrations/__init__.py
Normal file
0
versioning/migrations/__init__.py
Normal file
Reference in New Issue
Block a user