From 80510e8ba2183927dcc05cb64ff658c2c51b23cd Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 May 2022 02:14:25 +0200 Subject: [PATCH] fix docstrings 2 --- InvenTree/stock/models.py | 5 ++--- InvenTree/stock/serializers.py | 10 +-------- InvenTree/stock/test_api.py | 38 ++++------------------------------ InvenTree/stock/tests.py | 3 +-- InvenTree/stock/views.py | 23 ++++++++------------ InvenTree/users/tests.py | 2 -- 6 files changed, 17 insertions(+), 64 deletions(-) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index be0ab4117d..2eb74a742f 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -1897,9 +1897,7 @@ def after_save_stock_item(sender, instance: StockItem, created, **kwargs): class StockItemAttachment(InvenTreeAttachment): - """ - Model for storing file attachments against a StockItem object. - """ + """Model for storing file attachments against a StockItem object.""" @staticmethod def get_api_url(): @@ -1980,6 +1978,7 @@ def rename_stock_item_test_result_attachment(instance, filename): class StockItemTestResult(models.Model): """A StockItemTestResult records results of custom tests against individual StockItem objects. + This is useful for tracking unit acceptance tests, and particularly useful when integrated with automated testing setups. diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 44f0946194..1f1cf1ed44 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -74,10 +74,7 @@ class StockItemSerializer(InvenTree.serializers.InvenTreeModelSerializer): """ def update(self, instance, validated_data): - """ - Custom update method to pass the user information through to the instance - """ - + """Custom update method to pass the user information through to the instance""" instance._user = self.context['user'] return super().update(instance, validated_data) @@ -276,7 +273,6 @@ class SerializeStockItemSerializer(serializers.Serializer): def validate_quantity(self, quantity): """Validate that the quantity value is correct""" - item = self.context['item'] if quantity < 0: @@ -313,7 +309,6 @@ class SerializeStockItemSerializer(serializers.Serializer): def validate(self, data): """Check that the supplied serial numbers are valid""" - data = super().validate(data) item = self.context['item'] @@ -387,7 +382,6 @@ class InstallStockItemSerializer(serializers.Serializer): def validate_stock_item(self, stock_item): """Validate the selected stock item""" - if not stock_item.in_stock: # StockItem must be in stock to be "installed" raise ValidationError(_("Stock item is unavailable")) @@ -403,7 +397,6 @@ class InstallStockItemSerializer(serializers.Serializer): def save(self): """Install the selected stock item into this one""" - data = self.validated_data stock_item = data['stock_item'] @@ -856,7 +849,6 @@ class StockMergeSerializer(serializers.Serializer): At this point we are confident that the merge can take place """ - data = self.validated_data base_item = data['base_item'] diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py index af02a57d63..7c22ff31c7 100644 --- a/InvenTree/stock/test_api.py +++ b/InvenTree/stock/test_api.py @@ -78,7 +78,6 @@ class StockItemListTest(StockAPITestCase): def get_stock(self, **kwargs): """Filter stock and return JSON object""" - response = self.client.get(self.list_url, format='json', data=kwargs) self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -88,14 +87,12 @@ class StockItemListTest(StockAPITestCase): def test_get_stock_list(self): """List *all* StockItem objects.""" - response = self.get_stock() self.assertEqual(len(response), 29) def test_filter_by_part(self): """Filter StockItem by Part reference""" - response = self.get_stock(part=25) self.assertEqual(len(response), 17) @@ -106,13 +103,11 @@ class StockItemListTest(StockAPITestCase): def test_filter_by_IPN(self): """Filter StockItem by IPN reference""" - response = self.get_stock(IPN="R.CH") self.assertEqual(len(response), 3) def test_filter_by_location(self): """Filter StockItem by StockLocation reference""" - response = self.get_stock(location=5) self.assertEqual(len(response), 1) @@ -127,7 +122,6 @@ class StockItemListTest(StockAPITestCase): def test_filter_by_depleted(self): """Filter StockItem by depleted status""" - response = self.get_stock(depleted=1) self.assertEqual(len(response), 1) @@ -136,7 +130,6 @@ class StockItemListTest(StockAPITestCase): def test_filter_by_in_stock(self): """Filter StockItem by 'in stock' status""" - response = self.get_stock(in_stock=1) self.assertEqual(len(response), 26) @@ -145,7 +138,6 @@ class StockItemListTest(StockAPITestCase): def test_filter_by_status(self): """Filter StockItem by 'status' field""" - codes = { StockStatus.OK: 27, StockStatus.DESTROYED: 1, @@ -162,13 +154,11 @@ class StockItemListTest(StockAPITestCase): def test_filter_by_batch(self): """Filter StockItem by batch code""" - response = self.get_stock(batch='B123') self.assertEqual(len(response), 1) def test_filter_by_serialized(self): """Filter StockItem by serialized status""" - response = self.get_stock(serialized=1) self.assertEqual(len(response), 12) @@ -183,7 +173,6 @@ class StockItemListTest(StockAPITestCase): def test_filter_by_has_batch(self): """Test the 'has_batch' filter, which tests if the stock item has been assigned a batch code""" - with_batch = self.get_stock(has_batch=1) without_batch = self.get_stock(has_batch=0) @@ -200,9 +189,9 @@ class StockItemListTest(StockAPITestCase): def test_filter_by_tracked(self): """Test the 'tracked' filter. + This checks if the stock item has either a batch code *or* a serial number """ - tracked = self.get_stock(tracked=True) untracked = self.get_stock(tracked=False) @@ -220,7 +209,6 @@ class StockItemListTest(StockAPITestCase): def test_filter_by_expired(self): """Filter StockItem by expiry status""" - # First, we can assume that the 'stock expiry' feature is disabled response = self.get_stock(expired=1) self.assertEqual(len(response), 29) @@ -259,7 +247,6 @@ class StockItemListTest(StockAPITestCase): def test_paginate(self): """Test that we can paginate results correctly""" - for n in [1, 5, 10]: response = self.get_stock(limit=n) @@ -289,7 +276,6 @@ class StockItemListTest(StockAPITestCase): def test_export(self): """Test exporting of Stock data via the API""" - dataset = self.export_data({}) # Check that *all* stock item objects have been exported @@ -342,7 +328,6 @@ class StockItemTest(StockAPITestCase): """Test the default location functionality, if a 'location' is not specified in the creation request. """ - # The part 'R_4K7_0603' (pk=4) has a default location specified response = self.client.post( @@ -386,7 +371,6 @@ class StockItemTest(StockAPITestCase): def test_stock_item_create(self): """Test creation of a StockItem via the API""" - # POST with an empty part reference response = self.client.post( @@ -437,7 +421,6 @@ class StockItemTest(StockAPITestCase): def test_creation_with_serials(self): """Test that serialized stock items can be created via the API.""" - trackable_part = part.models.Part.objects.create( name='My part', description='A trackable part', @@ -495,8 +478,7 @@ class StockItemTest(StockAPITestCase): self.assertEqual(trackable_part.get_stock_count(), 10) def test_default_expiry(self): - """ - Test that the "default_expiry" functionality works via the API. + """Test that the "default_expiry" functionality works via the API. - If an expiry_date is specified, use that - Otherwise, check if the referenced part has a default_expiry defined @@ -507,7 +489,6 @@ class StockItemTest(StockAPITestCase): - Part <25> has a default_expiry of 10 days """ - # First test - create a new StockItem without an expiry date data = { 'part': 4, @@ -546,7 +527,6 @@ class StockItemTest(StockAPITestCase): def test_purchase_price(self): """Test that we can correctly read and adjust purchase price information via the API""" - url = reverse('api-stock-detail', kwargs={'pk': 1}) data = self.get(url, expected_code=200).data @@ -605,7 +585,6 @@ class StockItemTest(StockAPITestCase): def test_install(self): """Test that stock item can be installed into antoher item, via the API""" - # Select the "parent" stock item parent_part = part.models.Part.objects.get(pk=100) @@ -691,7 +670,6 @@ class StocktakeTest(StockAPITestCase): def test_action(self): """Test each stocktake action endpoint, for validation""" - for endpoint in ['api-stock-count', 'api-stock-add', 'api-stock-remove']: url = reverse(endpoint) @@ -748,7 +726,6 @@ class StocktakeTest(StockAPITestCase): def test_transfer(self): """Test stock transfers""" - data = { 'items': [ { @@ -886,8 +863,7 @@ class StockTestResultTest(StockAPITestCase): self.assertEqual(test['user'], self.user.pk) def test_post_bitmap(self): - """ - 2021-08-25 + """2021-08-25 For some (unknown) reason, prior to fix https://github.com/inventree/InvenTree/pull/2018 uploading a bitmap image would result in a failure. @@ -896,7 +872,6 @@ class StockTestResultTest(StockAPITestCase): As a bonus this also tests the file-upload component """ - here = os.path.dirname(__file__) image_file = os.path.join(here, 'fixtures', 'test_image.bmp') @@ -921,9 +896,7 @@ class StockTestResultTest(StockAPITestCase): class StockAssignTest(StockAPITestCase): - """Unit tests for the stock assignment API endpoint, - where stock items are manually assigned to a customer - """ + """Unit tests for the stock assignment API endpoint, where stock items are manually assigned to a customer""" URL = reverse('api-stock-assign') @@ -1062,7 +1035,6 @@ class StockMergeTest(StockAPITestCase): def test_missing_data(self): """Test responses which are missing required data""" - # Post completely empty data = self.post( @@ -1088,7 +1060,6 @@ class StockMergeTest(StockAPITestCase): def test_invalid_data(self): """Test responses which have invalid data""" - # Serialized stock items should be rejected data = self.post( self.URL, @@ -1170,7 +1141,6 @@ class StockMergeTest(StockAPITestCase): def test_valid_merge(self): """Test valid merging of stock items""" - # Check initial conditions n = StockItem.objects.filter(part=self.part).count() self.assertEqual(self.item_1.quantity, 100) diff --git a/InvenTree/stock/tests.py b/InvenTree/stock/tests.py index a89817aa9d..325df9a677 100644 --- a/InvenTree/stock/tests.py +++ b/InvenTree/stock/tests.py @@ -188,7 +188,7 @@ class StockTest(InvenTreeTestCase): self.assertEqual(s_item.location, self.office) def test_move(self): - """ Test stock movement functions """ + """Test stock movement functions""" # Move 4,000 screws to the bathroom it = StockItem.objects.get(pk=1) self.assertNotEqual(it.location, self.bathroom) @@ -508,7 +508,6 @@ class StockTest(InvenTreeTestCase): Ref: https://github.com/inventree/InvenTree/issues/2636 Ref: https://github.com/inventree/InvenTree/issues/2733 """ - # First, we will create a stock location structure A = StockLocation.objects.create( diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 5df3f2a027..8d3a59e8bf 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -72,11 +72,7 @@ class StockItemDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView): model = StockItem def get_context_data(self, **kwargs): - """ - Add information on the "next" and "previous" StockItem objects, - based on the serial numbers. - """ - + """Add information on the "next" and "previous" StockItem objects, based on the serial numbers.""" data = super().get_context_data(**kwargs) if self.object.serialized: @@ -97,7 +93,6 @@ class StockItemDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView): def get(self, request, *args, **kwargs): """Check if item exists else return to stock index""" - stock_pk = kwargs.get('pk', None) if stock_pk: @@ -120,7 +115,7 @@ class StockLocationQRCode(QRCodeView): role_required = ['stock_location.view', 'stock.view'] def get_qr_data(self): - """ Generate QR code data for the StockLocation """ + """Generate QR code data for the StockLocation""" try: loc = StockLocation.objects.get(id=self.pk) return loc.format_barcode() @@ -198,7 +193,7 @@ class StockItemQRCode(QRCodeView): role_required = 'stock.view' def get_qr_data(self): - """ Generate QR code data for the StockItem """ + """Generate QR code data for the StockItem""" try: item = StockItem.objects.get(id=self.pk) return item.format_barcode() @@ -237,8 +232,8 @@ class StockItemConvert(AjaxUpdateView): class StockLocationDelete(AjaxDeleteView): - """ - View to delete a StockLocation + """View to delete a StockLocation + Presents a deletion confirmation form to the user """ @@ -250,8 +245,8 @@ class StockLocationDelete(AjaxDeleteView): class StockItemDelete(AjaxDeleteView): - """ - View to delete a StockItem + """View to delete a StockItem + Presents a deletion confirmation form to the user """ @@ -263,8 +258,8 @@ class StockItemDelete(AjaxDeleteView): class StockItemTrackingDelete(AjaxDeleteView): - """ - View to delete a StockItemTracking object + """View to delete a StockItemTracking object + Presents a deletion confirmation form to the user """ diff --git a/InvenTree/users/tests.py b/InvenTree/users/tests.py index 0420096cbf..476e65bec3 100644 --- a/InvenTree/users/tests.py +++ b/InvenTree/users/tests.py @@ -47,7 +47,6 @@ class RuleSetModelTest(TestCase): def test_model_names(self): """Test that each model defined in the rulesets is valid, based on the database schema!""" - available_models = apps.get_models() available_tables = set() @@ -104,7 +103,6 @@ class RuleSetModelTest(TestCase): def test_permission_assign(self): """Test that the permission assigning works!""" - # Create a new group group = Group.objects.create(name="Test group")