Skip to content

Commit

Permalink
Using unittest for tests, fixed some errors, added gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
aarose committed Jul 28, 2015
1 parent c495df2 commit 940b604
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
13 changes: 8 additions & 5 deletions togglwrapper/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
BASE_URL = 'https://www.toggl.com/api'
API_VERSION = 'v8'
API_URL = '{base}/{version}'.format(base=BASE_URL, version=API_VERSION)
API_TOKEN = ''

auth = HTTPBasicAuth(API_TOKEN, 'api_token')


class TogglObject(object):
Expand All @@ -24,7 +21,7 @@ class User(TogglObject):

def get(self, related_data=False, since=None):
""" Get the user associated with the current API token. """
response = requests.get(self.full_uri, auth=auth)
response = requests.get(self.full_uri, auth=self.client.auth)
return response.json()

def update(self, data):
Expand All @@ -37,5 +34,11 @@ def __init__(self, api_token, base_url=BASE_URL, version=API_VERSION):
# self.api_token = api_token
self.api_url = '{base}/{version}'.format(base=base_url,
version=version)
self.auth = HTTPBasicAuth(self.api_token, 'api_token')
self.auth = HTTPBasicAuth(api_token, 'api_token')
self.user = User(self)

def test_connection(self):
""" Test for a successful connection. """
test_url = '{base}{uri}'.format(base=self.api_url, uri='test')
response = requests.get(test_url, auth=self.client.auth)
return response.json()
21 changes: 18 additions & 3 deletions togglwrapper/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
from . import api
import unittest

if __name__ == "__main__":
test_client = api.Client()
import api


class TestAPIMethods(unittest.TestCase):
def test_client(self):
""" Should successfully establish the client. """
api_token = 'correct_token'
self.assertTrue(api.Client(api_token))

def test_client_wrong_token(self):
""" Should raise exception when wrong API token is provided. """
wrong_api_token = 'wrong token'
self.assertRaises(Exception, api.Client, wrong_api_token)


if __name__ == '__main__':
unittest.main()

0 comments on commit 940b604

Please sign in to comment.