Skip to content
Snippets Groups Projects
Commit be880f89 authored by Martin Burchell's avatar Martin Burchell
Browse files

Renamed Item apply_term() to apply_terms()

parent 15d45df6
No related branches found
No related tags found
2 merge requests!46Tagging frontend,!45Add multiple terms api
......@@ -23,7 +23,7 @@ class Message(DataLayerModel):
terms = models.ManyToManyField(Term, related_name="items")
network_provider = models.CharField(max_length=200, blank=True)
def apply_term(self, term):
def apply_terms(self, term):
# TODO: test this
""" Add or replace value of term.taxonomy for current Item
......
......@@ -117,30 +117,30 @@ def test_last_modified_date_on_other_item_not_updated(
@pytest.mark.django_db
def test_apply_term_replaces_term_for_categories():
def test_apply_terms_replaces_term_for_categories():
item = ItemFactory()
taxonomy = TaxonomyFactory() # Ensure multiplicity = optional
term1 = TermFactory(taxonomy=taxonomy)
term2 = TermFactory(taxonomy=taxonomy)
assert taxonomy.is_optional
item.apply_term(term1)
item.apply_terms(term1)
assert list(item.terms.all()) == [term1]
item.apply_term(term2)
item.apply_terms(term2)
assert list(item.terms.all()) == [term2]
@pytest.mark.django_db
def test_apply_term_adds_term_for_tags():
def test_apply_terms_adds_term_for_tags():
item = ItemFactory()
taxonomy = TaxonomyFactory(multiplicity='multiple')
term1 = TermFactory(taxonomy=taxonomy)
term2 = TermFactory(taxonomy=taxonomy)
assert not taxonomy.is_optional
item.apply_term(term1)
item.apply_terms(term1)
assert list(item.terms.all()) == [term1]
item.apply_term(term2)
item.apply_terms(term2)
assert set(item.terms.all()) == set([term1, term2])
......@@ -86,7 +86,7 @@ class ItemViewSet(viewsets.ModelViewSet, BulkDestroyModelMixin):
data = {'detail': e.message}
return Response(data, status=status.HTTP_400_BAD_REQUEST)
item.apply_term(term)
item.apply_terms(term)
serializer = ItemSerializer(item)
return Response(serializer.data, status=status.HTTP_200_OK)
......@@ -113,7 +113,7 @@ class ItemViewSet(viewsets.ModelViewSet, BulkDestroyModelMixin):
name=term_name,
)
item.apply_term(term)
item.apply_terms(term)
serializer = ItemSerializer(item)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment