mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Markdown notes fix (#3946)
* Improve 'remove_non_printable_characters' method in helpers.py - Requires fancy 'negative-lookahead' regex to negate existing unicode regex * Adds extra test for markdown fields - Ensure that newline characters are retained - Very necessary for markdown formatting! - Update field cleaning to allow newlines in some very specific cases * Bug fix * Better edge case handling
This commit is contained in:
@ -1598,8 +1598,24 @@ class PartDetailTests(InvenTreeAPITestCase):
|
||||
self.assertFalse('hello' in part.metadata)
|
||||
self.assertEqual(part.metadata['x'], 'y')
|
||||
|
||||
def test_part_notes(self):
|
||||
"""Unit tests for the part 'notes' field"""
|
||||
|
||||
class PartNotesTests(InvenTreeAPITestCase):
|
||||
"""Tests for the 'notes' field (markdown field)"""
|
||||
|
||||
fixtures = [
|
||||
'category',
|
||||
'part',
|
||||
'location',
|
||||
'company',
|
||||
]
|
||||
|
||||
roles = [
|
||||
'part.change',
|
||||
'part.add',
|
||||
]
|
||||
|
||||
def test_long_notes(self):
|
||||
"""Test that very long notes field is rejected"""
|
||||
|
||||
# Ensure that we cannot upload a very long piece of text
|
||||
url = reverse('api-part-detail', kwargs={'pk': 1})
|
||||
@ -1614,6 +1630,36 @@ class PartDetailTests(InvenTreeAPITestCase):
|
||||
|
||||
self.assertIn('Ensure this field has no more than 50000 characters', str(response.data['notes']))
|
||||
|
||||
def test_multiline_formatting(self):
|
||||
"""Ensure that markdown formatting is retained"""
|
||||
|
||||
url = reverse('api-part-detail', kwargs={'pk': 1})
|
||||
|
||||
notes = """
|
||||
### Title
|
||||
|
||||
1. Numbered list
|
||||
2. Another item
|
||||
3. Another item again
|
||||
|
||||
[A link](http://link.com.go)
|
||||
|
||||
"""
|
||||
|
||||
response = self.patch(
|
||||
url,
|
||||
{
|
||||
'notes': notes,
|
||||
},
|
||||
expected_code=200
|
||||
)
|
||||
|
||||
# Ensure that newline chars have not been removed
|
||||
self.assertIn('\n', response.data['notes'])
|
||||
|
||||
# Entire notes field should match original value
|
||||
self.assertEqual(response.data['notes'], notes.strip())
|
||||
|
||||
|
||||
class PartPricingDetailTests(InvenTreeAPITestCase):
|
||||
"""Tests for the part pricing API endpoint"""
|
||||
|
Reference in New Issue
Block a user