Update unit tests

This commit is contained in:
Oliver Walters 2026-07-05 10:47:07 +00:00
parent ccc68f19a1
commit cf1d9eb90b
1 changed files with 33 additions and 11 deletions

View File

@ -2195,20 +2195,33 @@ class PartNotesTests(InvenTreeAPITestCase):
roles = ['part.change', 'part.add'] roles = ['part.change', 'part.add']
def test_long_notes(self): def test_long_notes(self):
"""Test that very long notes field is rejected.""" """Test that a very long note content field is rejected.
# Ensure that we cannot upload a very long piece of text
url = reverse('api-part-detail', kwargs={'pk': 1})
response = self.patch(url, {'notes': 'abcde' * 10001}, expected_code=400) Notes are no longer stored directly on the Part model - they are stored
as generic 'Note' instances, linked via a generic foreign key.
"""
# Ensure that we cannot upload a very long piece of text
url = reverse('api-note-list')
response = self.post(
url,
{
'model_type': 'part',
'model_id': 1,
'title': 'Test Note',
'content': 'abcde' * 10001,
},
expected_code=400,
)
self.assertIn( self.assertIn(
'Ensure this field has no more than 50000 characters', 'Ensure this field has no more than 50000 characters',
str(response.data['notes']), str(response.data['content']),
) )
def test_multiline_formatting(self): def test_multiline_formatting(self):
"""Ensure that markdown formatting is retained.""" """Ensure that markdown formatting is retained in a note's content."""
url = reverse('api-part-detail', kwargs={'pk': 1}) url = reverse('api-note-list')
notes = """ notes = """
### Title ### Title
@ -2221,13 +2234,22 @@ class PartNotesTests(InvenTreeAPITestCase):
""" """
response = self.patch(url, {'notes': notes}, expected_code=200) response = self.post(
url,
{
'model_type': 'part',
'model_id': 1,
'title': 'Test Note',
'content': notes,
},
expected_code=201,
)
# Ensure that newline chars have not been removed # Ensure that newline chars have not been removed
self.assertIn('\n', response.data['notes']) self.assertIn('\n', response.data['content'])
# Entire notes field should match original value # Entire note content should match original value
self.assertEqual(response.data['notes'], notes.strip()) self.assertEqual(response.data['content'], notes.strip())
class PartPricingDetailTests(InvenTreeAPITestCase): class PartPricingDetailTests(InvenTreeAPITestCase):