Skip to content

Commit

Permalink
chore: Merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Jun 27, 2023
2 parents 455e783 + 821a53c commit a043b41
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
7 changes: 1 addition & 6 deletions openedx_learning/lib/collations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ def __init__(self, *args, db_collations=None, db_collation=None, **kwargs):
it for Django 3.2 compatibility (see the ``db_collation`` method
docstring for details).
"""
if db_collation is not None:
raise ValueError(
f"Cannot use db_collation with {self.__class__.__name__}. "
+ "Please use a db_collations dict instead."
)

super().__init__(*args, **kwargs)
self.db_collations = db_collations or {}
Expand Down Expand Up @@ -106,7 +101,7 @@ def db_parameters(self, connection):
def deconstruct(self):
"""
How to serialize our Field for the migration file.
For our mixin fields, this is just doing what the field's superclass
would do and then tacking on our custom ``db_collations`` dict data.
"""
Expand Down
1 change: 0 additions & 1 deletion openedx_tagging/core/tagging/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def create_taxonomy(
"""
Creates, saves, and returns a new Taxonomy with the given attributes.
"""

return Taxonomy.objects.create(
name=name,
description=description,
Expand Down
3 changes: 2 additions & 1 deletion openedx_tagging/core/tagging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from openedx_learning.lib.fields import MultiCollationTextField, case_insensitive_char_field


# Maximum depth allowed for a hierarchical taxonomy's tree of tags.
TAXONOMY_MAX_DEPTH = 3

Expand Down Expand Up @@ -203,7 +204,7 @@ def validate_object_tag(
"""
# Must be linked to this taxonomy
if check_taxonomy and (
not object_tag.taxonomy_id or object_tag.taxonomy != self
not object_tag.taxonomy_id or object_tag.taxonomy_id != self.id
):
return False

Expand Down
39 changes: 27 additions & 12 deletions tests/openedx_tagging/core/tagging/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def test_resync_object_tags(self):
changed = tagging_api.resync_object_tags()
assert changed == 2
for object_tag in (missing_links, changed_links, no_changes):
self.check_object_tag(object_tag, self.taxonomy, self.mammalia, "Life on Earth", "Mammalia")
self.check_object_tag(
object_tag, self.taxonomy, self.mammalia, "Life on Earth", "Mammalia"
)

# Once all tags are resynced, they stay that way
changed = tagging_api.resync_object_tags()
Expand All @@ -101,7 +103,9 @@ def test_resync_object_tags(self):
# ObjectTag value preserved even if linked tag is deleted
self.mammalia.delete()
for object_tag in (missing_links, changed_links, no_changes):
self.check_object_tag(object_tag, self.taxonomy, None, "Life on Earth", "Mammalia")
self.check_object_tag(
object_tag, self.taxonomy, None, "Life on Earth", "Mammalia"
)

# ObjectTag name preserved even if linked taxonomy is deleted
self.taxonomy.delete()
Expand All @@ -121,21 +125,29 @@ def test_resync_object_tags(self):
)

with patch(
'openedx_tagging.core.tagging.models.Taxonomy.validate_object_tag',
"openedx_tagging.core.tagging.models.Taxonomy.validate_object_tag",
side_effect=[False, True, False, True],
):
changed = tagging_api.resync_object_tags(ObjectTag.objects.filter(object_type="alpha"))
changed = tagging_api.resync_object_tags(
ObjectTag.objects.filter(object_type="alpha")
)
assert changed == 2
for object_tag in (missing_links, changed_links):
self.check_object_tag(object_tag, second_taxonomy, new_tag, "Life on Earth", "Mammalia")
self.check_object_tag(
object_tag, second_taxonomy, new_tag, "Life on Earth", "Mammalia"
)

# Ensure the omitted tag was not updated
self.check_object_tag(no_changes, None, None, "Life on Earth", "Mammalia")

# Update that one too (without the patching)
changed = tagging_api.resync_object_tags(ObjectTag.objects.filter(object_type="beta"))
changed = tagging_api.resync_object_tags(
ObjectTag.objects.filter(object_type="beta")
)
assert changed == 1
self.check_object_tag(no_changes, first_taxonomy, None, "Life on Earth", "Mammalia")
self.check_object_tag(
no_changes, first_taxonomy, None, "Life on Earth", "Mammalia"
)

def test_tag_object(self):
self.taxonomy.allow_multiple = True
Expand Down Expand Up @@ -165,11 +177,14 @@ def test_tag_object(self):
)

# Ensure the expected number of tags exist in the database
assert tagging_api.get_object_tags(
taxonomy=self.taxonomy,
object_id="biology101",
object_type="course",
) == object_tags
assert (
tagging_api.get_object_tags(
taxonomy=self.taxonomy,
object_id="biology101",
object_type="course",
)
== object_tags
)
# And the expected number of tags were returned
assert len(object_tags) == len(tag_list)
for index, object_tag in enumerate(object_tags):
Expand Down

0 comments on commit a043b41

Please sign in to comment.