'Test vote API call.'

def test_kb_vote(self):

    r1 = RevisionFactory(document__locale='en-US')
    r2 = RevisionFactory(document__locale='es')
    r3 = RevisionFactory(document__locale='es')
    for r in [r1, r2, r3]:
        HelpfulVoteFactory(revision=r)
        HelpfulVoteFactory(revision=r)
        HelpfulVoteFactory(revision=r, helpful=True)
    firefox_os = ProductFactory(slug='firefox-os')
    firefox = ProductFactory(slug='firefox')
    r1.document.products.add(firefox_os)
    r2.document.products.add(firefox_os)
    r3.document.products.add(firefox)
    r = self._get_api_result('api.kpi.kb-votes')
    eq_(r['objects'][0]['kb_helpful'], 3)
    eq_(r['objects'][0]['kb_votes'], 9)
    r = self._get_api_result('api.kpi.kb-votes', locale='en-US')
    eq_(r['objects'][0]['kb_helpful'], 1)
    eq_(r['objects'][0]['kb_votes'], 3)
    r = self._get_api_result('api.kpi.kb-votes', locale='es')
    eq_(r['objects'][0]['kb_helpful'], 2)
    eq_(r['objects'][0]['kb_votes'], 6)
    r = self._get_api_result('api.kpi.kb-votes', product='firefox-os')
    eq_(r['objects'][0]['kb_helpful'], 2)
    eq_(r['objects'][0]['kb_votes'], 6)
    r = self._get_api_result('api.kpi.kb-votes', product='firefox')
    eq_(r['objects'][0]['kb_helpful'], 1)
    eq_(r['objects'][0]['kb_votes'], 3)
    r = self._get_api_result('api.kpi.kb-votes', product='firefox-os', locale='es')
    eq_(r['objects'][0]['kb_helpful'], 1)
    eq_(r['objects'][0]['kb_votes'], 3)
