Source

Repustate Clients / python / test_repustate.py

Full commit
from lxml import etree
import unittest2 as unittest

from client import Repustate

class TestRepustate(unittest.TestCase):

    text = 'iPad'

    url = 'http://tcrn.ch/aav9Ty'

    key = '0c9cf39718d8ce33e5310047617f8020984d8f18'

    def get_accessor(self):
        return Repustate(self.key, 'v2')

    def check_status(self, result):
        expected_type = dict
        status = result.get('status')
        self.assertIsInstance(result, expected_type, 'Invalid result')
        self.assertEqual(status, 'OK')

    def check_call(self, func_name, check_status=True, **kwargs):
        func = getattr(self.get_accessor(), func_name)
        result = func(**kwargs)
        self.assertIsNotNone(result, 'Invalid result')
        if check_status:
            self.check_status(result)

    def test_sentiment_for_text(self):
        self.check_call('sentiment', text=self.text)

    def test_sentiment_for_url(self):
        self.check_call('sentiment', url=self.url)

    def test_bulk_sentiment(self):
        self.check_call('bulk_sentiment', items=['I love candy'])

    def test_adjectives_for_text(self):
        self.check_call('adjectives', text=self.text)

    def test_adjectives_for_url(self):
        self.check_call('adjectives', url=self.url)

    def test_verbs_for_text(self):
        self.check_call('verbs', text=self.text)

    def test_verbs_for_url(self):
        self.check_call('verbs', url=self.url)

    def test_clean_html(self):
        self.check_call('clean_html', url=self.url)

    def test_ngrams_for_text(self):
        self.check_call('ngrams', text=self.text)

    def test_ngrams_for_url(self):
        self.check_call('ngrams', url=self.url)

    def test_date_extraction(self):
        self.check_call('date_extraction', text=self.text)

    def test_powerpoint(self):
        kwargs = dict(
            report_title='Test Report',
            author='Martin Ostrovsky',
            images=['repustate.gif'],
            titles=['A test title'],
            )
        self.check_call('powerpoint', check_status=False, **kwargs)