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

Added add_term to transport layer

parent dda119ca
No related branches found
No related tags found
No related merge requests found
from factory.django import DjangoModelFactory
from ..models import Taxonomy
from ..models import (
Taxonomy,
Term,
)
class TaxonomyFactory(DjangoModelFactory):
class Meta:
model = Taxonomy
class TermFactory(DjangoModelFactory):
class Meta:
model = Term
......@@ -63,3 +63,21 @@ def bulk_delete(ids):
# for the moment I'm mapping this onto multiple calls to delete()
for id in ids:
delete(id)
def add_term_url(item_id):
return reverse('item-add-term', kwargs={'pk': item_id})
def add_term(item_id, taxonomy_slug, name):
view = ItemViewSet.as_view(actions={'post': 'add_term'})
term = {'taxonomy': taxonomy_slug, 'name': name}
request = request_factory.post(add_term_url(item_id), term)
response = view(request, item_pk=item_id)
if status.is_success(response.status_code):
return response.data
else:
response.data['status_code'] = response.status_code
raise TransportException(response.data)
from __future__ import unicode_literals, absolute_import
import pytest
from data_layer.models import Item
from taxonomies.tests.factories import (
TaxonomyFactory,
TermFactory)
from transport import items
@pytest.mark.django_db
def test_terms_can_be_added_to_item():
item = {'body': "What is the cuse of ebola?"}
response = items.create(item)
item_id = response['id']
# TODO: Replace with Term list() ?
item = Item.objects.get(pk=item_id)
assert item.terms.count() == 0
ebola_questions = TaxonomyFactory(name="Ebola Questions")
term = TermFactory(name="Cause", taxonomy=ebola_questions)
items.add_term(item_id, ebola_questions.slug, term.name)
term = TermFactory(name="Question", taxonomy=ebola_questions)
items.add_term(item_id, ebola_questions.slug, term.name)
assert item.terms.count() == 2
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