From c1916e45b7452fcfae186e752ea509e61e04f1b6 Mon Sep 17 00:00:00 2001
From: Martin Burchell <martinb@aptivate.org>
Date: Wed, 29 Jul 2015 17:15:45 +0100
Subject: [PATCH] Refactored tests to use REST API

In this case for counting taxonomies
---
 .../tests/taxonomy_and_term_create_tests.py    | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/django/website/rest_api/tests/taxonomy_and_term_create_tests.py b/django/website/rest_api/tests/taxonomy_and_term_create_tests.py
index 409adebc..9e5a1bc0 100644
--- a/django/website/rest_api/tests/taxonomy_and_term_create_tests.py
+++ b/django/website/rest_api/tests/taxonomy_and_term_create_tests.py
@@ -25,17 +25,31 @@ def create_category(name):
     return view(request, pk=id)
 
 
+def count_taxonomies():
+    return len(get_taxonomies().data)
+
+
+def get_taxonomies():
+    url = reverse('taxonomy-list')
+    request = APIRequestFactory().get(url)
+    view = TaxonomyViewSet.as_view(actions={'get': 'list'})
+    response = view(request)
+    assert status.is_success(response.status_code), response.data
+
+    return response
+
+
 @pytest.mark.django_db
 def test_create_a_category():
     category = "Test Ebola Questions"
 
-    old_count = Taxonomy.objects.count()
+    old_count = count_taxonomies()
     assert not Taxonomy.objects.filter(name=category).exists()
 
     response = create_category(category)
     assert status.is_success(response.status_code), response.data
 
-    new_count = Taxonomy.objects.count()
+    new_count = count_taxonomies()
     assert new_count - old_count == 1
 
     assert Taxonomy.objects.filter(name=category).exists()
-- 
GitLab