mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Exclude testing exceptions from coverage (#3046)
* exclude testing excetions * check user str * check related users * move no coverage marker * fix assertation * add test for filters * do not cover logs
This commit is contained in:
parent
0ec067da40
commit
6247eecf69
@ -4,7 +4,7 @@ only used for testing the js files! - This file is omited from coverage
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os # pragma: no cover
|
import os # pragma: no cover
|
||||||
import pathlib
|
import pathlib # pragma: no cover
|
||||||
|
|
||||||
from InvenTree.helpers import InvenTreeTestCase # pragma: no cover
|
from InvenTree.helpers import InvenTreeTestCase # pragma: no cover
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ class CurrencyTests(TestCase):
|
|||||||
update_successful = True
|
update_successful = True
|
||||||
break
|
break
|
||||||
|
|
||||||
else:
|
else: # pragma: no cover
|
||||||
print("Exchange rate update failed - retrying")
|
print("Exchange rate update failed - retrying")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -156,14 +156,14 @@ class SettingsTest(InvenTreeTestCase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.run_settings_check(key, setting)
|
self.run_settings_check(key, setting)
|
||||||
except Exception as exc:
|
except Exception as exc: # pragma: no cover
|
||||||
print(f"run_settings_check failed for global setting '{key}'")
|
print(f"run_settings_check failed for global setting '{key}'")
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
for key, setting in InvenTreeUserSetting.SETTINGS.items():
|
for key, setting in InvenTreeUserSetting.SETTINGS.items():
|
||||||
try:
|
try:
|
||||||
self.run_settings_check(key, setting)
|
self.run_settings_check(key, setting)
|
||||||
except Exception as exc:
|
except Exception as exc: # pragma: no cover
|
||||||
print(f"run_settings_check failed for user setting '{key}'")
|
print(f"run_settings_check failed for user setting '{key}'")
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
@ -501,8 +501,12 @@ class PluginSettingsApiTest(InvenTreeAPITestCase):
|
|||||||
"""List installed plugins via API"""
|
"""List installed plugins via API"""
|
||||||
url = reverse('api-plugin-list')
|
url = reverse('api-plugin-list')
|
||||||
|
|
||||||
|
# Simple request
|
||||||
self.get(url, expected_code=200)
|
self.get(url, expected_code=200)
|
||||||
|
|
||||||
|
# Request with filter
|
||||||
|
self.get(url, expected_code=200, data={'mixin': 'settings'})
|
||||||
|
|
||||||
def test_api_list(self):
|
def test_api_list(self):
|
||||||
"""Test list URL"""
|
"""Test list URL"""
|
||||||
url = reverse('api-plugin-setting-list')
|
url = reverse('api-plugin-setting-list')
|
||||||
|
@ -58,7 +58,7 @@ class TemplateTagTest(InvenTreeTestCase):
|
|||||||
|
|
||||||
def test_hash(self):
|
def test_hash(self):
|
||||||
result_hash = inventree_extras.inventree_commit_hash()
|
result_hash = inventree_extras.inventree_commit_hash()
|
||||||
if settings.DOCKER:
|
if settings.DOCKER: # pragma: no cover
|
||||||
# Testing inside docker environment *may* return an empty git commit hash
|
# Testing inside docker environment *may* return an empty git commit hash
|
||||||
# In such a case, skip this check
|
# In such a case, skip this check
|
||||||
pass
|
pass
|
||||||
@ -67,7 +67,7 @@ class TemplateTagTest(InvenTreeTestCase):
|
|||||||
|
|
||||||
def test_date(self):
|
def test_date(self):
|
||||||
d = inventree_extras.inventree_commit_date()
|
d = inventree_extras.inventree_commit_date()
|
||||||
if settings.DOCKER:
|
if settings.DOCKER: # pragma: no cover
|
||||||
# Testing inside docker environment *may* return an empty git commit hash
|
# Testing inside docker environment *may* return an empty git commit hash
|
||||||
# In such a case, skip this check
|
# In such a case, skip this check
|
||||||
pass
|
pass
|
||||||
|
@ -20,7 +20,7 @@ class PluginAppConfig(AppConfig):
|
|||||||
def ready(self):
|
def ready(self):
|
||||||
if settings.PLUGINS_ENABLED:
|
if settings.PLUGINS_ENABLED:
|
||||||
if not canAppAccessDatabase(allow_test=True):
|
if not canAppAccessDatabase(allow_test=True):
|
||||||
logger.info("Skipping plugin loading sequence")
|
logger.info("Skipping plugin loading sequence") # pragma: no cover
|
||||||
else:
|
else:
|
||||||
logger.info('Loading InvenTree plugins')
|
logger.info('Loading InvenTree plugins')
|
||||||
|
|
||||||
@ -48,4 +48,4 @@ class PluginAppConfig(AppConfig):
|
|||||||
log_error(_('Your enviroment has an outdated git version. This prevents InvenTree from loading plugin details.'), 'load')
|
log_error(_('Your enviroment has an outdated git version. This prevents InvenTree from loading plugin details.'), 'load')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.info("Plugins not enabled - skipping loading sequence")
|
logger.info("Plugins not enabled - skipping loading sequence") # pragma: no cover
|
||||||
|
@ -57,10 +57,10 @@ class SettingsMixin:
|
|||||||
except (OperationalError, ProgrammingError): # pragma: no cover
|
except (OperationalError, ProgrammingError): # pragma: no cover
|
||||||
plugin = None
|
plugin = None
|
||||||
|
|
||||||
if not plugin:
|
if not plugin: # pragma: no cover
|
||||||
# Cannot find associated plugin model, return
|
# Cannot find associated plugin model, return
|
||||||
logger.error(f"Plugin configuration not found for plugin '{self.slug}'")
|
logger.error(f"Plugin configuration not found for plugin '{self.slug}'")
|
||||||
return # pragma: no cover
|
return
|
||||||
|
|
||||||
PluginSetting.set_setting(key, value, user, plugin=plugin)
|
PluginSetting.set_setting(key, value, user, plugin=plugin)
|
||||||
|
|
||||||
|
@ -180,11 +180,23 @@ class OwnerModelTest(InvenTreeTestCase):
|
|||||||
group_as_owner = Owner.get_owner(self.group)
|
group_as_owner = Owner.get_owner(self.group)
|
||||||
self.assertEqual(type(group_as_owner), Owner)
|
self.assertEqual(type(group_as_owner), Owner)
|
||||||
|
|
||||||
|
# Check name
|
||||||
|
self.assertEqual(str(user_as_owner), 'testuser (user)')
|
||||||
|
|
||||||
# Get related owners (user + group)
|
# Get related owners (user + group)
|
||||||
related_owners = group_as_owner.get_related_owners(include_group=True)
|
related_owners = group_as_owner.get_related_owners(include_group=True)
|
||||||
self.assertTrue(user_as_owner in related_owners)
|
self.assertTrue(user_as_owner in related_owners)
|
||||||
self.assertTrue(group_as_owner in related_owners)
|
self.assertTrue(group_as_owner in related_owners)
|
||||||
|
|
||||||
|
# Get related owners (only user)
|
||||||
|
related_owners = group_as_owner.get_related_owners(include_group=False)
|
||||||
|
self.assertTrue(user_as_owner in related_owners)
|
||||||
|
self.assertFalse(group_as_owner in related_owners)
|
||||||
|
|
||||||
|
# Get related owners on user
|
||||||
|
related_owners = user_as_owner.get_related_owners()
|
||||||
|
self.assertEqual(related_owners, [user_as_owner])
|
||||||
|
|
||||||
# Check owner matching
|
# Check owner matching
|
||||||
owners = Owner.get_owners_matching_user(self.user)
|
owners = Owner.get_owners_matching_user(self.user)
|
||||||
self.assertEqual(owners, [user_as_owner, group_as_owner])
|
self.assertEqual(owners, [user_as_owner, group_as_owner])
|
||||||
|
Loading…
Reference in New Issue
Block a user