Commit 76d86911 by Awais Jibran

Fix Course Syllabus max length issue

In the frontend, TinyMC is removing `\n` `&nbsp` which backend wasn't causing mismatch between the counts. Now updated the backend to use `get_text(strip=True)` method which will remove these from the text.
parent 0304d9f7
import ddt
from django.core.exceptions import ValidationError
from django.test import TestCase
from course_discovery.apps.publisher.validators import validate_text_count
@ddt.ddt
class ValidatorTests(TestCase):
"""
Tests for form validators
"""
@ddt.data(
('<strong>MODULE 0:&nbsp;</strong>', 'MODULE 0:'),
(' <strong>MODULE 0: </strong> ', 'MODULE 0:'),
('\n\n<strong>MODULE 0: \n\n</strong>\n\n', 'MODULE 0:')
)
@ddt.unpack
def test_validate_text_count(self, text_to_validate, expected_clean_text):
"""Tests that validate text count work as expected"""
max_length_allowed = len(expected_clean_text)
validate_text_count(max_length_allowed)(text_to_validate)
# Verify you get a Validation Error if try go below the max.
with self.assertRaises(ValidationError):
validate_text_count(max_length_allowed - 1)(text_to_validate)
......@@ -62,8 +62,7 @@ def validate_text_count(max_length):
Custom validator to count the text area characters without html tags.
"""
def innerfn(raw_html):
cleantext = BeautifulSoup(raw_html, 'html.parser').text.strip()
cleantext = BeautifulSoup(raw_html, 'html.parser').get_text(strip=True)
if len(cleantext) > max_length:
# pylint: disable=no-member
raise forms.ValidationError(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment