Skip to content

Commit

Permalink
Feature: DT-1813 Validate visualisation catalogue item description to…
Browse files Browse the repository at this point in the history
… at least 30 words (#3004)

* Validate visualisation catalogue item description to at least 30 words

* Allow description to be empty
  • Loading branch information
CaitBarnard authored Feb 8, 2024
1 parent 5ef5feb commit c8d1d0a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dataworkspace/dataworkspace/apps/datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,10 @@ def data_is_actively_updated(self):
def __str__(self):
return self.name

def clean(self):
if self.description and len(re.findall(r"\w+", self.description)) < 30:
raise ValidationError("Description must contain 30 or more words")


class AdminVisualisationUserPermission(models.Model):
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
Expand Down
17 changes: 17 additions & 0 deletions dataworkspace/dataworkspace/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3807,3 +3807,20 @@ def test_source_table_reporting_disabled(self, staff_client):

assert response.status_code == 200
assert SourceTable.objects.count() == num_tables + 1


class TestVisualisationCatalogueItemAdmin(BaseAdminTestCase):
def test_update_visualisation_with_description_not_long_enough(self):
dataset = factories.VisualisationCatalogueItemFactory.create()
response = self._authenticated_post(
reverse("admin:datasets_visualisationcatalogueitem_change", args=(dataset.id,)),
{
"published": dataset.published,
"name": dataset.name,
"slug": dataset.slug,
"short_description": "test short description",
"description": "not long enough description",
"type": 2,
},
)
self.assertContains(response, "Description must contain 30 or more words")

0 comments on commit c8d1d0a

Please sign in to comment.