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

Added term item count to transport layer

parent 69fa20c8
Branches
No related tags found
No related merge requests found
......@@ -3,7 +3,6 @@ from django.core.urlresolvers import reverse
from rest_api.views import TaxonomyViewSet
from rest_framework.test import APIRequestFactory
actions = {'get': 'list'}
request_factory = APIRequestFactory()
......@@ -11,7 +10,11 @@ def list_url():
return reverse('taxonomy-list')
def get_view():
def itemcount_url(slug):
return reverse('taxonomy-itemcount', kwargs={'slug': slug})
def get_view(actions):
return TaxonomyViewSet.as_view(actions)
......@@ -22,6 +25,12 @@ def list(**kwargs):
to filter the Taxonomies.
"""
view = get_view()
view = get_view(actions={'get': 'list'})
request = request_factory.get(list_url(), kwargs)
return view(request).data
def term_itemcount(slug):
view = get_view(actions={'get': 'itemcount'})
request = request_factory.get(itemcount_url(slug))
return view(request, slug=slug).data
from __future__ import unicode_literals, absolute_import
import pytest
from taxonomies.tests.factories import (
TaxonomyFactory,
TermFactory,
)
import transport
@pytest.fixture
def item_data():
item = {'body': "What is the cuse of ebola?"}
return transport.items.create(item)
@pytest.fixture
def questions_category():
# TODO: Replace with transport call when we have one
return TaxonomyFactory(name="Ebola Questions")
@pytest.fixture
def questions_term(questions_category):
# TODO: Replace with transport call when we have one
return TermFactory(taxonomy=questions_category)
@pytest.mark.django_db
def test_term_itemcount_returns_terms_and_counts(item_data,
questions_category,
questions_term):
# This is tested more comprehensively in the API tests
transport.items.add_term(item_data['id'],
questions_category.slug,
questions_term.name)
terms = transport.taxonomies.term_itemcount(slug=questions_category.slug)
counts = {term['name']: term['count'] for term in terms}
assert counts[questions_term.name] == 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment