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

Moved data_layer ItemTermException to taxonomies

parent 74f7a277
No related branches found
No related tags found
2 merge requests!46Tagging frontend,!45Add multiple terms api
class ItemTermException(Exception):
pass
...@@ -2,7 +2,7 @@ from django.db import models ...@@ -2,7 +2,7 @@ from django.db import models
from django.dispatch.dispatcher import receiver from django.dispatch.dispatcher import receiver
from taxonomies.models import Term from taxonomies.models import Term
from exceptions import ItemTermException from taxonomies.exceptions import TermException
class DataLayerModel(models.Model): class DataLayerModel(models.Model):
...@@ -42,12 +42,12 @@ class Message(DataLayerModel): ...@@ -42,12 +42,12 @@ class Message(DataLayerModel):
taxonomy = terms[0].taxonomy taxonomy = terms[0].taxonomy
if not all(t.taxonomy == taxonomy for t in terms): if not all(t.taxonomy == taxonomy for t in terms):
raise ItemTermException("Terms cannot be applied from different taxonomies") raise TermException("Terms cannot be applied from different taxonomies")
if not taxonomy.is_multiple: if not taxonomy.is_multiple:
if len(terms) > 1: if len(terms) > 1:
message = "Taxonomy '%s' does not support multiple terms" % taxonomy message = "Taxonomy '%s' does not support multiple terms" % taxonomy
raise ItemTermException(message) raise TermException(message)
self.delete_all_terms(taxonomy) self.delete_all_terms(taxonomy)
......
...@@ -6,7 +6,7 @@ from django.utils import timezone ...@@ -6,7 +6,7 @@ from django.utils import timezone
from factories import ItemFactory from factories import ItemFactory
from ..models import Item from ..models import Item
from ..exceptions import ItemTermException from taxonomies.exceptions import TermException
from taxonomies.tests.factories import TermFactory, TaxonomyFactory from taxonomies.tests.factories import TermFactory, TaxonomyFactory
...@@ -167,7 +167,7 @@ def test_applying_multiple_terms_raises_exception_if_not_multiple(): ...@@ -167,7 +167,7 @@ def test_applying_multiple_terms_raises_exception_if_not_multiple():
term1 = TermFactory(taxonomy=taxonomy) term1 = TermFactory(taxonomy=taxonomy)
term2 = TermFactory(taxonomy=taxonomy) term2 = TermFactory(taxonomy=taxonomy)
with pytest.raises(ItemTermException) as excinfo: with pytest.raises(TermException) as excinfo:
item.apply_terms((term1, term2)) item.apply_terms((term1, term2))
expected_message = "Taxonomy '%s' does not support multiple terms" % ( expected_message = "Taxonomy '%s' does not support multiple terms" % (
...@@ -185,7 +185,7 @@ def test_applied_terms_must_be_from_same_taxonomy(): ...@@ -185,7 +185,7 @@ def test_applied_terms_must_be_from_same_taxonomy():
term3 = TermFactory(taxonomy=taxonomy1) term3 = TermFactory(taxonomy=taxonomy1)
with pytest.raises(ItemTermException) as excinfo: with pytest.raises(TermException) as excinfo:
item.apply_terms((term1, term2, term3)) item.apply_terms((term1, term2, term3))
expected_message = "Terms cannot be applied from different taxonomies" expected_message = "Terms cannot be applied from different taxonomies"
......
class TermException(Exception):
pass
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