mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-11 09:09:42 +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 selenium.common.exceptions import NoSuchElementException
|
||||||
from PyRIGS.tests import regions
|
from PyRIGS.tests import regions
|
||||||
|
|
||||||
|
|
||||||
class BasePage(Page):
|
class BasePage(Page):
|
||||||
form_items = {}
|
form_items = {}
|
||||||
|
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ class AssetAuditList(AssetList):
|
|||||||
_search_text_locator = (By.ID, 'id_query')
|
_search_text_locator = (By.ID, 'id_query')
|
||||||
_go_button_locator = (By.ID, 'searchButton')
|
_go_button_locator = (By.ID, 'searchButton')
|
||||||
_modal_locator = (By.ID, 'modal')
|
_modal_locator = (By.ID, 'modal')
|
||||||
|
_errors_selector = (By.CLASS_NAME, "alert-danger")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def modal(self):
|
def modal(self):
|
||||||
@@ -201,6 +202,13 @@ class AssetAuditList(AssetList):
|
|||||||
def search(self):
|
def search(self):
|
||||||
self.find_element(*self._go_button_locator).click()
|
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):
|
class AssetAuditModal(Region):
|
||||||
_errors_selector = (By.CLASS_NAME, "alert-danger")
|
_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...
|
# 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 PyRIGS.tests.base import BaseTest, AutoLoginTest
|
||||||
from assets import models, urls
|
from assets import models, urls
|
||||||
from reversion import revisions as reversion
|
from reversion import revisions as reversion
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from RIGS.test_functional import animation_is_finished
|
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="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))
|
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.page = pages.AssetAuditList(self.driver, self.live_server_url).open()
|
||||||
|
self.wait = WebDriverWait(self.driver, 3)
|
||||||
|
|
||||||
def test_audit_process(self):
|
def test_audit_process(self):
|
||||||
asset_id = "1111"
|
asset_id = "1111"
|
||||||
self.page.set_query(asset_id)
|
self.page.set_query(asset_id)
|
||||||
self.page.search()
|
self.page.search()
|
||||||
wait = WebDriverWait(self.driver, 3)
|
self.wait.until(animation_is_finished())
|
||||||
wait.until(animation_is_finished())
|
|
||||||
|
|
||||||
mdl = self.page.modal
|
mdl = self.page.modal
|
||||||
self.assertTrue(mdl.is_displayed)
|
self.assertTrue(mdl.is_displayed)
|
||||||
@@ -284,7 +285,7 @@ class TestAssetAudit(AutoLoginTest):
|
|||||||
mdl.remove_all_required()
|
mdl.remove_all_required()
|
||||||
mdl.description = ""
|
mdl.description = ""
|
||||||
mdl.submit()
|
mdl.submit()
|
||||||
wait.until(animation_is_finished())
|
self.wait.until(animation_is_finished())
|
||||||
self.assertTrue(mdl.is_displayed)
|
self.assertTrue(mdl.is_displayed)
|
||||||
self.assertIn("This field is required.", mdl.errors["Description"])
|
self.assertIn("This field is required.", mdl.errors["Description"])
|
||||||
# Now do it properly
|
# Now do it properly
|
||||||
@@ -305,6 +306,31 @@ class TestAssetAudit(AutoLoginTest):
|
|||||||
# Check we've removed it from the 'needing audit' list
|
# Check we've removed it from the 'needing audit' list
|
||||||
self.assertNotIn(asset_id, self.page.assets)
|
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):
|
class TestSupplierValidation(TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user