File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
openedx_tagging/core/tagging
tests/openedx_tagging/core/tagging Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 1010Please look at the models.py file for more information about the kinds of data
1111are stored in this app.
1212"""
13- from typing import Generator , List , Type
13+ from typing import Generator , List , Type , Union
1414
1515from django .db .models import QuerySet
1616from 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+
4753def get_taxonomies (enabled = True ) -> QuerySet :
4854 """
4955 Returns a queryset containing the enabled taxonomies, sorted by name.
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments