Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openedx_learning/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Open edX Learning ("Learning Core").
"""
__version__ = "0.1.7"
__version__ = "0.1.8"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.19 on 2023-09-26 13:36

from django.db import migrations

import openedx_learning.lib.fields


class Migration(migrations.Migration):

dependencies = [
('oel_tagging', '0008_taxonomy_description_not_null'),
]

operations = [
migrations.AlterField(
model_name='objecttag',
name='object_id',
field=openedx_learning.lib.fields.MultiCollationCharField(db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'}, db_index=True, editable=False, help_text='Identifier for the object being tagged', max_length=255),
),
]
4 changes: 2 additions & 2 deletions openedx_tagging/core/tagging/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.utils.translation import gettext_lazy as _
from typing_extensions import Self # Until we upgrade to python 3.11

from openedx_learning.lib.fields import MultiCollationTextField, case_insensitive_char_field
from openedx_learning.lib.fields import MultiCollationTextField, case_insensitive_char_field, case_sensitive_char_field

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -577,7 +577,7 @@ class ObjectTag(models.Model):
"""

id = models.BigAutoField(primary_key=True)
object_id = case_insensitive_char_field(
object_id = case_sensitive_char_field(
max_length=255,
db_index=True,
editable=False,
Expand Down
32 changes: 32 additions & 0 deletions tests/openedx_tagging/core/tagging/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,38 @@ def test_tag_object_same_value_multiple_free(self) -> None:
)
assert len(object_tags) == 1

def test_tag_object_case_id(self) -> None:
"""
Test that the case of the object_id is preserved.
"""
tagging_api.tag_object(
self.taxonomy,
[self.eubacteria.id],
"biology101",
)

tagging_api.tag_object(
self.taxonomy,
[self.archaea.id],
"BIOLOGY101",
)

object_tags_lower = tagging_api.get_object_tags(
taxonomy_id=self.taxonomy.pk,
object_id="biology101",
)

assert len(object_tags_lower) == 1
assert object_tags_lower[0].tag_id == self.eubacteria.id

object_tags_upper = tagging_api.get_object_tags(
taxonomy_id=self.taxonomy.pk,
object_id="BIOLOGY101",
)

assert len(object_tags_upper) == 1
assert object_tags_upper[0].tag_id == self.archaea.id

@override_settings(LANGUAGES=test_languages)
def test_tag_object_language_taxonomy(self) -> None:
tags_list = [
Expand Down
37 changes: 37 additions & 0 deletions tests/openedx_tagging/core/tagging/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import ddt # type: ignore[import]
from django.contrib.auth import get_user_model
from django.db import transaction
from django.db.utils import IntegrityError
from django.test.testcases import TestCase

Expand Down Expand Up @@ -525,3 +526,39 @@ def test_tag_object_invalid_tag(self):
"biology101",
)
assert "Invalid object tag for taxonomy" in str(exc.exception)

def test_tag_case(self) -> None:
"""
Test that the object_id is case sensitive.
"""
# Tag with object_id with lower case
ObjectTag(
object_id="case:id:2",
taxonomy=self.taxonomy,
tag=self.domain_tags[0],
).save()

# Tag with object_id with upper case should not trigger IntegrityError
ObjectTag(
object_id="CASE:id:2",
taxonomy=self.taxonomy,
tag=self.domain_tags[0],
).save()

# Create another ObjectTag with lower case object_id should trigger IntegrityError
with transaction.atomic():
with self.assertRaises(IntegrityError):
ObjectTag(
object_id="case:id:2",
taxonomy=self.taxonomy,
tag=self.domain_tags[0],
).save()

# Create another ObjectTag with upper case object_id should trigger IntegrityError
with transaction.atomic():
with self.assertRaises(IntegrityError):
ObjectTag(
object_id="CASE:id:2",
taxonomy=self.taxonomy,
tag=self.domain_tags[0],
).save()