Skip to content

Commit

Permalink
chore: Remove is_valid checks from get_object_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuf-musleh committed Aug 14, 2023
1 parent 1992850 commit b9ba062
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
13 changes: 4 additions & 9 deletions openedx_tagging/core/tagging/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,12 @@ def resync_object_tags(object_tags: QuerySet = None) -> int:


def get_object_tags(
object_id: str, taxonomy: Taxonomy = None, valid_only=True
) -> Iterator[ObjectTag]:
object_id: str, taxonomy: Taxonomy = None
) -> QuerySet:
"""
Generates a list of object tags for a given object.
Returns a Queryset of object tags for a given object.
Pass taxonomy to limit the returned object_tags to a specific taxonomy.
Pass valid_only=False when displaying tags to content authors, so they can see invalid tags too.
Invalid tags will (probably) be hidden from learners.
"""
ObjectTagClass = taxonomy.object_tag_class if taxonomy else ObjectTag
tags = (
Expand All @@ -117,9 +114,7 @@ def get_object_tags(
if taxonomy:
tags = tags.filter(taxonomy=taxonomy)

for object_tag in tags:
if not valid_only or object_tag.is_valid():
yield object_tag
return tags


def tag_object(
Expand Down
20 changes: 0 additions & 20 deletions tests/openedx_tagging/core/tagging/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,37 +427,17 @@ def test_get_object_tags(self):
assert list(
tagging_api.get_object_tags(
object_id="abc",
valid_only=False,
)
) == [
alpha,
beta,
]

# No valid tags for this object yet..
assert not list(
tagging_api.get_object_tags(
object_id="abc",
valid_only=True,
)
)
beta.tag = self.mammalia
beta.save()
assert list(
tagging_api.get_object_tags(
object_id="abc",
valid_only=True,
)
) == [
beta,
]

# Fetch all the tags for a given object ID + taxonomy
assert list(
tagging_api.get_object_tags(
object_id="abc",
taxonomy=self.taxonomy,
valid_only=False,
)
) == [
beta,
Expand Down

0 comments on commit b9ba062

Please sign in to comment.