Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better(?) tests

  • Loading branch information...
commit 2d86057d7200b303ad265c1b2d5701d364d57d84 1 parent 206125d
@rlr authored
Showing with 56 additions and 6 deletions.
  1. +56 −6 apps/kpi/tests/test_api.py
View
62 apps/kpi/tests/test_api.py
@@ -2,6 +2,8 @@
from datetime import date, datetime
import json
+from django.core.cache import cache
+
from nose.tools import eq_
from customercare.tests import reply
@@ -32,7 +34,19 @@ def test_solved(self):
question(save=True)
- # Add some questions by inactive user. These should't be counted.
+ url = reverse('api_dispatch_list',
+ kwargs={'resource_name': 'kpi_solution',
+ 'api_name': 'v1'})
+ response = self.client.get(url + '?format=json')
+ eq_(200, response.status_code)
+ r = json.loads(response.content)
+ eq_(r['objects'][0]['solved'], 1)
+ eq_(r['objects'][0]['questions'], 2)
+
+ def test_solved_inactive_user(self):
+ """Verify questions from inactive users aren't counted."""
+ # Create two questions for an inactive user.
+ # They shouldn't show up in the count.
u = user(is_active=False, save=True)
question(creator=u, save=True)
question(creator=u, save=True)
@@ -43,7 +57,19 @@ def test_solved(self):
response = self.client.get(url + '?format=json')
eq_(200, response.status_code)
r = json.loads(response.content)
- eq_(r['objects'][0]['solved'], 1)
+ eq_(len(r['objects']), 0)
+
+ # Activate the user, now the questions should count.
+ u.is_active = True
+ u.save()
+ cache.clear() # We need to clear the cache for new results.
+
+ url = reverse('api_dispatch_list',
+ kwargs={'resource_name': 'kpi_solution',
+ 'api_name': 'v1'})
+ response = self.client.get(url + '?format=json')
+ eq_(200, response.status_code)
+ r = json.loads(response.content)
eq_(r['objects'][0]['questions'], 2)
def test_vote(self):
@@ -69,8 +95,8 @@ def test_vote(self):
eq_(r['objects'][0]['ans_helpful'], 2)
eq_(r['objects'][0]['ans_votes'], 3)
- def test_fast_response(self):
- """Test fast response API call."""
+ def test_responded(self):
+ """Test responded API call."""
a = answer(save=True)
a.question.solution = a
a.question.save()
@@ -78,7 +104,19 @@ def test_fast_response(self):
a = answer(save=True)
a.question.save()
- # Add some questions by inactive user. These should't be counted.
+ url = reverse('api_dispatch_list',
+ kwargs={'resource_name': 'kpi_fast_response',
+ 'api_name': 'v1'})
+ response = self.client.get(url + '?format=json')
+ eq_(200, response.status_code)
+ r = json.loads(response.content)
+ eq_(r['objects'][0]['responded'], 2)
+ eq_(r['objects'][0]['questions'], 2)
+
+ def test_responded_inactive_user(self):
+ """Verify questions from inactive users aren't counted."""
+ # Create two questions for an inactive user.
+ # They shouldn't show up in the count.
u = user(is_active=False, save=True)
question(creator=u, save=True)
question(creator=u, save=True)
@@ -89,7 +127,19 @@ def test_fast_response(self):
response = self.client.get(url + '?format=json')
eq_(200, response.status_code)
r = json.loads(response.content)
- eq_(r['objects'][0]['responded'], 2)
+ eq_(len(r['objects']), 0)
+
+ # Activate the user, now the questions should count.
+ u.is_active = True
+ u.save()
+ cache.clear() # We need to clear the cache for new results.
+
+ url = reverse('api_dispatch_list',
+ kwargs={'resource_name': 'kpi_fast_response',
+ 'api_name': 'v1'})
+ response = self.client.get(url + '?format=json')
+ eq_(200, response.status_code)
+ r = json.loads(response.content)
eq_(r['objects'][0]['questions'], 2)
def test_active_kb_contributors(self):
Please sign in to comment.
Something went wrong with that request. Please try again.