mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Improve asset audit testing
This commit is contained in:
@@ -4,6 +4,7 @@ from selenium.webdriver import Chrome
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
from PyRIGS.tests import regions
|
||||
|
||||
|
||||
class BasePage(Page):
|
||||
form_items = {}
|
||||
|
||||
|
||||
@@ -134,24 +134,24 @@ class SingleSelectPicker(Region):
|
||||
|
||||
|
||||
class ErrorPage(Region):
|
||||
_error_item_selector = (By.CSS_SELECTOR, "dl>span")
|
||||
_error_item_selector = (By.CSS_SELECTOR, "dl>span")
|
||||
|
||||
class ErrorItem(Region):
|
||||
_field_selector = (By.CSS_SELECTOR, "dt")
|
||||
_error_selector = (By.CSS_SELECTOR, "dd>ul>li")
|
||||
class ErrorItem(Region):
|
||||
_field_selector = (By.CSS_SELECTOR, "dt")
|
||||
_error_selector = (By.CSS_SELECTOR, "dd>ul>li")
|
||||
|
||||
@property
|
||||
def field_name(self):
|
||||
return self.find_element(*self._field_selector).text
|
||||
@property
|
||||
def field_name(self):
|
||||
return self.find_element(*self._field_selector).text
|
||||
|
||||
@property
|
||||
def errors(self):
|
||||
return [x.text for x in self.find_elements(*self._error_selector)]
|
||||
@property
|
||||
def errors(self):
|
||||
return [x.text for x in self.find_elements(*self._error_selector)]
|
||||
|
||||
@property
|
||||
def errors(self):
|
||||
error_items = [self.ErrorItem(self, x) for x in self.find_elements(*self._error_item_selector)]
|
||||
errors = {}
|
||||
for error in error_items:
|
||||
errors[error.field_name] = error.errors
|
||||
return errors
|
||||
@property
|
||||
def errors(self):
|
||||
error_items = [self.ErrorItem(self, x) for x in self.find_elements(*self._error_item_selector)]
|
||||
errors = {}
|
||||
for error in error_items:
|
||||
errors[error.field_name] = error.errors
|
||||
return errors
|
||||
|
||||
@@ -184,6 +184,7 @@ class AssetAuditList(AssetList):
|
||||
_search_text_locator = (By.ID, 'id_query')
|
||||
_go_button_locator = (By.ID, 'searchButton')
|
||||
_modal_locator = (By.ID, 'modal')
|
||||
_errors_selector = (By.CLASS_NAME, "alert-danger")
|
||||
|
||||
@property
|
||||
def modal(self):
|
||||
@@ -201,6 +202,13 @@ class AssetAuditList(AssetList):
|
||||
def search(self):
|
||||
self.find_element(*self._go_button_locator).click()
|
||||
|
||||
@property
|
||||
def error(self):
|
||||
try:
|
||||
return self.find_element(*self._errors_selector)
|
||||
except NoSuchElementException:
|
||||
return None
|
||||
|
||||
class AssetAuditModal(Region):
|
||||
_errors_selector = (By.CLASS_NAME, "alert-danger")
|
||||
# Don't use the usual success selector - that tries and fails to hit the '10m long cable' helper button...
|
||||
|
||||
@@ -9,6 +9,7 @@ from RIGS import models as rigsmodels
|
||||
from PyRIGS.tests.base import BaseTest, AutoLoginTest
|
||||
from assets import models, urls
|
||||
from reversion import revisions as reversion
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from RIGS.test_functional import animation_is_finished
|
||||
@@ -270,13 +271,13 @@ class TestAssetAudit(AutoLoginTest):
|
||||
models.Asset.objects.create(asset_id="111", description="Erms", status=self.status, category=self.category, date_acquired=datetime.date(2020, 2, 1))
|
||||
models.Asset.objects.create(asset_id="1111", description="A hammer", status=self.status, category=self.category, date_acquired=datetime.date(2020, 2, 1))
|
||||
self.page = pages.AssetAuditList(self.driver, self.live_server_url).open()
|
||||
self.wait = WebDriverWait(self.driver, 3)
|
||||
|
||||
def test_audit_process(self):
|
||||
asset_id = "1111"
|
||||
self.page.set_query(asset_id)
|
||||
self.page.search()
|
||||
wait = WebDriverWait(self.driver, 3)
|
||||
wait.until(animation_is_finished())
|
||||
self.wait.until(animation_is_finished())
|
||||
|
||||
mdl = self.page.modal
|
||||
self.assertTrue(mdl.is_displayed)
|
||||
@@ -284,7 +285,7 @@ class TestAssetAudit(AutoLoginTest):
|
||||
mdl.remove_all_required()
|
||||
mdl.description = ""
|
||||
mdl.submit()
|
||||
wait.until(animation_is_finished())
|
||||
self.wait.until(animation_is_finished())
|
||||
self.assertTrue(mdl.is_displayed)
|
||||
self.assertIn("This field is required.", mdl.errors["Description"])
|
||||
# Now do it properly
|
||||
@@ -305,6 +306,31 @@ class TestAssetAudit(AutoLoginTest):
|
||||
# Check we've removed it from the 'needing audit' list
|
||||
self.assertNotIn(asset_id, self.page.assets)
|
||||
|
||||
def test_audit_list(self):
|
||||
self.assertEqual(len(models.Asset.objects.filter(last_audited_at=None)), len(self.page.assets))
|
||||
|
||||
assetRow = self.page.assets[0]
|
||||
assetRow.find_element(By.CSS_SELECTOR, "td:nth-child(5) > div:nth-child(1) > a:nth-child(1)").click()
|
||||
self.wait.until(animation_is_finished())
|
||||
mdl = self.page.modal
|
||||
self.assertTrue(mdl.is_displayed)
|
||||
self.assertEqual(mdl.asset_id, assetRow.id)
|
||||
|
||||
# First close button is for the not found error
|
||||
mdl.find_element(By.XPATH, '(//button[@class="close"])[2]').click()
|
||||
self.wait.until(animation_is_finished())
|
||||
self.assertFalse(mdl.is_displayed)
|
||||
# Make sure audit log was NOT filled out
|
||||
audited = models.Asset.objects.get(asset_id=assetRow.id)
|
||||
self.assertEqual(None, audited.last_audited_by)
|
||||
|
||||
# Check that a failed search works
|
||||
self.page.set_query("NOTFOUND")
|
||||
self.page.search()
|
||||
self.wait.until(animation_is_finished())
|
||||
self.assertFalse(self.page.modal.is_displayed)
|
||||
self.assertIn("Asset with that ID does not exist!", self.page.error.text)
|
||||
|
||||
|
||||
class TestSupplierValidation(TestCase):
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user