Skip to content

Commit

Permalink
Added a postgresql test to check long names are shortened to its max …
Browse files Browse the repository at this point in the history
…length
  • Loading branch information
José Redrejo committed Oct 10, 2024
1 parent 4e8c330 commit 130405f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
{
"id": "222455c2cc484298b1501a13e1c7eb5c",
"tag_name": "tag_3"
},
{
"id": "0c20e2eb254b4070a713da63380ff0a3",
"tag_name": "velocidad de reacciones químicas"
}
],
"content_contentnode": [
Expand Down
17 changes: 17 additions & 0 deletions kolibri/core/content/test/test_channel_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import logging
import os
import tempfile
import unittest
import uuid

import pytest
from django.conf import settings
from django.core.management import call_command
from django.test import TestCase
from django.test import TransactionTestCase
Expand All @@ -30,6 +32,7 @@
from kolibri.core.content.models import AssessmentMetaData
from kolibri.core.content.models import ChannelMetadata
from kolibri.core.content.models import ContentNode
from kolibri.core.content.models import ContentTag
from kolibri.core.content.models import File
from kolibri.core.content.models import Language
from kolibri.core.content.models import LocalFile
Expand Down Expand Up @@ -832,6 +835,7 @@ class ImportLongDescriptionsTestCase(ContentImportTestBase, TransactionTestCase)
data_name = "longdescriptions"

longdescription = "soverylong" * 45
long_tag_id = "0c20e2eb254b4070a713da63380ff0a3"

def test_long_descriptions(self):
self.assertEqual(
Expand All @@ -845,6 +849,19 @@ def test_long_descriptions(self):
self.longdescription,
)

@unittest.skipIf(
getattr(settings, "DATABASES")["default"]["ENGINE"]
!= "django.db.backends.postgresql",
"Postgresql only test",
)
def test_import_too_long_content_tags(self):
"""
Test that importing content tags with overly long tag_name fields will truncate correctly.
"""
max_length = ContentTag._meta.get_field("tag_name").max_length
long_imported_tag = ContentTag.objects.get(id=self.long_tag_id)
assert len(long_imported_tag.tag_name) == max_length


class Version4ImportTestCase(NaiveImportTestCase):
"""
Expand Down

0 comments on commit 130405f

Please # to comment.