Source

RIL / test_readitlater.py

Full commit
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-

import logging
import unittest

import readitlater
import test_configs as configs

"""Define test configurations in test_configs.py

RIL_APIKEY = '<your api key>'
RIL_USERNAME = '<username>'
RIL_PASSWORD = '<password>'
"""

class TestAPI(unittest.TestCase):
    def setUp(self):
        self.api = readitlater.API(configs.RIL_APIKEY)

    def test_auth(self):
        self.assertRaises(readitlater.AuthError, self.api.auth, 'invalid_user', 'invalid_password')
        self.assertTrue(self.api.auth(configs.RIL_USERNAME, configs.RIL_PASSWORD))

    def test_add(self):
        self.assertTrue(self.api.add(configs.RIL_USERNAME, configs.RIL_PASSWORD, 
            'http://google.com/', 'Google'))

    def test_send_new(self):
        data = [{"url": "http://google.com",
                 "title": "Google",
                 "ref_id": "123456709"},
                {"url": "http://ideashower.com",
                 "title": "The Idea Shower"}]
        self.assertTrue(self.api.send(
            configs.RIL_USERNAME, configs.RIL_PASSWORD, new=data))

    def test_send_read(self):
        data = [{"url": "http://google.com"},
                {"url": "http://ideashower.com"}]
        self.assertTrue(self.api.send(
            configs.RIL_USERNAME, configs.RIL_PASSWORD, read=data))

    def test_send_update_title(self):
        data = [{"url": "http://google.com",
                 "title": "Google"},
                {"url": "http://ideashower.com",
                 "title": "The Idea Shower"}]
        self.assertTrue(self.api.send(
            configs.RIL_USERNAME, configs.RIL_PASSWORD, update_title=data))

    def test_send_update_tags(self):
        data = [{"url": "http://google.com",
                 "tags": "comma,seperated,list"},
                {"url": "http://ideashower.com",
                 "tags": "ideas,developer,nate weiner"}]
        self.assertTrue(self.api.send(
            configs.RIL_USERNAME, configs.RIL_PASSWORD, update_tags=data))


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG, filename='test.log')

    testsuite = unittest.TestLoader().loadTestsFromTestCase(TestAPI)
    unittest.TextTestRunner(verbosity=2).run(testsuite)