Skip to content
Snippets Groups Projects
Commit 8d31810e authored by Alice Heaton's avatar Alice Heaton :speech_balloon:
Browse files

Merge remote-tracking branch 'origin/staging' into view_and_edit_page

parents 14ad2242 13e5c08e
Branches
No related tags found
No related merge requests found
......@@ -16,15 +16,21 @@ from ..views import ItemViewSet
@pytest.fixture
def category():
return create_category(name="Ebola Questions").data
response = create_category(name="Test Ebola Questions")
assert status.is_success(response.status_code), response.data
return response.data
def term_for(taxonomy, name):
""" Create, and return a Term in the given taxonomy """
return add_term(
response = add_term(
taxonomy=taxonomy['slug'],
name=name,
).data
)
assert status.is_success(response.status_code), response.data
return response.data
@pytest.fixture
......
......@@ -12,7 +12,10 @@ from ..views import (
TaxonomyViewSet,
TermViewSet,
)
from taxonomies.tests.factories import TermFactory
from taxonomies.tests.factories import (
TaxonomyFactory,
TermFactory,
)
def create_category(name):
......@@ -24,19 +27,23 @@ def create_category(name):
@pytest.mark.django_db
def test_create_a_category():
category = "Test Ebola Questions"
response = create_category('Ebola Questions')
old_count = Taxonomy.objects.count()
assert not Taxonomy.objects.filter(name=category).exists()
response = create_category(category)
assert status.is_success(response.status_code), response.data
assert Taxonomy.objects.count() == 1
[taxonomy] = Taxonomy.objects.all()
assert taxonomy.name == 'Ebola Questions'
new_count = Taxonomy.objects.count()
assert new_count - old_count == 1
assert Taxonomy.objects.filter(name=category).exists()
# TODO: write test for getting taxonomies and terms, so we can re-write all
# these tests using only the API (as Functional tests)
def add_term(**kwargs):
"""
taxonomy: string with taxonomy name
......@@ -50,32 +57,36 @@ def add_term(**kwargs):
@pytest.mark.django_db
def test_add_term_to_taxonomy():
taxonomy = Taxonomy(name='Ebola Questions')
taxonomy.save()
taxonomy = TaxonomyFactory(name='Test Ebola Questions')
response1 = add_term(taxonomy=taxonomy.slug, name='Vaccine')
response2 = add_term(taxonomy=taxonomy.slug, name='Time')
assert status.is_success(response1.status_code), response1.data
assert status.is_success(response2.status_code), response2.data
terms = Term.objects.all()
terms = Term.objects.filter(taxonomy=taxonomy)
assert len(terms) == 2
assert all(term.taxonomy.name == taxonomy.name for term in terms)
@pytest.mark.django_db
def test_terms_have_long_name():
taxonomy = Taxonomy(name='Ebola Questions')
taxonomy.save()
taxonomy = TaxonomyFactory(name="Ebola Questions")
vacc_long_name = "Is there a vaccine?"
add_term(
assert not Term.objects.filter(long_name=vacc_long_name).exists()
response = add_term(
taxonomy=taxonomy.slug,
name="Vaccine",
long_name="Is there a vaccine?"
name="Test Vaccine",
long_name=vacc_long_name
)
[term] = Term.objects.all()
assert term.long_name == "Is there a vaccine?"
assert status.is_success(response.status_code), response.data
assert Term.objects.filter(long_name=vacc_long_name).exists()
@pytest.mark.django_db
......
......@@ -8,9 +8,9 @@ from ..models import (
class TaxonomyFactory(DjangoModelFactory):
class Meta:
model = Taxonomy
django_get_or_create = ('name',)
name = fuzzy.FuzzyText()
......@@ -19,6 +19,7 @@ class TermFactory(DjangoModelFactory):
class Meta:
model = Term
django_get_or_create = ('name',)
name = fuzzy.FuzzyText()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment