2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-09 07:00:56 +00:00

[WIP] Test result table (#6430)

* Add basic table for stock item test results

* Improve custom data formatter callback

* Custom data formatter for returned results

* Update YesNoButton functionality

- Add PassFailButton with custom text

* Enhancements for stock item test result table

- Render all data

* Add placeholder row actions

* Fix table link

* Add option to filter parttesttemplate table by "inherited"

* Navigate through to parent part

* Update PartTestTemplate model

- Save 'key' value to database
- Update whenever model is saved
- Custom data migration

* Custom migration step in tasks.py

- Add custom management command
- Wraps migration step in maintenance mode

* Improve uniqueness validation for PartTestTemplate

* Add 'template' field to StockItemTestResult

- Links to a PartTestTemplate instance
- Add migrations to link existing PartTestTemplates

* Add "results" count to PartTestTemplate API

- Include in rendered tables

* Add 'results' column to test result table

- Allow filtering too

* Update serializer for StockItemTestResult

- Include template information
- Update CUI and PUI tables

* Control template_detail field with query params

* Update ref in api_version.py

* Update data migration

- Ensure new template is created for top level assembly

* Fix admin integration

* Update StockItemTestResult table

- Remove 'test' field
- Make 'template' field non-nullable
- Previous data migrations should have accounted for this

* Implement "legacy" API support

- Create test result by providing test name
- Lookup existing template

* PUI: Cleanup table

* Update tasks.py

- Exclude temporary settings when exporting data

* Fix unique validation check

* Remove duplicate code

* CUI: Fix data rendering

* More refactoring of PUI table

* More fixes for PUI table

* Get row expansion working (kinda)

* Improve rendering of subtable

* More PUI updates:

- Edit existing results
- Add new results

* allow delete of test result

* Fix typo

* Updates for admin integration

* Unit tests for stock migrations

* Added migration test for PartTestTemplate

* Fix for AttachmentTable

- Rebuild actions when permissions are recalculated

* Update test fixtures

* Add ModelType information

* Fix TableState

* Fix dataFormatter type def

* Improve table rendering

* Correctly filter "edit" and "delete" buttons

* Loosen requirements for dataFormatter

* Fixtures for report tests

* Better API filtering for StocokItemTestResult list

- Add Filter class
- Add option for filtering against legacy "name" data

* Cleanup API filter

* Fix unit tests

* Further unit test fixes

* Include test results for installed stock items

* Improve rendering of test result table

* Fix filtering for getTestResults

* More unit test fixes

* Fix more unit tests

* FIx part unit test

* More fixes

* More unit test fixes

* Rebuild stock item trees when merging

* Helper function for adding a test result to a stock item

* Set init fix

* Code cleanup

* Cleanup unused variables

* Add docs and more unit tests

* Update build unit test
This commit is contained in:
Oliver
2024-02-18 23:26:01 +11:00
committed by GitHub
parent ad1c1ae604
commit 0f51127adf
50 changed files with 1505 additions and 243 deletions

View File

@ -19,7 +19,7 @@ import part.models
from common.models import InvenTreeSetting
from InvenTree.status_codes import StockHistoryCode, StockStatus
from InvenTree.unit_test import InvenTreeAPITestCase
from part.models import Part
from part.models import Part, PartTestTemplate
from stock.models import (
StockItem,
StockItemTestResult,
@ -34,6 +34,7 @@ class StockAPITestCase(InvenTreeAPITestCase):
fixtures = [
'category',
'part',
'test_templates',
'bom',
'company',
'location',
@ -1559,6 +1560,8 @@ class StockTestResultTest(StockAPITestCase):
response = self.client.get(url)
n = len(response.data)
# Test upload using test name (legacy method)
# Note that a new test template will be created
data = {
'stock_item': 105,
'test': 'Checked Steam Valve',
@ -1569,6 +1572,9 @@ class StockTestResultTest(StockAPITestCase):
response = self.post(url, data, expected_code=201)
# Check that a new test template has been created
test_template = PartTestTemplate.objects.get(key='checkedsteamvalve')
response = self.client.get(url)
self.assertEqual(len(response.data), n + 1)
@ -1581,6 +1587,27 @@ class StockTestResultTest(StockAPITestCase):
self.assertEqual(test['value'], '150kPa')
self.assertEqual(test['user'], self.user.pk)
# Test upload using template reference (new method)
data = {
'stock_item': 105,
'template': test_template.pk,
'result': True,
'value': '75kPa',
}
response = self.post(url, data, expected_code=201)
# Check that a new test template has been created
self.assertEqual(test_template.test_results.all().count(), 2)
# List test results against the template
response = self.client.get(url, data={'template': test_template.pk})
self.assertEqual(len(response.data), 2)
for item in response.data:
self.assertEqual(item['template'], test_template.pk)
def test_post_bitmap(self):
"""2021-08-25.
@ -1598,14 +1625,15 @@ class StockTestResultTest(StockAPITestCase):
with open(image_file, 'rb') as bitmap:
data = {
'stock_item': 105,
'test': 'Checked Steam Valve',
'test': 'Temperature Test',
'result': False,
'value': '150kPa',
'notes': 'I guess there was just too much pressure?',
'value': '550C',
'notes': 'I guess there was just too much heat?',
'attachment': bitmap,
}
response = self.client.post(self.get_url(), data)
self.assertEqual(response.status_code, 201)
# Check that an attachment has been uploaded
@ -1619,23 +1647,34 @@ class StockTestResultTest(StockAPITestCase):
url = reverse('api-stock-test-result-list')
stock_item = StockItem.objects.get(pk=1)
# Ensure the part is marked as "trackable"
p = stock_item.part
p.trackable = True
p.save()
# Create some objects (via the API)
for _ii in range(50):
response = self.post(
url,
{
'stock_item': 1,
'stock_item': stock_item.pk,
'test': f'Some test {_ii}',
'result': True,
'value': 'Test result value',
},
expected_code=201,
# expected_code=201,
)
tests.append(response.data['pk'])
self.assertEqual(StockItemTestResult.objects.count(), n + 50)
# Filter test results by part
response = self.get(url, {'part': p.pk}, expected_code=200)
self.assertEqual(len(response.data), 50)
# Attempt a delete without providing items
self.delete(url, {}, expected_code=400)
@ -1838,6 +1877,7 @@ class StockMetadataAPITest(InvenTreeAPITestCase):
fixtures = [
'category',
'part',
'test_templates',
'bom',
'company',
'location',