-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bug 718698] KB Article votes in KPI dashboard.
* Refactorings to api views for reuse. * Refactored js into a backbone app.
- Loading branch information
Showing
8 changed files
with
304 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,55 @@ | ||
import json | ||
|
||
import mock | ||
from nose.tools import eq_ | ||
import waffle | ||
|
||
from questions.models import Question, Answer, User | ||
from users.models import Profile | ||
|
||
from sumo.helpers import urlparams | ||
from questions.tests import question, answer | ||
from sumo.tests import TestCase, LocalizingClient | ||
from sumo.urlresolvers import reverse | ||
from users.tests import user, add_permission | ||
from users.models import Profile | ||
from wiki.tests import revision, helpful_vote | ||
|
||
|
||
class KpiAPITests(TestCase): | ||
client_class = LocalizingClient | ||
|
||
@mock.patch.object(waffle, 'switch_is_active') | ||
def test_percent(self, switch_is_active): | ||
"""Test user API with all defaults.""" | ||
switch_is_active.return_value = True | ||
u = user() | ||
u.save() | ||
add_permission(u, models.Profile , 'view_dashboard') | ||
import json | ||
|
||
import mock | ||
from nose.tools import eq_ | ||
import waffle | ||
def test_solved(self): | ||
"""Test solved API call.""" | ||
u = user(save=True) | ||
add_permission(u, Profile, 'view_kpi_dashboard') | ||
|
||
from questions.models import Question, Answer, User | ||
a = answer(save=True) | ||
a.question.solution = a | ||
a.question.save() | ||
|
||
from sumo.helpers import urlparams | ||
from sumo.tests import TestCase, LocalizingClient | ||
from sumo.urlresolvers import reverse | ||
from users.tests import user, add_permission | ||
from users.models import Profile | ||
question(save=True) | ||
|
||
class KpiAPITests(TestCase): | ||
client_class = LocalizingClient | ||
url = reverse('api_dispatch_list', | ||
kwargs={'resource_name': 'kpi_solution', | ||
'api_name': 'v1'}) | ||
self.client.login(username=u.username, password='testpass') | ||
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) | ||
|
||
@mock.patch.object(waffle, 'switch_is_active') | ||
def test_percent(self, switch_is_active): | ||
"""Test user API with all defaults.""" | ||
switch_is_active.return_value = True | ||
u = user() | ||
u.save() | ||
def test_vote(self): | ||
"""Test vote API call.""" | ||
u = user(save=True) | ||
add_permission(u, Profile, 'view_kpi_dashboard') | ||
question = Question(title='Test Question', | ||
content='Lorem Ipsum Dolor', | ||
creator_id=u.id) | ||
question.save() | ||
answer = Answer(question=question, creator_id=u.id, | ||
content="Test Answer") | ||
answer.save() | ||
|
||
question.solution = answer | ||
question.save() | ||
r = revision(save=True) | ||
helpful_vote(revision=r, save=True) | ||
helpful_vote(revision=r, save=True) | ||
helpful_vote(revision=r, helpful=True, save=True) | ||
|
||
url = reverse('api_dispatch_list', | ||
kwargs={'resource_name': 'kpi_solution', | ||
kwargs={'resource_name': 'kpi_kbvote', | ||
'api_name': 'v1'}) | ||
self.client.login(username=u.username, password='testpass') | ||
response = self.client.get(url + '?format=json') | ||
eq_(200, response.status_code) | ||
r = json.loads(response.content) | ||
eq_(r['objects'][0]['with_solutions'], 1) | ||
eq_(r['objects'][0]['without_solutions'], 0) | ||
eq_(r['objects'][0]['helpful'], 1) | ||
eq_(r['objects'][0]['votes'], 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.