mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-30 20:02:16 +00:00
Asset duplicate tests
Also fixed some random bugs
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<a class="btn btn-default" href="{% url 'asset_duplicate' object.pk %}"><i class="glyphicon glyphicon-duplicate"></i> Duplicate</a>
|
<a class="btn btn-default" href="{% url 'asset_duplicate' object.pk %}"><i class="glyphicon glyphicon-duplicate"></i> Duplicate</a>
|
||||||
{% elif duplicate %}
|
{% elif duplicate %}
|
||||||
<!--duplicate-->
|
<!--duplicate-->
|
||||||
<button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-ok-sign"></i> Create Duplicate</button>
|
<button type="submit" class="btn btn-success"><i class="glyphicon glyphicon-ok-sign"></i> Create Duplicate</button>
|
||||||
{% elif create %}
|
{% elif create %}
|
||||||
<!--create-->
|
<!--create-->
|
||||||
<button type="submit" class="btn btn-success"><i class="glyphicon glyphicon-floppy-disk"></i> Save</button>
|
<button type="submit" class="btn btn-success"><i class="glyphicon glyphicon-floppy-disk"></i> Save</button>
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class AssetList(BasePage):
|
|||||||
class AssetForm(FormPage):
|
class AssetForm(FormPage):
|
||||||
_purchased_from_select_locator = (By.CSS_SELECTOR, 'div#purchased-from-group>div.bootstrap-select')
|
_purchased_from_select_locator = (By.CSS_SELECTOR, 'div#purchased-from-group>div.bootstrap-select')
|
||||||
_parent_select_locator = (By.CSS_SELECTOR, 'div#parent-group>div.bootstrap-select')
|
_parent_select_locator = (By.CSS_SELECTOR, 'div#parent-group>div.bootstrap-select')
|
||||||
|
_submit_locator = (By.CLASS_NAME, 'btn-success')
|
||||||
form_items = {
|
form_items = {
|
||||||
'asset_id': (regions.TextBox, (By.ID, 'id_asset_id')),
|
'asset_id': (regions.TextBox, (By.ID, 'id_asset_id')),
|
||||||
'description': (regions.TextBox, (By.ID, 'id_description')),
|
'description': (regions.TextBox, (By.ID, 'id_description')),
|
||||||
@@ -97,16 +98,15 @@ class AssetForm(FormPage):
|
|||||||
def parent_selector(self):
|
def parent_selector(self):
|
||||||
return regions.BootstrapSelectElement(self, self.find_element(*self._parent_select_locator))
|
return regions.BootstrapSelectElement(self, self.find_element(*self._parent_select_locator))
|
||||||
|
|
||||||
|
|
||||||
class AssetEdit(AssetForm):
|
|
||||||
URL_TEMPLATE = '/assets/asset/id/{asset_id}/edit/'
|
|
||||||
_submit_locator = (By.CLASS_NAME, 'btn-success')
|
|
||||||
|
|
||||||
def submit(self):
|
def submit(self):
|
||||||
previous_errors = self.errors
|
previous_errors = self.errors
|
||||||
self.find_element(*self._submit_locator).click()
|
self.find_element(*self._submit_locator).click()
|
||||||
self.wait.until(lambda x: self.errors != previous_errors or self.success)
|
self.wait.until(lambda x: self.errors != previous_errors or self.success)
|
||||||
|
|
||||||
|
|
||||||
|
class AssetEdit(AssetForm):
|
||||||
|
URL_TEMPLATE = '/assets/asset/id/{asset_id}/edit/'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self):
|
def success(self):
|
||||||
return '/edit' not in self.driver.current_url
|
return '/edit' not in self.driver.current_url
|
||||||
@@ -114,18 +114,20 @@ class AssetEdit(AssetForm):
|
|||||||
|
|
||||||
class AssetCreate(AssetForm):
|
class AssetCreate(AssetForm):
|
||||||
URL_TEMPLATE = '/assets/asset/create/'
|
URL_TEMPLATE = '/assets/asset/create/'
|
||||||
_submit_locator = (By.CLASS_NAME, 'btn-success')
|
|
||||||
|
|
||||||
def submit(self):
|
|
||||||
previous_errors = self.errors
|
|
||||||
self.find_element(*self._submit_locator).click()
|
|
||||||
self.wait.until(lambda x: self.errors != previous_errors or self.success)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self):
|
def success(self):
|
||||||
return '/create' not in self.driver.current_url
|
return '/create' not in self.driver.current_url
|
||||||
|
|
||||||
|
|
||||||
|
class AssetDuplicate(AssetForm):
|
||||||
|
URL_TEMPLATE = '/assets/asset/id/{asset_id}/duplicate'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def success(self):
|
||||||
|
return '/duplicate' not in self.driver.current_url
|
||||||
|
|
||||||
|
|
||||||
class SupplierList(BasePage):
|
class SupplierList(BasePage):
|
||||||
URL_TEMPLATE = reverse('supplier_list')
|
URL_TEMPLATE = reverse('supplier_list')
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ class TestAssetForm(AutoLoginTest):
|
|||||||
self.assertTrue(self.page.success)
|
self.assertTrue(self.page.success)
|
||||||
|
|
||||||
def test_asset_edit(self):
|
def test_asset_edit(self):
|
||||||
self.page = pages.AssetEdit(self.driver, self.live_server_url, asset_id="9000").open()
|
self.page = pages.AssetEdit(self.driver, self.live_server_url, asset_id=self.parent.asset_id).open()
|
||||||
|
|
||||||
self.assertTrue(self.driver.find_element_by_id('id_asset_id').get_attribute('readonly') is not None)
|
self.assertTrue(self.driver.find_element_by_id('id_asset_id').get_attribute('readonly') is not None)
|
||||||
|
|
||||||
@@ -126,7 +126,20 @@ class TestAssetForm(AutoLoginTest):
|
|||||||
self.page.submit()
|
self.page.submit()
|
||||||
self.assertTrue(self.page.success)
|
self.assertTrue(self.page.success)
|
||||||
|
|
||||||
self.assertEqual(models.Asset.objects.get(asset_id="9000").description, new_description)
|
self.assertEqual(models.Asset.objects.get(asset_id=self.parent.asset_id).description, new_description)
|
||||||
|
|
||||||
|
def test_asset_duplicate(self):
|
||||||
|
self.page = pages.AssetDuplicate(self.driver, self.live_server_url, asset_id=self.parent.asset_id).open()
|
||||||
|
|
||||||
|
self.assertNotEqual(self.parent.asset_id, self.page.asset_id)
|
||||||
|
self.assertEqual(self.parent.description, self.page.description)
|
||||||
|
self.assertEqual(self.parent.status.name, self.page.status)
|
||||||
|
self.assertEqual(self.parent.category.name, self.page.category)
|
||||||
|
self.assertEqual(self.parent.date_acquired, self.page.date_acquired.date())
|
||||||
|
|
||||||
|
self.page.submit()
|
||||||
|
self.assertTrue(self.page.success)
|
||||||
|
self.assertEqual(models.Asset.objects.last().description, self.parent.description)
|
||||||
|
|
||||||
|
|
||||||
class TestSupplierList(AutoLoginTest):
|
class TestSupplierList(AutoLoginTest):
|
||||||
@@ -335,6 +348,15 @@ class TestFormValidation(TestCase):
|
|||||||
self.assertFormError(response, 'form', 'circuits', 'There must be at least one circuit in a cable')
|
self.assertFormError(response, 'form', 'circuits', 'There must be at least one circuit in a cable')
|
||||||
self.assertFormError(response, 'form', 'cores', 'There must be at least one core in a cable')
|
self.assertFormError(response, 'form', 'cores', 'There must be at least one core in a cable')
|
||||||
|
|
||||||
|
def test_asset_duplicate(self):
|
||||||
|
url = reverse('asset_duplicate', kwargs={'pk': self.cable_asset.asset_id})
|
||||||
|
response = self.client.post(url, {'is_cable': True, 'length': 0, 'csa': 0, 'circuits': 0, 'cores': 0})
|
||||||
|
|
||||||
|
self.assertFormError(response, 'form', 'length', 'The length of a cable must be more than 0')
|
||||||
|
self.assertFormError(response, 'form', 'csa', 'The CSA of a cable must be more than 0')
|
||||||
|
self.assertFormError(response, 'form', 'circuits', 'There must be at least one circuit in a cable')
|
||||||
|
self.assertFormError(response, 'form', 'cores', 'There must be at least one core in a cable')
|
||||||
|
|
||||||
|
|
||||||
class TestSampleDataGenerator(TestCase):
|
class TestSampleDataGenerator(TestCase):
|
||||||
@override_settings(DEBUG=True)
|
@override_settings(DEBUG=True)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, Http404
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
@@ -87,8 +87,7 @@ class AssetIDUrlMixin:
|
|||||||
# Get the single item from the filtered queryset
|
# Get the single item from the filtered queryset
|
||||||
obj = queryset.get()
|
obj = queryset.get()
|
||||||
except queryset.model.DoesNotExist:
|
except queryset.model.DoesNotExist:
|
||||||
raise Http404(_("No %(verbose_name)s found matching the query") %
|
raise Http404("No assets found matching the query")
|
||||||
{'verbose_name': queryset.model._meta.verbose_name})
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user