Skip to content

Commit 4c34a54

Browse files
committed
feat: adds api.get_taxonomy
for completeness.
1 parent 7ebc97a commit 4c34a54

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

openedx_tagging/core/tagging/api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Please look at the models.py file for more information about the kinds of data
1111
are stored in this app.
1212
"""
13-
from typing import Generator, List, Type
13+
from typing import Generator, List, Type, Union
1414

1515
from django.db.models import QuerySet
1616
from django.utils.translation import gettext_lazy as _
@@ -44,6 +44,12 @@ def create_taxonomy(
4444
return taxonomy
4545

4646

47+
def get_taxonomy(id: int) -> Union[Taxonomy, None]:
48+
"""
49+
Returns a Taxonomy of the appropriate subclass which has the given ID.
50+
"""
51+
return Taxonomy.objects.filter(id=id).first()
52+
4753
def get_taxonomies(enabled=True) -> QuerySet:
4854
"""
4955
Returns a queryset containing the enabled taxonomies, sorted by name.

tests/openedx_tagging/core/tagging/test_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def test_create_taxonomy_bad_object_tag_class(self):
3838
exc.exception
3939
)
4040

41+
def test_get_taxonomy(self):
42+
tax1 = tagging_api.get_taxonomy(1)
43+
assert tax1 == self.taxonomy
44+
no_tax = tagging_api.get_taxonomy(10)
45+
assert no_tax is None
46+
4147
def test_get_taxonomies(self):
4248
tax1 = tagging_api.create_taxonomy("Enabled")
4349
tax2 = tagging_api.create_taxonomy("Disabled", enabled=False)

0 commit comments

Comments
 (0)