mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 03:30:54 +00:00
[CI] docstrings (#6172)
* Squashed commit of the following: commit52d7ff0f65
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 23:03:20 2024 +0100 fixed lookup commit0d076eaea8
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 23:03:08 2024 +0100 switched to pathlib for lookup commit473e75eda2
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 22:52:30 2024 +0100 fix wrong url response commitfd74f8d703
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 21:14:38 2024 +0100 switched to ruff for import sorting commitf83fedbbb8
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 21:03:14 2024 +0100 switched to single quotes everywhere commita92442e60e
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:58:23 2024 +0100 added autofixes commitcc66c93136
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:56:47 2024 +0100 enable autoformat commit1f343606ec
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:42:14 2024 +0100 Squashed commit of the following: commitf5cf7b2e78
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:36:57 2024 +0100 fixed reqs commit9d845bee98
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:32:35 2024 +0100 disable autofix/format commitaff5f27148
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:28:50 2024 +0100 adjust checks commit47271cf1ef
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:28:22 2024 +0100 reorder order of operations commite1bf178b40
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:01:09 2024 +0100 adapted ruff settings to better fit code base commitad7d88a6f4
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:59:45 2024 +0100 auto fixed docstring commita2e54a760e
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:46:35 2024 +0100 fix getattr useage commitcb80c73bc6
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:25:09 2024 +0100 fix requirements file commitb7780bbd21
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:42:28 2024 +0100 fix removed sections commit71f1681f55
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:41:21 2024 +0100 fix djlint syntax commita0bcf1bcce
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:35:28 2024 +0100 remove flake8 from code base commit22475b31cc
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:34:56 2024 +0100 remove flake8 from code base commit0413350f14
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:24:39 2024 +0100 moved ruff section commitd90c48a0bf
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:24:24 2024 +0100 move djlint config to pyproject commitc5ce55d511
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:20:39 2024 +0100 added isort again commit42a41d23af
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:19:02 2024 +0100 move config section commit8569233181
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:17:52 2024 +0100 fix codespell error commit2897c6704d
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 17:29:21 2024 +0100 replaced flake8 with ruff mostly for speed improvements * enable docstring checks * fix docstrings * fixed D417 Missing argument description * Squashed commit of the following: commitd3b795824b
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 22:56:17 2024 +0100 fixed source path commit0bac0c19b8
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 22:47:53 2024 +0100 fixed req commit9f61f01d9c
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 22:45:18 2024 +0100 added missing toml req commit91b71ed24a
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:49:50 2024 +0100 moved isort config commit12460b0419
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:43:22 2024 +0100 remove flake8 section from setup.cfg commitf5cf7b2e78
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:36:57 2024 +0100 fixed reqs commit9d845bee98
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:32:35 2024 +0100 disable autofix/format commitaff5f27148
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:28:50 2024 +0100 adjust checks commit47271cf1ef
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:28:22 2024 +0100 reorder order of operations commite1bf178b40
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:01:09 2024 +0100 adapted ruff settings to better fit code base commitad7d88a6f4
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:59:45 2024 +0100 auto fixed docstring commita2e54a760e
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:46:35 2024 +0100 fix getattr useage commitcb80c73bc6
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:25:09 2024 +0100 fix requirements file commitb7780bbd21
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:42:28 2024 +0100 fix removed sections commit71f1681f55
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:41:21 2024 +0100 fix djlint syntax commita0bcf1bcce
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:35:28 2024 +0100 remove flake8 from code base commit22475b31cc
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:34:56 2024 +0100 remove flake8 from code base commit0413350f14
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:24:39 2024 +0100 moved ruff section commitd90c48a0bf
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:24:24 2024 +0100 move djlint config to pyproject commitc5ce55d511
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:20:39 2024 +0100 added isort again commit42a41d23af
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:19:02 2024 +0100 move config section commit8569233181
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:17:52 2024 +0100 fix codespell error commit2897c6704d
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 17:29:21 2024 +0100 replaced flake8 with ruff mostly for speed improvements * fix pyproject * make docstrings more uniform * auto-format * fix order * revert url change
This commit is contained in:
@ -110,12 +110,12 @@ class WebhookView(CsrfExemptMixin, APIView):
|
||||
|
||||
|
||||
class CurrencyExchangeView(APIView):
|
||||
"""API endpoint for displaying currency information"""
|
||||
"""API endpoint for displaying currency information."""
|
||||
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
def get(self, request, format=None):
|
||||
"""Return information on available currency conversions"""
|
||||
"""Return information on available currency conversions."""
|
||||
# Extract a list of all available rates
|
||||
try:
|
||||
rates = Rate.objects.all()
|
||||
@ -157,7 +157,7 @@ class CurrencyRefreshView(APIView):
|
||||
permission_classes = [permissions.IsAuthenticated, permissions.IsAdminUser]
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""Performing a POST request will update currency exchange rates"""
|
||||
"""Performing a POST request will update currency exchange rates."""
|
||||
from InvenTree.tasks import update_exchange_rates
|
||||
|
||||
update_exchange_rates(force=True)
|
||||
@ -185,7 +185,7 @@ class GlobalSettingsList(SettingsList):
|
||||
serializer_class = common.serializers.GlobalSettingsSerializer
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
"""Ensure all global settings are created"""
|
||||
"""Ensure all global settings are created."""
|
||||
common.models.InvenTreeSetting.build_default_values()
|
||||
return super().list(request, *args, **kwargs)
|
||||
|
||||
@ -241,7 +241,7 @@ class UserSettingsList(SettingsList):
|
||||
serializer_class = common.serializers.UserSettingsSerializer
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
"""Ensure all user settings are created"""
|
||||
"""Ensure all user settings are created."""
|
||||
common.models.InvenTreeUserSetting.build_default_values(user=request.user)
|
||||
return super().list(request, *args, **kwargs)
|
||||
|
||||
@ -361,7 +361,7 @@ class NotificationList(NotificationMessageMixin, BulkDeleteMixin, ListAPI):
|
||||
return queryset
|
||||
|
||||
def filter_delete_queryset(self, queryset, request):
|
||||
"""Ensure that the user can only delete their *own* notifications"""
|
||||
"""Ensure that the user can only delete their *own* notifications."""
|
||||
queryset = queryset.filter(user=request.user)
|
||||
return queryset
|
||||
|
||||
@ -440,7 +440,7 @@ class NotesImageList(ListCreateAPI):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
def perform_create(self, serializer):
|
||||
"""Create (upload) a new notes image"""
|
||||
"""Create (upload) a new notes image."""
|
||||
image = serializer.save()
|
||||
image.user = self.request.user
|
||||
image.save()
|
||||
@ -460,7 +460,7 @@ class ProjectCodeList(ListCreateAPI):
|
||||
|
||||
|
||||
class ProjectCodeDetail(RetrieveUpdateDestroyAPI):
|
||||
"""Detail view for a particular project code"""
|
||||
"""Detail view for a particular project code."""
|
||||
|
||||
queryset = common.models.ProjectCode.objects.all()
|
||||
serializer_class = common.serializers.ProjectCodeSerializer
|
||||
@ -468,7 +468,7 @@ class ProjectCodeDetail(RetrieveUpdateDestroyAPI):
|
||||
|
||||
|
||||
class CustomUnitList(ListCreateAPI):
|
||||
"""List view for custom units"""
|
||||
"""List view for custom units."""
|
||||
|
||||
queryset = common.models.CustomUnit.objects.all()
|
||||
serializer_class = common.serializers.CustomUnitSerializer
|
||||
@ -477,7 +477,7 @@ class CustomUnitList(ListCreateAPI):
|
||||
|
||||
|
||||
class CustomUnitDetail(RetrieveUpdateDestroyAPI):
|
||||
"""Detail view for a particular custom unit"""
|
||||
"""Detail view for a particular custom unit."""
|
||||
|
||||
queryset = common.models.CustomUnit.objects.all()
|
||||
serializer_class = common.serializers.CustomUnitSerializer
|
||||
|
@ -19,7 +19,6 @@ class CommonConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
"""Initialize restart flag clearance on startup."""
|
||||
|
||||
if InvenTree.ready.isRunningMigrations():
|
||||
return
|
||||
|
||||
|
@ -77,14 +77,15 @@ class MetaMixin(models.Model):
|
||||
|
||||
|
||||
class BaseURLValidator(URLValidator):
|
||||
"""Validator for the InvenTree base URL:
|
||||
"""Validator for the InvenTree base URL.
|
||||
|
||||
Rules:
|
||||
- Allow empty value
|
||||
- Allow value without specified TLD (top level domain)
|
||||
"""
|
||||
|
||||
def __init__(self, schemes=None, **kwargs):
|
||||
"""Custom init routine"""
|
||||
"""Custom init routine."""
|
||||
super().__init__(schemes, **kwargs)
|
||||
|
||||
# Override default host_re value - allow optional tld regex
|
||||
@ -145,7 +146,7 @@ class ProjectCode(InvenTree.models.MetadataMixin, models.Model):
|
||||
|
||||
|
||||
class SettingsKeyType(TypedDict, total=False):
|
||||
"""Type definitions for a SettingsKeyType
|
||||
"""Type definitions for a SettingsKeyType.
|
||||
|
||||
Attributes:
|
||||
name: Translatable string name of the setting (required)
|
||||
@ -216,7 +217,7 @@ class BaseInvenTreeSetting(models.Model):
|
||||
|
||||
@classmethod
|
||||
def build_default_values(cls, **kwargs):
|
||||
"""Ensure that all values defined in SETTINGS are present in the database
|
||||
"""Ensure that all values defined in SETTINGS are present in the database.
|
||||
|
||||
If a particular setting is not present, create it with the default value
|
||||
"""
|
||||
@ -269,13 +270,13 @@ class BaseInvenTreeSetting(models.Model):
|
||||
|
||||
@property
|
||||
def cache_key(self):
|
||||
"""Generate a unique cache key for this settings object"""
|
||||
"""Generate a unique cache key for this settings object."""
|
||||
return self.__class__.create_cache_key(
|
||||
self.key, **self.get_filters_for_instance()
|
||||
)
|
||||
|
||||
def save_to_cache(self):
|
||||
"""Save this setting object to cache"""
|
||||
"""Save this setting object to cache."""
|
||||
ckey = self.cache_key
|
||||
|
||||
# skip saving to cache if no pk is set
|
||||
@ -308,7 +309,7 @@ class BaseInvenTreeSetting(models.Model):
|
||||
|
||||
@classmethod
|
||||
def get_filters(cls, **kwargs):
|
||||
"""Enable to filter by other kwargs defined in cls.extra_unique_fields"""
|
||||
"""Enable to filter by other kwargs defined in cls.extra_unique_fields."""
|
||||
return {
|
||||
key: value
|
||||
for key, value in kwargs.items()
|
||||
@ -316,7 +317,7 @@ class BaseInvenTreeSetting(models.Model):
|
||||
}
|
||||
|
||||
def get_filters_for_instance(self):
|
||||
"""Enable to filter by other fields defined in self.extra_unique_fields"""
|
||||
"""Enable to filter by other fields defined in self.extra_unique_fields."""
|
||||
return {
|
||||
key: getattr(self, key, None)
|
||||
for key in self.extra_unique_fields
|
||||
@ -1090,7 +1091,7 @@ def validate_email_domains(setting):
|
||||
|
||||
|
||||
def currency_exchange_plugins():
|
||||
"""Return a set of plugin choices which can be used for currency exchange"""
|
||||
"""Return a set of plugin choices which can be used for currency exchange."""
|
||||
try:
|
||||
from plugin import registry
|
||||
|
||||
@ -1102,7 +1103,7 @@ def currency_exchange_plugins():
|
||||
|
||||
|
||||
def update_exchange_rates(setting):
|
||||
"""Update exchange rates when base currency is changed"""
|
||||
"""Update exchange rates when base currency is changed."""
|
||||
if InvenTree.ready.isImportingData():
|
||||
return
|
||||
|
||||
@ -1113,7 +1114,7 @@ def update_exchange_rates(setting):
|
||||
|
||||
|
||||
def reload_plugin_registry(setting):
|
||||
"""When a core plugin setting is changed, reload the plugin registry"""
|
||||
"""When a core plugin setting is changed, reload the plugin registry."""
|
||||
from plugin import registry
|
||||
|
||||
logger.info("Reloading plugin registry due to change in setting '%s'", setting.key)
|
||||
@ -2752,7 +2753,7 @@ class NotificationEntry(MetaMixin):
|
||||
|
||||
|
||||
class NotificationMessage(models.Model):
|
||||
"""A NotificationMessage is a message sent to a particular user, notifying them of some *important information*
|
||||
"""A NotificationMessage is a message sent to a particular user, notifying them of some *important information*.
|
||||
|
||||
Notification messages can be generated by a variety of sources.
|
||||
|
||||
@ -2870,7 +2871,7 @@ class NotesImage(models.Model):
|
||||
|
||||
|
||||
class CustomUnit(models.Model):
|
||||
"""Model for storing custom physical unit definitions
|
||||
"""Model for storing custom physical unit definitions.
|
||||
|
||||
Model Attributes:
|
||||
name: Name of the unit
|
||||
@ -2882,7 +2883,7 @@ class CustomUnit(models.Model):
|
||||
"""
|
||||
|
||||
def fmt_string(self):
|
||||
"""Construct a unit definition string e.g. 'dog_year = 52 * day = dy'"""
|
||||
"""Construct a unit definition string e.g. 'dog_year = 52 * day = dy'."""
|
||||
fmt = f'{self.name} = {self.definition}'
|
||||
|
||||
if self.symbol:
|
||||
@ -2891,7 +2892,7 @@ class CustomUnit(models.Model):
|
||||
return fmt
|
||||
|
||||
def clean(self):
|
||||
"""Validate that the provided custom unit is indeed valid"""
|
||||
"""Validate that the provided custom unit is indeed valid."""
|
||||
super().clean()
|
||||
|
||||
from InvenTree.conversion import get_unit_registry
|
||||
@ -2946,7 +2947,7 @@ class CustomUnit(models.Model):
|
||||
@receiver(post_save, sender=CustomUnit, dispatch_uid='custom_unit_saved')
|
||||
@receiver(post_delete, sender=CustomUnit, dispatch_uid='custom_unit_deleted')
|
||||
def after_custom_unit_updated(sender, instance, **kwargs):
|
||||
"""Callback when a custom unit is updated or deleted"""
|
||||
"""Callback when a custom unit is updated or deleted."""
|
||||
# Force reload of the unit registry
|
||||
from InvenTree.conversion import reload_unit_registry
|
||||
|
||||
|
@ -263,7 +263,7 @@ class UIMessageNotification(SingleNotificationMethod):
|
||||
METHOD_NAME = 'ui_message'
|
||||
|
||||
def get_targets(self):
|
||||
"""Only send notifications for active users"""
|
||||
"""Only send notifications for active users."""
|
||||
return [target for target in self.targets if target.is_active]
|
||||
|
||||
def send(self, target):
|
||||
|
@ -23,14 +23,14 @@ class SettingsValueField(serializers.Field):
|
||||
return instance
|
||||
|
||||
def to_representation(self, instance):
|
||||
"""Return the value of the setting:
|
||||
"""Return the value of the setting.
|
||||
|
||||
- Protected settings are returned as '***'
|
||||
Protected settings are returned as '***'
|
||||
"""
|
||||
return '***' if instance.protected else str(instance.value)
|
||||
|
||||
def to_internal_value(self, data):
|
||||
"""Return the internal value of the setting"""
|
||||
"""Return the internal value of the setting."""
|
||||
return str(data)
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
def currency_code_default():
|
||||
"""Returns the default currency code (or USD if not specified)"""
|
||||
"""Returns the default currency code (or USD if not specified)."""
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
cached_value = cache.get('currency_code_default', '')
|
||||
|
@ -134,14 +134,14 @@ class SettingsTest(InvenTreeTestCase):
|
||||
self.assertNotIn('SERVER_RESTART_REQUIRED', result)
|
||||
|
||||
def test_all_settings(self):
|
||||
"""Make sure that the all_settings function returns correctly"""
|
||||
"""Make sure that the all_settings function returns correctly."""
|
||||
result = InvenTreeSetting.all_settings()
|
||||
self.assertIn('INVENTREE_INSTANCE', result)
|
||||
self.assertIsInstance(result['INVENTREE_INSTANCE'], InvenTreeSetting)
|
||||
|
||||
@mock.patch('common.models.InvenTreeSetting.get_setting_definition')
|
||||
def test_check_all_settings(self, get_setting_definition):
|
||||
"""Make sure that the check_all_settings function returns correctly"""
|
||||
"""Make sure that the check_all_settings function returns correctly."""
|
||||
# define partial schema
|
||||
settings_definition = {
|
||||
'AB': { # key that's has not already been accessed
|
||||
@ -295,7 +295,7 @@ class SettingsTest(InvenTreeTestCase):
|
||||
) # pragma: no cover
|
||||
|
||||
def test_global_setting_caching(self):
|
||||
"""Test caching operations for the global settings class"""
|
||||
"""Test caching operations for the global settings class."""
|
||||
key = 'PART_NAME_FORMAT'
|
||||
|
||||
cache_key = InvenTreeSetting.create_cache_key(key)
|
||||
@ -316,7 +316,7 @@ class SettingsTest(InvenTreeTestCase):
|
||||
self.assertEqual(InvenTreeSetting.get_setting(key), val)
|
||||
|
||||
def test_user_setting_caching(self):
|
||||
"""Test caching operation for the user settings class"""
|
||||
"""Test caching operation for the user settings class."""
|
||||
cache.clear()
|
||||
|
||||
# Generate a number of new users
|
||||
@ -348,7 +348,7 @@ class GlobalSettingsApiTest(InvenTreeAPITestCase):
|
||||
"""Tests for the global settings API."""
|
||||
|
||||
def setUp(self):
|
||||
"""Ensure cache is cleared as part of test setup"""
|
||||
"""Ensure cache is cleared as part of test setup."""
|
||||
cache.clear()
|
||||
return super().setUp()
|
||||
|
||||
@ -825,7 +825,7 @@ class NotificationTest(InvenTreeAPITestCase):
|
||||
response = self.post(url, {}, expected_code=405)
|
||||
|
||||
def test_bulk_delete(self):
|
||||
"""Tests for bulk deletion of user notifications"""
|
||||
"""Tests for bulk deletion of user notifications."""
|
||||
from error_report.models import Error
|
||||
|
||||
# Create some notification messages by throwing errors
|
||||
@ -1004,17 +1004,17 @@ class ColorThemeTest(TestCase):
|
||||
|
||||
|
||||
class CurrencyAPITests(InvenTreeAPITestCase):
|
||||
"""Unit tests for the currency exchange API endpoints"""
|
||||
"""Unit tests for the currency exchange API endpoints."""
|
||||
|
||||
def test_exchange_endpoint(self):
|
||||
"""Test that the currency exchange endpoint works as expected"""
|
||||
"""Test that the currency exchange endpoint works as expected."""
|
||||
response = self.get(reverse('api-currency-exchange'), expected_code=200)
|
||||
|
||||
self.assertIn('base_currency', response.data)
|
||||
self.assertIn('exchange_rates', response.data)
|
||||
|
||||
def test_refresh_endpoint(self):
|
||||
"""Call the 'refresh currencies' endpoint"""
|
||||
"""Call the 'refresh currencies' endpoint."""
|
||||
from djmoney.contrib.exchange.models import Rate
|
||||
|
||||
# Delete any existing exchange rate data
|
||||
@ -1074,7 +1074,7 @@ class NotesImageTest(InvenTreeAPITestCase):
|
||||
self.assertEqual(NotesImage.objects.count(), n)
|
||||
|
||||
def test_valid_image(self):
|
||||
"""Test upload of a valid image file"""
|
||||
"""Test upload of a valid image file."""
|
||||
n = NotesImage.objects.count()
|
||||
|
||||
# Construct a simple image file
|
||||
@ -1100,16 +1100,16 @@ class NotesImageTest(InvenTreeAPITestCase):
|
||||
|
||||
|
||||
class ProjectCodesTest(InvenTreeAPITestCase):
|
||||
"""Units tests for the ProjectCodes model and API endpoints"""
|
||||
"""Units tests for the ProjectCodes model and API endpoints."""
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
"""Return the URL for the project code list endpoint"""
|
||||
"""Return the URL for the project code list endpoint."""
|
||||
return reverse('api-project-code-list')
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
"""Create some initial project codes"""
|
||||
"""Create some initial project codes."""
|
||||
super().setUpTestData()
|
||||
|
||||
codes = [
|
||||
@ -1122,12 +1122,12 @@ class ProjectCodesTest(InvenTreeAPITestCase):
|
||||
ProjectCode.objects.bulk_create(codes)
|
||||
|
||||
def test_list(self):
|
||||
"""Test that the list endpoint works as expected"""
|
||||
"""Test that the list endpoint works as expected."""
|
||||
response = self.get(self.url, expected_code=200)
|
||||
self.assertEqual(len(response.data), ProjectCode.objects.count())
|
||||
|
||||
def test_delete(self):
|
||||
"""Test we can delete a project code via the API"""
|
||||
"""Test we can delete a project code via the API."""
|
||||
n = ProjectCode.objects.count()
|
||||
|
||||
# Get the first project code
|
||||
@ -1143,7 +1143,7 @@ class ProjectCodesTest(InvenTreeAPITestCase):
|
||||
self.assertEqual(ProjectCode.objects.count(), n - 1)
|
||||
|
||||
def test_duplicate_code(self):
|
||||
"""Test that we cannot create two project codes with the same code"""
|
||||
"""Test that we cannot create two project codes with the same code."""
|
||||
# Create a new project code
|
||||
response = self.post(
|
||||
self.url,
|
||||
@ -1157,7 +1157,7 @@ class ProjectCodesTest(InvenTreeAPITestCase):
|
||||
)
|
||||
|
||||
def test_write_access(self):
|
||||
"""Test that non-staff users have read-only access"""
|
||||
"""Test that non-staff users have read-only access."""
|
||||
# By default user has staff access, can create a new project code
|
||||
response = self.post(
|
||||
self.url,
|
||||
@ -1196,16 +1196,16 @@ class ProjectCodesTest(InvenTreeAPITestCase):
|
||||
|
||||
|
||||
class CustomUnitAPITest(InvenTreeAPITestCase):
|
||||
"""Unit tests for the CustomUnit API"""
|
||||
"""Unit tests for the CustomUnit API."""
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
"""Return the API endpoint for the CustomUnit list"""
|
||||
"""Return the API endpoint for the CustomUnit list."""
|
||||
return reverse('api-custom-unit-list')
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
"""Construct some initial test fixture data"""
|
||||
"""Construct some initial test fixture data."""
|
||||
super().setUpTestData()
|
||||
|
||||
units = [
|
||||
@ -1222,12 +1222,12 @@ class CustomUnitAPITest(InvenTreeAPITestCase):
|
||||
CustomUnit.objects.bulk_create(units)
|
||||
|
||||
def test_list(self):
|
||||
"""Test API list functionality"""
|
||||
"""Test API list functionality."""
|
||||
response = self.get(self.url, expected_code=200)
|
||||
self.assertEqual(len(response.data), CustomUnit.objects.count())
|
||||
|
||||
def test_edit(self):
|
||||
"""Test edit permissions for CustomUnit model"""
|
||||
"""Test edit permissions for CustomUnit model."""
|
||||
unit = CustomUnit.objects.first()
|
||||
|
||||
# Try to edit without permission
|
||||
@ -1254,7 +1254,7 @@ class CustomUnitAPITest(InvenTreeAPITestCase):
|
||||
self.assertEqual(unit.name, 'new_unit_name')
|
||||
|
||||
def test_validation(self):
|
||||
"""Test that validation works as expected"""
|
||||
"""Test that validation works as expected."""
|
||||
unit = CustomUnit.objects.first()
|
||||
|
||||
self.user.is_staff = True
|
||||
|
Reference in New Issue
Block a user