From b3ea18f3ff2ef16e0a8d5e6e1c6259df00785ffe Mon Sep 17 00:00:00 2001 From: Volodymyr Hotsyk Date: Sat, 28 May 2011 12:13:47 +0300 Subject: [PATCH 01/19] 0.4.1 public release --- changelog.rst | 12 ++++- full_list.rst | 13 ----- odesk/__init__.py | 19 ++----- odesk/auth.py | 2 +- odesk/exceptions.py | 2 +- odesk/http.py | 2 +- odesk/namespaces.py | 2 +- odesk/oauth.py | 5 +- odesk/routers/finance.py | 44 ---------------- odesk/routers/finreport.py | 2 +- odesk/routers/hr.py | 20 +------- odesk/routers/mc.py | 2 +- odesk/routers/oconomy.py | 3 +- odesk/routers/provider.py | 52 ++++--------------- odesk/routers/task.py | 2 +- odesk/routers/team.py | 17 +----- odesk/routers/ticket.py | 79 ---------------------------- odesk/routers/timereport.py | 2 +- odesk/routers/url.py | 38 -------------- odesk/tests.py | 100 ------------------------------------ 20 files changed, 38 insertions(+), 380 deletions(-) delete mode 100644 odesk/routers/finance.py delete mode 100644 odesk/routers/ticket.py delete mode 100644 odesk/routers/url.py diff --git a/changelog.rst b/changelog.rst index d2a9d5d..23bad86 100644 --- a/changelog.rst +++ b/changelog.rst @@ -7,6 +7,15 @@ Changelog .. +.. _0.4.1: + +Version 0.4.1 +----------------- +*May 2011* + +* Cleaned release from not implemented yet or not accessable API methods + + .. _0.4: Version 0.4 @@ -14,7 +23,6 @@ Version 0.4 *May 2011* * *Incompatibility with previous release* Changed name of the otask router to the task -* *Incompatibility with previous release* Chaged name of the oticket router to the ticket ?? * *Incompatibility with previous release* Changed name of the time_report router to the timereport * *Incompatibility with previous release* Changed name of the finreports router to the finreport * *Incompatibility with previous release* "from odesk import *" now import only: "get_version", "Client", "utils" @@ -22,7 +30,7 @@ Version 0.4 * All helper classes moved to own modules * Added logging inside exceptions * Added possiblity to switch off unused routers inside client class -* Added oconomy, finance routers +* Added oconomy routers * Added oDesk oAuth support .. _0.2: diff --git a/full_list.rst b/full_list.rst index 7a0c52a..25142f5 100644 --- a/full_list.rst +++ b/full_list.rst @@ -21,7 +21,6 @@ Package structure * routers * __init__.py - * finance.py * finreport.py * hr.py * mc.py @@ -29,9 +28,7 @@ Package structure * provider.py * task.py * team.py - * ticket.py * timereport.py - * url.py * tests.py @@ -191,8 +188,6 @@ oauth.py routers/ --------------------- -* Finances(Namespace) - routers/finance.py - * Finreports(GdsNamespace) - routers/finreport.py * get_provider_billings(self, provider_id, query) @@ -214,14 +209,11 @@ routers/ * get_companies(self) * get_company(self, company_id) * get_company_teams(self, company_id) - * get_company_tasks(self, company_id) - Not implemented in API * get_company_users(self, company_id, active=True) * get_teams(self) * get_team(self, team_id, include_users=False) - * get_team_tasks(self, team_id) - Not implemented in API * get_team_users(self, team_id, active=True) * post_team_adjustment(self, team_id, engagement_id, amount, comments, notes) - * get_tasks(self) - Not implemented in API * get_user_role(self, user_id=None, team_id=None, sub_teams=False) * get_jobs(self) * get_job(self, job_id) @@ -284,8 +276,6 @@ routers/ * get_snapshots(self, team_id, online='now') * get_workdiaries(self, team_id, username, date=None) -* Ticket(Namespace) - routers/ticket.py - * Timereport(GdsNamespace) - routers/timereport.py * get_provider_report(self, provider_id, query, hours=False) @@ -293,9 +283,6 @@ routers/ * get_agency_report(self, company_id, agency_id, query, hours=False) * query is the odesk.Query object -* Url(Namespace) - routers/url.py - - .. _utils: utils.py diff --git a/odesk/__init__.py b/odesk/__init__.py index f7ecf55..e3b6130 100644 --- a/odesk/__init__.py +++ b/odesk/__init__.py @@ -1,9 +1,9 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ -VERSION = (0, 4, 0, 'final', 5) +VERSION = (0, 4, 1, 'final', 5) def get_version(): @@ -146,9 +146,9 @@ class Client(BaseClient): def __init__(self, public_key, secret_key, api_token=None, oauth_access_token=None, oauth_access_token_secret=None, - format='json', auth='simple', finance=True, finreport=True, + format='json', auth='simple', finreport=True, hr=True, mc=True, oconomy=True, provider=True, - task=True, team=True, ticket=True, timereport=True, url=True): + task=True, team=True, timereport=True): self.public_key = public_key self.secret_key = secret_key @@ -164,10 +164,6 @@ def __init__(self, public_key, secret_key, api_token=None, self.oauth_access_token_secret = oauth_access_token_secret #Namespaces - if finance: - from odesk.routers.finance import Finance - self.finance = Finance(self) - if finreport: from odesk.routers.finreport import Finreports self.finreport = Finreports(self) @@ -197,17 +193,10 @@ def __init__(self, public_key, secret_key, api_token=None, from odesk.routers.team import Team self.team = Team(self) - if ticket: - from odesk.routers.ticket import Ticket - self.ticket = Ticket(self) - if timereport: from odesk.routers.timereport import TimeReport self.timereport = TimeReport(self) - if url: - from odesk.routers.url import Url - self.url = Url(self) #Shortcuts for HTTP methods def get(self, url, data={}): diff --git a/odesk/auth.py b/odesk/auth.py index f98ce3f..1b5fd94 100644 --- a/odesk/auth.py +++ b/odesk/auth.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ diff --git a/odesk/exceptions.py b/odesk/exceptions.py index ff8f472..5b030d5 100644 --- a/odesk/exceptions.py +++ b/odesk/exceptions.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ diff --git a/odesk/http.py b/odesk/http.py index bde90da..57f098e 100644 --- a/odesk/http.py +++ b/odesk/http.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ diff --git a/odesk/namespaces.py b/odesk/namespaces.py index 7cb4331..bc519f4 100644 --- a/odesk/namespaces.py +++ b/odesk/namespaces.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ diff --git a/odesk/oauth.py b/odesk/oauth.py index 0b6a64d..a2891cb 100644 --- a/odesk/oauth.py +++ b/odesk/oauth.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ @@ -15,6 +15,9 @@ class OAuth(Namespace): + """ + oAuth support in oDesk is in beta currently. + """ api_url = 'auth/' version = 1 diff --git a/odesk/routers/finance.py b/odesk/routers/finance.py deleted file mode 100644 index 8121230..0000000 --- a/odesk/routers/finance.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -Python bindings to odesk API -python-odesk version 0.4 -(C) 2010-2011 oDesk -""" - -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - - -from odesk.namespaces import Namespace - - -class Finance(Namespace): - api_url = 'finance/' - version = 1 - - def get_withdrawal_methods(self): - """ - Retrieve a list of withdrawl available - """ - return self.get('withdrawals') - - def post_withdrawal(self, method_ref, amount): - """ - Post a withdrawl request - - Parameters - method_ref Withdrawl method reference - Amount Amount of withdrawl - """ - url = 'withdrawals/%s' % method_ref - data = {'amount': amount} - return self.post(url, data) diff --git a/odesk/routers/finreport.py b/odesk/routers/finreport.py index e43a78e..87e055f 100644 --- a/odesk/routers/finreport.py +++ b/odesk/routers/finreport.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ diff --git a/odesk/routers/hr.py b/odesk/routers/hr.py index e0af937..23f04db 100644 --- a/odesk/routers/hr.py +++ b/odesk/routers/hr.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ @@ -75,12 +75,6 @@ def get_company_teams(self, company_referece): result = self.get(url) return result['teams'] - def get_company_tasks(self, company_referece): - """ - API doesn't support this call yet - """ - raise APINotImplementedException("API doesn't support this call yet") - def get_company_users(self, company_referece, active=True): """ Retrieve a list of all users within the referenced company. @@ -122,12 +116,6 @@ def get_team(self, team_reference, include_users=False): #TODO: check how included users returned return result['team'] - def get_team_tasks(self, team_reference): - """ - API doesn't support this call yet - """ - raise APINotImplementedException("API doesn't support this call yet") - def get_team_users(self, team_reference, active=True): """ get_team_users(team_reference, active=True) @@ -160,12 +148,6 @@ def post_team_adjustment(self, team_reference, engagement_reference, result = self.post(url, data) return result['adjustment'] - '''task api''' - - def get_tasks(self): - "API doesn't support this call yet" - raise APINotImplementedException("API doesn't support this call yet") - '''userrole api''' def get_user_role(self, user_reference=None, team_reference=None, diff --git a/odesk/routers/mc.py b/odesk/routers/mc.py index 28c5474..8885ae6 100644 --- a/odesk/routers/mc.py +++ b/odesk/routers/mc.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ diff --git a/odesk/routers/oconomy.py b/odesk/routers/oconomy.py index a58bfda..045836c 100644 --- a/odesk/routers/oconomy.py +++ b/odesk/routers/oconomy.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ @@ -57,7 +57,6 @@ def get_summary(self, year=None, month=None): else: url = 'summary' result = self.get(url) - print url return result diff --git a/odesk/routers/provider.py b/odesk/routers/provider.py index 39b9a1d..6e640de 100644 --- a/odesk/routers/provider.py +++ b/odesk/routers/provider.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ @@ -106,11 +106,11 @@ def get_jobs(self, data=None, page_offset=0, page_size=20, order_by=None): return result['jobs'] def _get_resume_info(self, provider_ciphertext, info_type): - ''' + """ info_type can be one of (otherexp|skills|tests|certificates|employments|\ educations|projects) - ''' + """ strinfo = str(info_type) if strinfo not in self.resume_info_result_keys: raise ValueError('invalid info_type %s' % strinfo) @@ -121,11 +121,11 @@ def _get_resume_info(self, provider_ciphertext, info_type): def _add_resume_info_item(self, provider_ciphertext, info_type,\ item_data): - ''' + """ info_type can be one of (otherexp|skills|tests|certificates|employments|\ educations|projects - ''' + """ strinfo = str(info_type) if strinfo not in self.resume_info_result_keys: raise ValueError('invalid info_type %s' % strinfo) @@ -134,10 +134,10 @@ def _add_resume_info_item(self, provider_ciphertext, info_type,\ def _update_resume_info_item(self, provider_ciphertext,\ resource_id, info_type, item_data): - ''' + """ info_type can be one of (otherexp|skills|tests|certificates|\ employments|educations|projects - ''' + """ strinfo = str(info_type) if strinfo not in self.resume_info_result_keys: raise ValueError('invalid info_type %s' % strinfo) @@ -152,10 +152,10 @@ def _update_resume_info_item(self, provider_ciphertext,\ def _delete_resume_info_item(self, provider_ciphertext,\ resource_id, info_type): - ''' + """ info_type can be one of (otherexp|skills|tests|certificates|\ employments|educations|projects - ''' + """ strinfo = str(info_type) if strinfo not in self.resume_info_result_keys: raise ValueError('invalid info_type %s' % strinfo) @@ -178,40 +178,6 @@ def get_skills(self, provider_ciphertext): """ return self._get_resume_info(provider_ciphertext, 'skills') - def add_skill(self, provider_ciphertext, data): - """ - Add provider skills info - - Parameters - provider_ciphertext Provider cipher text (key) - data dict containing details of skill to add - """ - return self._add_resume_info_item(provider_ciphertext,\ - 'skills', data) - - def update_skill(self, provider_ciphertext, skill_id, data): - """ - Update provider skills info - - Parameters - provider_ciphertext Provider cipher text (key) - skill_id Resource id of the referenced skill - data dict containing details of skill to delete - """ - return self._update_resume_info_item(provider_ciphertext,\ - skill_id, 'skills', data) - - def delete_skill(self, provider_ciphertext, skill_id): - """ - Delete provider skills info - - Parameters - provider_ciphertext Provider cipher text (key) - skill_id Resource id of the referenced skill - """ - return self._delete_resume_info_item(provider_ciphertext,\ - skill_id, 'skills') - def get_quickinfo(self, provider_ciphertext): """ Retrieve provider 'quick info' diff --git a/odesk/routers/task.py b/odesk/routers/task.py index 1c45446..70e7cfd 100644 --- a/odesk/routers/task.py +++ b/odesk/routers/task.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ diff --git a/odesk/routers/team.py b/odesk/routers/team.py index c255a32..a31e115 100644 --- a/odesk/routers/team.py +++ b/odesk/routers/team.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ @@ -135,21 +135,6 @@ def get_workdiaries(self, team_id, username, date=None): #not sure we need to return user return result['snapshots']['user'], snapshots - def get_stream(self, team_id, user_id=None,\ - from_ts=None): - """ - get_stream(team_id, user_id=None, from_ts=None) - """ - url = 'streams/%s' % (team_id) - if user_id: - url += '/%s' % (user_id) - if from_ts: - data = {'from_ts': from_ts} - else: - data = {} - result = self.get(url, data) - return result['streams']['snapshot'] - def get_teamrooms_2(self): """ Retrieve all teamrooms accessible to the authenticated user diff --git a/odesk/routers/ticket.py b/odesk/routers/ticket.py deleted file mode 100644 index 9254b05..0000000 --- a/odesk/routers/ticket.py +++ /dev/null @@ -1,79 +0,0 @@ -""" -Python bindings to odesk API -python-odesk version 0.4 -(C) 2010-2011 oDesk -""" - -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - - -from odesk.namespaces import Namespace - - -class Ticket(Namespace): - api_url = 'tickets/' - version = 1 - - def get_topics(self): - """ - Retrieve ticket topics - """ - url = 'topics' - result = self.get(url) - return result['topics'] - - def get_ticket(self, ticket_key): - """ - Retrieve details of a specific ticket - - Parameters - ticket_key Ticket key - """ - url = 'tickets/%s' % str(ticket_key) - result = self.get(url) - return result['ticket'] - - def post_new_ticket(self, message, topic_id='', topic_api_ref='', - email='', name=''): - """ - Post a new ticket - - Parameters - message - topic_id - topic_api_ref - email - name - """ - url = 'tickets' - data = {'message': message, - 'topic_id': topic_id, - 'topic_api_ref': topic_api_ref, - 'email': email, - } - result = self.post(url, data) - return result # TBD - - def post_reply_ticket(self, ticket_key, message): - """ - Post reply to a specific ticket - - Parameters - ticket_key Ticket key - message - """ - url = 'tickets/%s' % str(ticket_key) - data = {'message': message} - result = self.post(url, data) - return result # TBD diff --git a/odesk/routers/timereport.py b/odesk/routers/timereport.py index ec69482..05c30c5 100644 --- a/odesk/routers/timereport.py +++ b/odesk/routers/timereport.py @@ -1,6 +1,6 @@ """ Python bindings to odesk API -python-odesk version 0.4 +python-odesk version 0.4.1 (C) 2010-2011 oDesk """ diff --git a/odesk/routers/url.py b/odesk/routers/url.py deleted file mode 100644 index 2547c95..0000000 --- a/odesk/routers/url.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -Python bindings to odesk API -python-odesk version 0.4 -(C) 2010-2011 oDesk -""" - -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - - -from odesk.namespaces import Namespace - - -class Url(Namespace): - api_url = 'shorturl/' - version = 1 - - def get_shorten(self, long_url): - url = 'shorten' - data = {'url': long_url} - result = self.get(url, data=data) - return result['short_url'] - - def get_expand(self, short_url): - url = 'expand' - data = {'url': short_url} - result = self.get(url, data=data) - return result['long_url'] diff --git a/odesk/tests.py b/odesk/tests.py index bbd1069..3928200 100644 --- a/odesk/tests.py +++ b/odesk/tests.py @@ -450,52 +450,6 @@ def test_team(): assert te.get_workdiaries(1, 1, 1) == (teamrooms_dict['snapshots']['user'], \ [teamrooms_dict['snapshots']['snapshot']]), te.get_workdiaries(1, 1, 1) - -stream_dict = {'streams': {'snapshot': [{u'uid': u'test', - u'portrait_50_img': u'http://www.odesk.com/att/~~test', - u'account_status': u'', - u'billing_status': u'billed.active', - u'screenshot_img_thmb': u'http://team.odesk.com/team/images.cache/test.jpg', - u'screenshot_url': u'https://team.odesk.com/team/scripts/image.jpg', - u'timezone': u'', u'digest': u'0', u'user_id': u'test', - u'company_id': u'test:test', u'report_url': u'http://team.url', - u'profile_url': u'http://www.odesk.com/users/~~test', - u'status': u'NORMAL', - u'report24_img': u'http://chart.apis.google.com/chart.png', - u'screenshot_img': u'http://team.odesk.com/team/images/test:test/test/2010/01/01/test.jpg', - u'memo': u'Bug 1: Test:Test', - u'time': u'test', u'cellts': u'test', - u'screenshot_img_med': u'http://team.odesk.com/team/scripts/image.jpg', - u'user': {u'first_name': u'Test', u'last_name': u'Test', - u'uid': u'test', u'timezone_offset': u'10000', u'creation_time': u'', - u'mail': u'test@odesk.com', u'timezone': u'Europe/Athens', - u'messenger_id': u'', u'messenger_type': u''}, u'computer_name': u'laptop', - u'active_window_title': u'2010-01-01 - Google Chrome', - u'task': {u'code': u'484', u'id': u'{type=bugzilla,cny=test:test,code=1}', - u'description': u'Bug 1: Test: Test'}, - u'keyboard_events_count': u'1', u'mouse_events_count': u'1', u'activity': u'1', - u'client_version': u'Linux/2.0.0', u'screenshot_img_lrg': u'http://test.com', - u'portrait_img': u'http://www.test.com'}]}} - - -def return_stream_json(): - return json.dumps(stream_dict) - - -def patched_urlopen_stream(request, *args, **kwargs): - request.read = return_stream_json - return request - - -@patch('urllib2.urlopen', patched_urlopen_stream) -def test_stream(): - te = Team(get_client()) - - #test get_stream - assert te.get_stream('test', 'test') == stream_dict['streams']['snapshot'], \ - te.get_stream('test', 'test') - - userroles = {u'userrole': [{u'parent_team__reference': u'1', u'user__id': u'testuser', u'team__id': u'test:t', @@ -683,21 +637,6 @@ def test_get_hrv2_company_users(): assert hr.get_company_users(1, False) == hr_dict['users'], \ hr.get_company_users(1, False) - -@patch('urllib2.urlopen', patched_urlopen_hr) -def test_get_hrv2_company_tasks(): - hr = get_client().hr - #test get_company_tasks - try: - assert hr.get_company_tasks(1) == hr_dict['tasks'], \ - hr.get_company_tasks(1) - except APINotImplementedException, e: - pass - except Exception, e: - print e - assert 0, "APINotImplementedException not raised" - - @patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_teams(): hr = get_client().hr @@ -717,36 +656,6 @@ def test_get_hrv2_team_users(): hr.get_team_users(1, False) -@patch('urllib2.urlopen', patched_urlopen_hr) -def test_get_hrv2_team_tasks(): - hr = get_client().hr - #test get_team_tasks - try: - assert hr.get_team_tasks(1) == hr_dict['tasks'], hr.get_team_tasks(1) - except APINotImplementedException, e: - pass - except: - assert 0, "APINotImplementedException not raised" - - -@patch('urllib2.urlopen', patched_urlopen_hr) -def test_get_hrv2_userroles(): - hr = get_client().hr - #test get_user_role - assert hr.get_user_role(user_reference=1) == hr_dict['userroles'], \ - hr.get_user_role(user_reference=1) - assert hr.get_user_role(team_reference=1) == hr_dict['userroles'], \ - hr.get_user_role(team_reference=1) - assert hr.get_user_role() == hr_dict['userroles'], hr.get_user_role() - - try: - assert hr.get_tasks() == hr_dict['tasks'], hr.get_tasks() - except APINotImplementedException, e: - pass - except: - assert 0, "APINotImplementedException not raised" - - @patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_jobs(): hr = get_client().hr @@ -872,15 +781,6 @@ def test_provider(): assert pr.get_skills(1) == provider_dict['skills'], \ pr.get_skills(1) - assert pr.add_skill(1, {'skill': 'skill'}) == provider_dict, \ - pr.add_skill(1, {'skill': 'skill'}) - - assert pr.update_skill(1, 1, {'skill': 'skill'}) == provider_dict, \ - pr.update_skill(1, 1, {'skill': 'skill'}) - - assert pr.delete_skill(1, 1) == provider_dict, \ - pr.delete_skill(1, 1) - assert pr.get_quickinfo(1) == provider_dict['quick_info'], \ pr.get_quickinfo(1) From 44a2cfe8f73535f4e9878ad62dbbac1d317d3a15 Mon Sep 17 00:00:00 2001 From: Ilia Vihtinsky Date: Wed, 6 Jun 2012 15:34:10 +0400 Subject: [PATCH 02/19] beta version --- README | 11 +- README.md | 11 +- changelog.rst | 74 ---- getting_started.rst | 11 +- how_to.rst | 2 +- index.rst | 11 +- odesk/__init__.py | 60 +-- odesk/auth.py | 20 +- odesk/exceptions.py | 18 +- odesk/http.py | 27 +- odesk/namespaces.py | 29 +- odesk/oauth.py | 20 +- odesk/routers/__init__.py | 6 +- odesk/routers/finreport.py | 21 +- odesk/routers/hr.py | 21 +- odesk/routers/mc.py | 33 +- odesk/routers/oconomy.py | 19 +- odesk/routers/provider.py | 37 +- odesk/routers/task.py | 32 +- odesk/routers/team.py | 20 +- odesk/routers/timereport.py | 21 +- odesk/tests.py | 714 ++++++++++++++++++------------------ setup.py | 2 +- 23 files changed, 482 insertions(+), 738 deletions(-) delete mode 100644 changelog.rst diff --git a/README b/README index 2879a2b..9e73dc0 100644 --- a/README +++ b/README @@ -1,11 +1,10 @@ Copyright (c) 2010-2011, oDesk http://www.odesk.com All rights reserved. -Python bindings to oDesk API +Python3 bindings to oDesk API -* Git repo: http://github.com/odesk/python-odesk -* Issues: http://github.com/odesk/python-odesk/issues -* Documentation: http://odesk.github.com/python-odesk/ -* Mailing list: python-odesk@googlegroups.com -* Facebook group: http://www.facebook.com/group.php?gid=136364403050710 +* Git repo: http://github.com/odesk/python-odesk3 +* Issues: http://github.com/odesk/python-odesk3/issues +* Documentation: http://odesk.github.com/python-odesk3/ + diff --git a/README.md b/README.md index 66a0fe3..d449b85 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ Copyright (c) 2010-2011, oDesk http://www.odesk.com All rights reserved. -Python bindings to oDesk API +Python3 bindings to oDesk API ======================================= -* [Git repo](http://github.com/odesk/python-odesk) -* [Issues](http://github.com/odesk/python-odesk/issues) -* [Documentation](http://odesk.github.com/python-odesk/) -* [Mailing list](http://groups.google.com/group/python-odesk) -* [Facebook group](http://www.facebook.com/group.php?gid=136364403050710) +* [Git repo](http://github.com/odesk/python-odesk3) +* [Issues](http://github.com/odesk/python-odesk3/issues) +* [Documentation](http://odesk.github.com/python-odesk3/) + diff --git a/changelog.rst b/changelog.rst deleted file mode 100644 index 23bad86..0000000 --- a/changelog.rst +++ /dev/null @@ -1,74 +0,0 @@ -.. _changelog: - - -*************** -Changelog -*************** - -.. - -.. _0.4.1: - -Version 0.4.1 ------------------ -*May 2011* - -* Cleaned release from not implemented yet or not accessable API methods - - -.. _0.4: - -Version 0.4 ------------------ -*May 2011* - -* *Incompatibility with previous release* Changed name of the otask router to the task -* *Incompatibility with previous release* Changed name of the time_report router to the timereport -* *Incompatibility with previous release* Changed name of the finreports router to the finreport -* *Incompatibility with previous release* "from odesk import *" now import only: "get_version", "Client", "utils" -* All routers moved from the __init__.py to the own files in the routers dir. -* All helper classes moved to own modules -* Added logging inside exceptions -* Added possiblity to switch off unused routers inside client class -* Added oconomy routers -* Added oDesk oAuth support - -.. _0.2: - -Version 0.2 ------------------ -*October 2010* - -* All helpers classes moved to the utils.py, added Table helper class -* *Incompatibility with previous release* Changed names of the methods' params to reflect real oDesk params - e.g. company_reference vs company name - -.. _0.1.2: - -Version 0.1.2 ------------------ -*29 September 2010* - -Bug fix release - -* Fixed check_token method -* Fixed KeyError on empty workdiaries - -.. _0.1.1: - -Version 0.1.1 ------------------ -*15 July 2010* - -Bug fix release - -* Fixed HR2.get_user_role(user_id=None, team_id=None, sub_teams=False) method to correctly get user roles when both user reference and team reference were submitted - previously only one of them was used in the request -* Documentation fixes - -.. _0.1: - -Version 0.1 ------------------ -*08 July 2010* - -First public release - diff --git a/getting_started.rst b/getting_started.rst index 35562f2..1c1f8b2 100644 --- a/getting_started.rst +++ b/getting_started.rst @@ -10,7 +10,7 @@ Getting started Requirements ----------------- -You need to install oauth2 to run the python-odesk, and mock and nosetests if you plan to develop python-odesk and/or run library's tests. +You need to install oauth2 to run the python-odesk3, and mock and nosetests if you plan to develop python-odesk and/or run library's tests. Mock:: @@ -34,17 +34,10 @@ To install:: python setup.py install -Or via easy_install:: - - easy_install python-odesk - -Or via pip:: - - pip install python-odesk Also, you can retrieve fresh version of python-odesk from GitHub:: - git clone git://github.com/odesk/python-odesk.git + git clone git://github.com/odesk/python-odesk3.git .. _settings: diff --git a/how_to.rst b/how_to.rst index 46f584f..9965e2b 100644 --- a/how_to.rst +++ b/how_to.rst @@ -13,7 +13,7 @@ Authenticate http://developers.odesk.com/Authentication -To authenticate your web application with the python-odesk, use next code:: +To authenticate your web application with the python-odesk3, use next code:: client = odesk.Client('your public key', 'your secret key') #redirect your user to the client.auth.auth_url() diff --git a/index.rst b/index.rst index 20c1e80..b7f0af6 100644 --- a/index.rst +++ b/index.rst @@ -1,7 +1,7 @@ .. sampledoc documentation master file ****************************************** -Python bindings to oDesk API +Python3 bindings to oDesk API ****************************************** .. toctree:: @@ -19,8 +19,7 @@ Python bindings to oDesk API Urls ********************* -* Git repo: http://github.com/odesk/python-odesk -* Issues: http://github.com/odesk/python-odesk/issues -* Documentation: http://odesk.github.com/python-odesk/ -* Mailing list: http://groups.google.com/group/python-odesk (python-odesk@googlegroups.com) -* Facebook group: http://www.facebook.com/group.php?gid=136364403050710 +* Git repo: http://github.com/odesk/python-odesk3 +* Issues: http://github.com/odesk/python-odesk3/issues +* Documentation: http://odesk.github.com/python-odesk3/ + diff --git a/odesk/__init__.py b/odesk/__init__.py index e3b6130..b3f3aa1 100644 --- a/odesk/__init__.py +++ b/odesk/__init__.py @@ -1,9 +1,9 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -VERSION = (0, 4, 1, 'final', 5) +VERSION = (0, 1, 0, 'beta', 1) def get_version(): @@ -20,39 +20,20 @@ def get_version(): return version -import cookielib -from datetime import date + import hashlib import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json +import urllib.request, urllib.parse, urllib.error +import json - -from odesk.auth import * -from odesk.exceptions import * -from odesk.http import * -from odesk.namespaces import * -from odesk.utils import * +from odesk.auth import Auth +from odesk.oauth import OAuth +from odesk.http import HttpRequest, raise_http_error __all__ = ["get_version", "Client", "utils"] -def _utf8_str(obj): - try: - return unicode(obj).encode("utf8") - except UnicodeDecodeError, e: - # input could be an utf8 encoded - obj.decode("utf8") # check if it is a valid utf8 string - return obj - - def signed_urlencode(secret, query={}): """ Converts a mapping object to signed url query @@ -65,16 +46,15 @@ def signed_urlencode(secret, query={}): message = secret for key in sorted(query.keys()): try: - message += _utf8_str(key) + _utf8_str(query[_utf8_str(key)]) - except Exception, e: + message += str(key) + str(query[key]) + except Exception as e: logging.debug("[python-odesk] Error while trying to sign key: %s and query %s" % (key, query[key])) raise e - #query = query.copy() _query = {} - _query['api_sig'] = hashlib.md5(message).hexdigest() - for k, v in query.iteritems(): - _query[_utf8_str(k)] = _utf8_str(v) - return urllib.urlencode(_query) + _query['api_sig'] = hashlib.md5(message.encode('utf-8')).hexdigest() + for k, v in query.items(): + _query[k] = str(v) + return urllib.parse.urlencode(_query) class BaseClient(object): @@ -97,7 +77,6 @@ def urlencode(self, data={}): return signed_urlencode(self.secret_key, data) def urlopen(self, url, data={}, method='GET'): - from odesk.oauth import OAuth data = data.copy() #FIXME: Http method hack. Should be removed once oDesk supports true @@ -121,7 +100,7 @@ def urlopen(self, url, data={}, method='GET'): request = HttpRequest(url=url, data=None, method=method) else: request = HttpRequest(url=url, data=query, method=method) - return urllib2.urlopen(request) + return urllib.request.urlopen(request) def read(self, url, data={}, method='GET', format='json'): """ @@ -131,7 +110,7 @@ def read(self, url, data={}, method='GET', format='json'): url += '.' + format try: response = self.urlopen(url, data, method) - except urllib2.HTTPError, e: + except urllib.error.HTTPError as e: raise_http_error(e) if format == 'json': @@ -158,7 +137,6 @@ def __init__(self, public_key, secret_key, api_token=None, if auth == 'simple': self.auth = Auth(self) elif auth == 'oauth': - from odesk.oauth import OAuth self.auth = OAuth(self) self.oauth_access_token = oauth_access_token self.oauth_access_token_secret = oauth_access_token_secret @@ -173,7 +151,7 @@ def __init__(self, public_key, secret_key, api_token=None, self.hr = HR(self) if mc: - from odesk.routers.mc import * + from odesk.routers.mc import MC self.mc = MC(self) if oconomy: diff --git a/odesk/auth.py b/odesk/auth.py index 1b5fd94..2482b64 100644 --- a/odesk/auth.py +++ b/odesk/auth.py @@ -1,23 +1,9 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - - from odesk.namespaces import Namespace diff --git a/odesk/exceptions.py b/odesk/exceptions.py index 5b030d5..183d211 100644 --- a/odesk/exceptions.py +++ b/odesk/exceptions.py @@ -1,32 +1,32 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ import logging -import urllib2 +import urllib.request, urllib.error, urllib.parse class BaseException(Exception): def __init__(self, *args, **kwargs): - logging.debug("[python-odesk]:" + unicode(s) for s in args) + logging.debug("[python-odesk]:" + str(s) for s in args) super(BaseException, self).__init__() -class HTTP400BadRequestError(urllib2.HTTPError, BaseException): +class HTTP400BadRequestError(urllib.error.HTTPError, BaseException): pass -class HTTP401UnauthorizedError(urllib2.HTTPError, BaseException): +class HTTP401UnauthorizedError(urllib.error.HTTPError, BaseException): pass -class HTTP403ForbiddenError(urllib2.HTTPError, BaseException): +class HTTP403ForbiddenError(urllib.error.HTTPError, BaseException): pass -class HTTP404NotFoundError(urllib2.HTTPError, BaseException): +class HTTP404NotFoundError(urllib.error.HTTPError, BaseException): pass diff --git a/odesk/http.py b/odesk/http.py index 57f098e..09d7dbd 100644 --- a/odesk/http.py +++ b/odesk/http.py @@ -1,24 +1,13 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 +import urllib.request - -try: - import json -except ImportError: - import simplejson as json - -from odesk.exceptions import * -from odesk.utils import * +from odesk.exceptions import (HTTP400BadRequestError, HTTP401UnauthorizedError, + HTTP403ForbiddenError, HTTP404NotFoundError) def raise_http_error(e): @@ -39,7 +28,7 @@ def raise_http_error(e): raise e -class HttpRequest(urllib2.Request): +class HttpRequest(urllib.request.Request): """ A hack around Request class that allows to specify HTTP method explicitly """ @@ -47,7 +36,7 @@ class HttpRequest(urllib2.Request): def __init__(self, *args, **kwargs): #Request is an old-style class, so can't use `super` method = kwargs.pop('method', 'GET') - urllib2.Request.__init__(self, *args, **kwargs) + urllib.request.Request.__init__(self, *args, **kwargs) self.method = method def get_method(self): diff --git a/odesk/namespaces.py b/odesk/namespaces.py index bc519f4..1b9cac5 100644 --- a/odesk/namespaces.py +++ b/odesk/namespaces.py @@ -1,25 +1,14 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 +import urllib.request, urllib.error +import json +from odesk.http import raise_http_error, HttpRequest -try: - import json -except ImportError: - import simplejson as json - - -from odesk.http import * -from odesk.utils import * class Namespace(object): @@ -63,7 +52,7 @@ def urlopen(self, url, data={}, method='GET'): if method == 'GET': url += '?' + query request = HttpRequest(url=url, data=None, method=method) - return urllib2.urlopen(request) + return urllib.request.urlopen(request) return None def read(self, url, data={}, method='GET'): @@ -72,7 +61,7 @@ def read(self, url, data={}, method='GET'): """ try: response = self.urlopen(url, data, method) - except urllib2.HTTPError, e: + except urllib.error.HTTPError as e: raise_http_error(e) result = json.loads(response.read()) @@ -92,5 +81,5 @@ def urlopen(self, url, data={}, method='GET'): if method == 'GET': request = HttpRequest(url=url, data=data.copy(), method=method) - return urllib2.urlopen(request) + return urllib.request.urlopen(request) return None diff --git a/odesk/oauth.py b/odesk/oauth.py index a2891cb..321dd26 100644 --- a/odesk/oauth.py +++ b/odesk/oauth.py @@ -1,17 +1,15 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ import time -import urlparse -import urllib +import urllib.parse import oauth2 as oauth from odesk.namespaces import Namespace -from odesk.http import HttpRequest class OAuth(Namespace): @@ -55,10 +53,12 @@ def get_request_token(self): Returns request token and request token secret """ client = oauth.Client(self.get_oauth_consumer()) + #import pdb + #pdb.set_trace() response, content = client.request(self.request_token_url, 'POST') if response.get('status') != '200': raise Exception("Invalid request token response: %s." % content) - request_token = dict(urlparse.parse_qsl(content)) + request_token = dict(urllib.parse.parse_qsl(content)) self.request_token = request_token.get('oauth_token') self.request_token_secret = request_token.get('oauth_token_secret') return self.request_token, self.request_token_secret @@ -70,10 +70,10 @@ def get_authorize_url(self, callback_url=None): oauth_token = getattr(self, 'request_token', None) or\ self.get_request_token()[0] if callback_url: - params = urllib.urlencode({'oauth_token': oauth_token,\ + params = urllib.parse.urlencode({'oauth_token': oauth_token,\ 'oauth_callback': callback_url}) else: - params = urllib.urlencode({'oauth_token': oauth_token}) + params = urllib.parse.urlencode({'oauth_token': oauth_token}) return '%s?%s' % (self.authorize_url, params) def get_access_token(self, verifier): @@ -91,7 +91,7 @@ def get_access_token(self, verifier): response, content = client.request(self.access_token_url, 'POST') if response.get('status') != '200': raise Exception("Invalid access token response: %s." % content) - access_token = dict(urlparse.parse_qsl(content)) + access_token = dict(urllib.parse.parse_qsl(content)) self.access_token = access_token.get('oauth_token') self.access_token_secret = access_token.get('oauth_token_secret') return self.access_token, self.access_token_secret diff --git a/odesk/routers/__init__.py b/odesk/routers/__init__.py index 3851dd2..d1e126f 100644 --- a/odesk/routers/__init__.py +++ b/odesk/routers/__init__.py @@ -1,5 +1,5 @@ """ -Python bindings to odesk API -python-odesk version 0.4 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ diff --git a/odesk/routers/finreport.py b/odesk/routers/finreport.py index 87e055f..7a44928 100644 --- a/odesk/routers/finreport.py +++ b/odesk/routers/finreport.py @@ -1,25 +1,10 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - - from odesk.namespaces import GdsNamespace -from odesk.utils import * class Finreports(GdsNamespace): diff --git a/odesk/routers/hr.py b/odesk/routers/hr.py index 23f04db..685a624 100644 --- a/odesk/routers/hr.py +++ b/odesk/routers/hr.py @@ -1,25 +1,10 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - -from odesk.exceptions import APINotImplementedException from odesk.namespaces import Namespace -from odesk.utils import * class HR(Namespace): diff --git a/odesk/routers/mc.py b/odesk/routers/mc.py index 8885ae6..d17a3a5 100644 --- a/odesk/routers/mc.py +++ b/odesk/routers/mc.py @@ -1,23 +1,11 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 +import urllib.parse - -try: - import json -except ImportError: - import simplejson as json - -from odesk.exceptions import * from odesk.namespaces import Namespace @@ -86,8 +74,8 @@ def get_thread_content(self, username, thread_id, paging_offset=0, result = self.get(url, data=data) return result["thread"] - def _generate_many_threads_url(self, url, threads_ids): - return ';'.join(urllib.quote(str(i)) for i in threads_ids) + def _generate_many_threads_url(self, threads_ids): + return ';'.join(urllib.parse.quote(str(i)) for i in threads_ids) def put_threads_read_unread(self, username, thread_ids, read=True): """ @@ -103,8 +91,7 @@ def put_threads_read_unread(self, username, thread_ids, read=True): data = {'read': 'true'} else: data = {'read': 'false'} - result = self.put(self._generate_many_threads_url(url,\ - thread_ids), data=data) + result = self.put(self._generate_many_threads_url(thread_ids), data=data) return result def put_threads_read(self, username, thread_ids): @@ -144,8 +131,7 @@ def put_threads_starred_or_unstarred(self, username, thread_ids, else: data = {'starred': 'false'} - result = self.put(self._generate_many_threads_url(url,\ - thread_ids), data=data) + result = self.put(self._generate_many_threads_url(thread_ids), data=data) return result def put_threads_starred(self, username, thread_ids): @@ -187,8 +173,7 @@ def put_threads_deleted_or_undeleted(self, username, thread_ids, else: data = {'deleted': 'false'} - result = self.put(self._generate_many_threads_url(url, thread_ids), - data=data) + result = self.put(self._generate_many_threads_url(thread_ids), data=data) return result def put_threads_deleted(self, username, thread_ids): diff --git a/odesk/routers/oconomy.py b/odesk/routers/oconomy.py index 045836c..bcd5732 100644 --- a/odesk/routers/oconomy.py +++ b/odesk/routers/oconomy.py @@ -1,25 +1,12 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib from datetime import date -import hashlib -import logging -import urllib -import urllib2 - -try: - import json -except ImportError: - import simplejson as json - -from odesk.exceptions import * from odesk.namespaces import GdsNamespace, NonauthGdsNamespace -from odesk.utils import * class OConomy(GdsNamespace): diff --git a/odesk/routers/provider.py b/odesk/routers/provider.py index 6e640de..1e85ea5 100644 --- a/odesk/routers/provider.py +++ b/odesk/routers/provider.py @@ -1,25 +1,10 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - - from odesk.namespaces import Namespace -from odesk.utils import * class Provider(Namespace): @@ -119,7 +104,7 @@ def _get_resume_info(self, provider_ciphertext, info_type): result_key = self.resume_info_result_keys[strinfo] return result[result_key] - def _add_resume_info_item(self, provider_ciphertext, info_type,\ + def _add_resume_info_item(self, provider_ciphertext, info_type, \ item_data): """ info_type can be one of @@ -132,7 +117,7 @@ def _add_resume_info_item(self, provider_ciphertext, info_type,\ url = 'providers/%s/%s' % (str(provider_ciphertext), strinfo) return self.post(url, item_data) - def _update_resume_info_item(self, provider_ciphertext,\ + def _update_resume_info_item(self, provider_ciphertext, \ resource_id, info_type, item_data): """ info_type can be one of (otherexp|skills|tests|certificates|\ @@ -143,14 +128,14 @@ def _update_resume_info_item(self, provider_ciphertext,\ raise ValueError('invalid info_type %s' % strinfo) if resource_id is not None: - url = 'providers/%s/%s/%s' % (str(provider_ciphertext),\ + url = 'providers/%s/%s/%s' % (str(provider_ciphertext), \ str(resource_id), strinfo) else: - url = 'providers/%s/%s' % (str(provider_ciphertext),\ + url = 'providers/%s/%s' % (str(provider_ciphertext), \ strinfo) return self.post(url, item_data) - def _delete_resume_info_item(self, provider_ciphertext,\ + def _delete_resume_info_item(self, provider_ciphertext, \ resource_id, info_type): """ info_type can be one of (otherexp|skills|tests|certificates|\ @@ -161,10 +146,10 @@ def _delete_resume_info_item(self, provider_ciphertext,\ raise ValueError('invalid info_type %s' % strinfo) if resource_id is not None: - url = 'providers/%s/%s/%s' % (str(provider_ciphertext),\ + url = 'providers/%s/%s/%s' % (str(provider_ciphertext), \ str(resource_id), strinfo) else: - url = 'providers/%s/%s' % (str(provider_ciphertext),\ + url = 'providers/%s/%s' % (str(provider_ciphertext), \ strinfo) return self.delete(url) @@ -195,7 +180,7 @@ def update_quickinfo(self, provider_ciphertext, data): provider_ciphertext Provider cipher text (key) data A dict containing updated 'quick info' """ - return self._update_resume_info_item(provider_ciphertext, None,\ + return self._update_resume_info_item(provider_ciphertext, None, \ 'quickinfo', data) def get_affiliates(self, affiliate_key): diff --git a/odesk/routers/task.py b/odesk/routers/task.py index 70e7cfd..a02458c 100644 --- a/odesk/routers/task.py +++ b/odesk/routers/task.py @@ -1,22 +1,10 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - +import urllib.parse from odesk.namespaces import Namespace @@ -94,7 +82,7 @@ def get_team_tasks_full(self, company_id, team_id): company_id Company ID team_id Team ID """ - url = 'tasks/companies/%s/teams/%s/tasks/full_list' %\ + url = 'tasks/companies/%s/teams/%s/tasks/full_list' % \ (str(company_id), str(team_id)) result = self.get(url) return result["tasks"] or [] @@ -111,13 +99,13 @@ def get_user_tasks_full(self, company_id, team_id, user_id): team_id Team ID user_id User ID """ - url = 'tasks/companies/%s/teams/%s/users/%s/tasks/full_list' %\ + url = 'tasks/companies/%s/teams/%s/users/%s/tasks/full_list' % \ (str(company_id), str(team_id), str(user_id)) result = self.get(url) return result["tasks"] or [] def _generate_many_tasks_url(self, task_codes): - return ';'.join(urllib.quote(str(c)) for c in task_codes) + return ';'.join(urllib.parse.quote(str(c)) for c in task_codes) def get_company_specific_tasks(self, company_id, task_codes): """ @@ -141,7 +129,7 @@ def get_team_specific_tasks(self, company_id, team_id, task_codes): team_id Team ID task_codes Task codes (must be a list, even of 1 item) """ - url = 'tasks/companies/%s/teams/%s/tasks/%s' %\ + url = 'tasks/companies/%s/teams/%s/tasks/%s' % \ (str(company_id), str(team_id), self._generate_many_tasks_url(task_codes)) result = self.get(url) @@ -158,7 +146,7 @@ def get_user_specific_tasks(self, company_id, team_id, user_id, user_id User ID task_codes Task codes (must be a list, even of 1 item) """ - url = 'tasks/companies/%s/teams/%s/users/%s/tasks/%s' %\ + url = 'tasks/companies/%s/teams/%s/users/%s/tasks/%s' % \ (str(company_id), str(team_id), str(user_id), self._generate_many_tasks_url(task_codes)) result = self.get(url) @@ -317,7 +305,7 @@ def delete_user_task(self, company_id, team_id, user_id, task_codes): user_id User ID task_codes Task codes (must be a list, even of 1 item) """ - url = 'tasks/companies/%s/teams/%s/users/%s/tasks/%s' %\ + url = 'tasks/companies/%s/teams/%s/users/%s/tasks/%s' % \ (str(company_id), str(team_id), str(user_id), self. _generate_many_tasks_url(task_codes)) return self.delete(url, {}) diff --git a/odesk/routers/team.py b/odesk/routers/team.py index a31e115..dfd955f 100644 --- a/odesk/routers/team.py +++ b/odesk/routers/team.py @@ -1,23 +1,9 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - - from odesk.namespaces import Namespace diff --git a/odesk/routers/timereport.py b/odesk/routers/timereport.py index 05c30c5..72a3a2b 100644 --- a/odesk/routers/timereport.py +++ b/odesk/routers/timereport.py @@ -1,25 +1,10 @@ """ -Python bindings to odesk API -python-odesk version 0.4.1 -(C) 2010-2011 oDesk +Python3 bindings to odesk API +python-odesk3 version 0.1 +(C) 2012 oDesk """ -import cookielib -from datetime import date -import hashlib -import logging -import urllib -import urllib2 - - -try: - import json -except ImportError: - import simplejson as json - - from odesk.namespaces import GdsNamespace -from odesk.utils import * class TimeReport(GdsNamespace): diff --git a/odesk/tests.py b/odesk/tests.py index 3928200..97f08f1 100644 --- a/odesk/tests.py +++ b/odesk/tests.py @@ -12,7 +12,7 @@ from odesk.routers.team import Team from mock import Mock, patch -import urllib2 +import urllib.request, urllib.error, urllib.parse try: import json @@ -32,7 +32,7 @@ def test_signed_urlencode(): 'result': 'api_sig=ac0e1b26f401dd4a5ccbaf7f4ea86b2f&foo=bar&spam=42'}, } - for key in secret_data.keys(): + for key in list(secret_data.keys()): result = signed_urlencode(key, secret_data[key]['query']) assert secret_data[key]['result'] == result, \ " %s returned and should be %s" % (result, \ @@ -60,21 +60,21 @@ def test_base_client(): encodedkey = 'api_sig=8a0da3cab1dbf7451f38fb5f5aec129c&api_key=public&foo=bar&spam=42' assert urlresult == encodedkey, urlresult -sample_json_dict = {u'glossary': - {u'GlossDiv': - {u'GlossList': - {u'GlossEntry': - {u'GlossDef': - {u'GlossSeeAlso': [u'GML', u'XML'], - u'para': u'A meta-markup language'}, - u'GlossSee': u'markup', - u'Acronym': u'SGML', - u'GlossTerm': u'Standard Generalized Markup Language', - u'Abbrev': u'ISO 8879:1986', - u'SortAs': u'SGML', - u'ID': u'SGML'}}, - u'title': u'S'}, - u'title': u'example glossary'}} +sample_json_dict = {'glossary': + {'GlossDiv': + {'GlossList': + {'GlossEntry': + {'GlossDef': + {'GlossSeeAlso': ['GML', 'XML'], + 'para': 'A meta-markup language'}, + 'GlossSee': 'markup', + 'Acronym': 'SGML', + 'GlossTerm': 'Standard Generalized Markup Language', + 'Abbrev': 'ISO 8879:1986', + 'SortAs': 'SGML', + 'ID': 'SGML'}}, + 'title': 'S'}, + 'title': 'example glossary'}} def return_sample_json(): @@ -86,7 +86,7 @@ def patched_urlopen(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen) +@patch('urllib.request.urlopen', patched_urlopen) def test_base_client_urlopen(): public_key = 'public' secret_key = 'secret' @@ -136,7 +136,7 @@ def test_base_client_urlopen(): def patched_urlopen_error(request, code=400, *args, **kwargs): - raise urllib2.HTTPError(url=request.get_full_url(), + raise urllib.error.HTTPError(url=request.get_full_url(), code=code, msg=str(code), hdrs='', fp=None) @@ -160,32 +160,32 @@ def patched_urlopen_500(request, *args, **kwargs): return patched_urlopen_error(request, 500, *args, **kwargs) -@patch('urllib2.urlopen', patched_urlopen_400) +@patch('urllib.request.urlopen', patched_urlopen_400) def base_client_read_400(bc, url): return bc.read(url) -@patch('urllib2.urlopen', patched_urlopen_401) +@patch('urllib.request.urlopen', patched_urlopen_401) def base_client_read_401(bc, url): return bc.read(url) -@patch('urllib2.urlopen', patched_urlopen_403) +@patch('urllib.request.urlopen', patched_urlopen_403) def base_client_read_403(bc, url): return bc.read(url) -@patch('urllib2.urlopen', patched_urlopen_404) +@patch('urllib.request.urlopen', patched_urlopen_404) def base_client_read_404(bc, url): return bc.read(url) -@patch('urllib2.urlopen', patched_urlopen_500) +@patch('urllib.request.urlopen', patched_urlopen_500) def base_client_read_500(bc, url): return bc.read(url) -@patch('urllib2.urlopen', patched_urlopen) +@patch('urllib.request.urlopen', patched_urlopen) def test_base_client_read(): """ test cases: @@ -206,7 +206,7 @@ class NotJsonException(Exception): try: bc.read(url=test_url, format='yaml') raise NotJsonException() - except NotJsonException, e: + except NotJsonException as e: assert 0, "BaseClient.read() doesn't produce error on yaml format" except: pass @@ -218,44 +218,44 @@ class NotJsonException(Exception): #test get, 400 error try: result = base_client_read_400(bc=bc, url=test_url) - except HTTP400BadRequestError, e: + except HTTP400BadRequestError as e: pass - except Exception, e: + except Exception as e: assert 0, "Incorrect exception raised for 400 code: " + str(e) #test get, 401 error try: result = base_client_read_401(bc=bc, url=test_url) - except HTTP401UnauthorizedError, e: + except HTTP401UnauthorizedError as e: pass - except Exception, e: + except Exception as e: assert 0, "Incorrect exception raised for 401 code: " + str(e) #test get, 403 error try: result = base_client_read_403(bc=bc, url=test_url) - except HTTP403ForbiddenError, e: + except HTTP403ForbiddenError as e: pass - except Exception, e: + except Exception as e: assert 0, "Incorrect exception raised for 403 code: " + str(e) #test get, 404 error try: result = base_client_read_404(bc=bc, url=test_url) - except HTTP404NotFoundError, e: + except HTTP404NotFoundError as e: pass - except Exception, e: + except Exception as e: assert 0, "Incorrect exception raised for 404 code: " + str(e) #test get, 500 error try: result = base_client_read_500(bc=bc, url=test_url) - except urllib2.HTTPError, e: + except urllib.error.HTTPError as e: if e.code == 500: pass else: assert 0, "Incorrect exception raised for 500 code: " + str(e) - except Exception, e: + except Exception as e: assert 0, "Incorrect exception raised for 500 code: " + str(e) @@ -266,7 +266,7 @@ def get_client(): return Client(public_key, secret_key, api_token) -@patch('urllib2.urlopen', patched_urlopen) +@patch('urllib.request.urlopen', patched_urlopen) def test_client(): c = get_client() test_url = "http://test.url" @@ -284,7 +284,7 @@ def test_client(): assert result == sample_json_dict, result -@patch('urllib2.urlopen', patched_urlopen) +@patch('urllib.request.urlopen', patched_urlopen) def test_namespace(): ns = Namespace(get_client()) test_url = "http://test.url" @@ -337,7 +337,7 @@ def patched_urlopen_frob(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_frob) +@patch('urllib.request.urlopen', patched_urlopen_frob) def test_auth_get_frob(): #test get_frob au = setup_auth() @@ -356,7 +356,7 @@ def patched_urlopen_token(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_token) +@patch('urllib.request.urlopen', patched_urlopen_token) def test_auth_get_token(): #test get_frob au = setup_auth() @@ -365,7 +365,7 @@ def test_auth_get_token(): assert auth_user == token_dict['auth_user'], auth_user -@patch('urllib2.urlopen', patched_urlopen_token) +@patch('urllib.request.urlopen', patched_urlopen_token) def test_check_token_true(): #check if ok au = setup_auth() @@ -377,14 +377,14 @@ def test_check_token_true(): assert "Not Raised" -@patch('urllib2.urlopen', patched_urlopen_token) +@patch('urllib.request.urlopen', patched_urlopen_token) def test_revoke_token_true(): #check if ok au = setup_auth() assert au.revoke_token(), au.revoke_token() -@patch('urllib2.urlopen', patched_urlopen_403) +@patch('urllib.request.urlopen', patched_urlopen_403) def test_check_token_false(): #check if denied au = setup_auth() @@ -398,14 +398,14 @@ def test_check_token_false(): teamrooms_dict = {'teamrooms': {'teamroom': - {u'team_ref': u'1', - u'name': u'oDesk', - u'recno': u'1', - u'parent_team_ref': u'1', - u'company_name': u'oDesk', - u'company_recno': u'1', - u'teamroom_api': u'/api/team/v1/teamrooms/odesk:some.json', - u'id': u'odesk:some'}}, + {'team_ref': '1', + 'name': 'oDesk', + 'recno': '1', + 'parent_team_ref': '1', + 'company_name': 'oDesk', + 'company_recno': '1', + 'teamroom_api': '/api/team/v1/teamrooms/odesk:some.json', + 'id': 'odesk:some'}}, 'teamroom': {'snapshot': 'test snapshot'}, 'snapshots': {'user': 'test', 'snapshot': 'test'}, 'snapshot': {'status': 'private'} @@ -421,7 +421,7 @@ def patched_urlopen_teamrooms(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_teamrooms) +@patch('urllib.request.urlopen', patched_urlopen_teamrooms) def test_team(): te = Team(get_client()) @@ -450,149 +450,149 @@ def test_team(): assert te.get_workdiaries(1, 1, 1) == (teamrooms_dict['snapshots']['user'], \ [teamrooms_dict['snapshots']['snapshot']]), te.get_workdiaries(1, 1, 1) -userroles = {u'userrole': - [{u'parent_team__reference': u'1', - u'user__id': u'testuser', u'team__id': u'test:t', - u'reference': u'1', u'team__name': u'te', - u'company__reference': u'1', - u'user__reference': u'1', - u'user__first_name': u'Test', - u'user__last_name': u'Development', - u'parent_team__id': u'testdev', - u'team__reference': u'1', u'role': u'manager', - u'affiliation_status': u'none', u'engagement__reference': u'', - u'parent_team__name': u'TestDev', u'has_team_room_access': u'1', - u'company__name': u'Test Dev', - u'permissions': - {u'permission': [u'manage_employment', u'manage_recruiting']}}]} - -engagement = {u'status': u'active', - u'buyer_team__reference': u'1', u'provider__reference': u'2', - u'job__title': u'development', u'roles': {u'role': u'buyer'}, - u'reference': u'1', u'engagement_end_date': u'', - u'fixed_price_upfront_payment': u'0', - u'fixed_pay_amount_agreed': u'1.00', - u'provider__id': u'test_provider', - u'buyer_team__id': u'testteam:aa', - u'engagement_job_type': u'fixed-price', - u'job__reference': u'1', u'provider_team__reference': u'', - u'engagement_title': u'Developer', - u'fixed_charge_amount_agreed': u'0.01', - u'created_time': u'0000', u'provider_team__id': u'', - u'offer__reference': u'', - u'engagement_start_date': u'000', u'description': u''} - -engagements = {u'lister': - {u'total_items': u'10', u'query': u'', - u'paging': {u'count': u'10', u'offset': u'0'}, u'sort': u''}, - u'engagement': [engagement, engagement], +userroles = {'userrole': + [{'parent_team__reference': '1', + 'user__id': 'testuser', 'team__id': 'test:t', + 'reference': '1', 'team__name': 'te', + 'company__reference': '1', + 'user__reference': '1', + 'user__first_name': 'Test', + 'user__last_name': 'Development', + 'parent_team__id': 'testdev', + 'team__reference': '1', 'role': 'manager', + 'affiliation_status': 'none', 'engagement__reference': '', + 'parent_team__name': 'TestDev', 'has_team_room_access': '1', + 'company__name': 'Test Dev', + 'permissions': + {'permission': ['manage_employment', 'manage_recruiting']}}]} + +engagement = {'status': 'active', + 'buyer_team__reference': '1', 'provider__reference': '2', + 'job__title': 'development', 'roles': {'role': 'buyer'}, + 'reference': '1', 'engagement_end_date': '', + 'fixed_price_upfront_payment': '0', + 'fixed_pay_amount_agreed': '1.00', + 'provider__id': 'test_provider', + 'buyer_team__id': 'testteam:aa', + 'engagement_job_type': 'fixed-price', + 'job__reference': '1', 'provider_team__reference': '', + 'engagement_title': 'Developer', + 'fixed_charge_amount_agreed': '0.01', + 'created_time': '0000', 'provider_team__id': '', + 'offer__reference': '', + 'engagement_start_date': '000', 'description': ''} + +engagements = {'lister': + {'total_items': '10', 'query': '', + 'paging': {'count': '10', 'offset': '0'}, 'sort': ''}, + 'engagement': [engagement, engagement], } -offer = {u'provider__reference': u'1', - u'signed_by_buyer_user': u'', - u'reference': u'1', u'job__description': u'python', - u'buyer_company__name': u'Python community', - u'engagement_title': u'developer', u'created_time': u'000', - u'buyer_company__reference': u'2', u'buyer_team__id': u'testteam:aa', - u'interview_status': u'in_process', u'buyer_team__reference': u'1', - u'signed_time_buyer': u'', u'has_buyer_signed': u'', - u'signed_time_provider': u'', u'created_by': u'testuser', - u'job__reference': u'2', u'engagement_start_date': u'00000', - u'fixed_charge_amount_agreed': u'0.01', u'provider_team__id': u'', - u'status': u'', u'signed_by_provider_user': u'', - u'engagement_job_type': u'fixed-price', u'description': u'', - u'provider_team__name': u'', u'fixed_pay_amount_agreed': u'0.01', - u'candidacy_status': u'active', u'has_provider_signed': u'', - u'message_from_provider': u'', u'my_role': u'buyer', - u'key': u'~~0001', u'message_from_buyer': u'', - u'buyer_team__name': u'Python community 2', - u'engagement_end_date': u'', u'fixed_price_upfront_payment': u'0', - u'created_type': u'buyer', u'provider_team__reference': u'', - u'job__title': u'translation', u'expiration_date': u'', - u'engagement__reference': u''} - -offers = {u'lister': - {u'total_items': u'10', u'query': u'', u'paging': - {u'count': u'10', u'offset': u'0'}, u'sort': u''}, - u'offer': [offer, offer]} - -job = {u'subcategory': u'Development', u'reference': u'1', - u'buyer_company__name': u'Python community', - u'job_type': u'fixed-price', u'created_time': u'000', - u'created_by': u'test', u'duration': u'', - u'last_candidacy_access_time': u'', - u'category': u'Web', - u'buyer_team__reference': u'169108', u'title': u'translation', - u'buyer_company__reference': u'1', u'num_active_candidates': u'0', - u'buyer_team__name': u'Python community 2', u'start_date': u'000', - u'status': u'filled', u'num_new_candidates': u'0', - u'description': u'test', u'end_date': u'000', - u'public_url': u'http://www.odesk.com/jobs/~~0001', - u'visibility': u'invite-only', u'buyer_team__id': u'testteam:aa', - u'num_candidates': u'1', u'budget': u'1000', u'cancelled_date': u'', - u'filled_date': u'0000'} +offer = {'provider__reference': '1', + 'signed_by_buyer_user': '', + 'reference': '1', 'job__description': 'python', + 'buyer_company__name': 'Python community', + 'engagement_title': 'developer', 'created_time': '000', + 'buyer_company__reference': '2', 'buyer_team__id': 'testteam:aa', + 'interview_status': 'in_process', 'buyer_team__reference': '1', + 'signed_time_buyer': '', 'has_buyer_signed': '', + 'signed_time_provider': '', 'created_by': 'testuser', + 'job__reference': '2', 'engagement_start_date': '00000', + 'fixed_charge_amount_agreed': '0.01', 'provider_team__id': '', + 'status': '', 'signed_by_provider_user': '', + 'engagement_job_type': 'fixed-price', 'description': '', + 'provider_team__name': '', 'fixed_pay_amount_agreed': '0.01', + 'candidacy_status': 'active', 'has_provider_signed': '', + 'message_from_provider': '', 'my_role': 'buyer', + 'key': '~~0001', 'message_from_buyer': '', + 'buyer_team__name': 'Python community 2', + 'engagement_end_date': '', 'fixed_price_upfront_payment': '0', + 'created_type': 'buyer', 'provider_team__reference': '', + 'job__title': 'translation', 'expiration_date': '', + 'engagement__reference': ''} + +offers = {'lister': + {'total_items': '10', 'query': '', 'paging': + {'count': '10', 'offset': '0'}, 'sort': ''}, + 'offer': [offer, offer]} + +job = {'subcategory': 'Development', 'reference': '1', + 'buyer_company__name': 'Python community', + 'job_type': 'fixed-price', 'created_time': '000', + 'created_by': 'test', 'duration': '', + 'last_candidacy_access_time': '', + 'category': 'Web', + 'buyer_team__reference': '169108', 'title': 'translation', + 'buyer_company__reference': '1', 'num_active_candidates': '0', + 'buyer_team__name': 'Python community 2', 'start_date': '000', + 'status': 'filled', 'num_new_candidates': '0', + 'description': 'test', 'end_date': '000', + 'public_url': 'http://www.odesk.com/jobs/~~0001', + 'visibility': 'invite-only', 'buyer_team__id': 'testteam:aa', + 'num_candidates': '1', 'budget': '1000', 'cancelled_date': '', + 'filled_date': '0000'} jobs = [job, job] -task = {u'reference': u'test', u'company_reference': u'1', - u'team__reference': u'1', u'user__reference': u'1', - u'code': u'1', u'description': u'test task', - u'url': u'http://url.odesk.com/task', u'level': u'1'} +task = {'reference': 'test', 'company_reference': '1', + 'team__reference': '1', 'user__reference': '1', + 'code': '1', 'description': 'test task', + 'url': 'http://url.odesk.com/task', 'level': '1'} tasks = [task, task] -auth_user = {u'first_name': u'TestF', u'last_name': u'TestL', - u'uid': u'testuser', u'timezone_offset': u'0', - u'timezone': u'Europe/Athens', u'mail': u'test_user@odesk.com', - u'messenger_id': u'', u'messenger_type': u'yahoo'} - -user = {u'status': u'active', u'first_name': u'TestF', - u'last_name': u'TestL', u'reference': u'0001', - u'timezone_offset': u'10800', - u'public_url': u'http://www.odesk.com/users/~~000', - u'is_provider': u'1', - u'timezone': u'GMT+02:00 Athens, Helsinki, Istanbul', - u'id': u'testuser'} - -team = {u'status': u'active', u'parent_team__reference': u'0', - u'name': u'Test', - u'reference': u'1', - u'company__reference': u'1', - u'id': u'test', - u'parent_team__id': u'test_parent', - u'company_name': u'Test', u'is_hidden': u'', - u'parent_team__name': u'Test parent'} - -company = {u'status': u'active', - u'name': u'Test', - u'reference': u'1', - u'company_id': u'1', - u'owner_user_id': u'1', } - -candidacy_stats = {u'job_application_quota': u'20', - u'job_application_quota_remaining': u'20', - u'number_of_applications': u'2', - u'number_of_interviews': u'3', - u'number_of_invites': u'0', - u'number_of_offers': u'0'} - -hr_dict = {u'auth_user': auth_user, - u'server_time': u'0000', - u'user': user, - u'team': team, - u'company': company, - u'teams': [team, team], - u'companies': [company, company], - u'users': [user, user], - u'tasks': task, - u'userroles': userroles, - u'engagements': engagements, - u'engagement': engagement, - u'offer': offer, - u'offers': offers, - u'job': job, - u'jobs': jobs, - u'candidacy_stats': candidacy_stats} +auth_user = {'first_name': 'TestF', 'last_name': 'TestL', + 'uid': 'testuser', 'timezone_offset': '0', + 'timezone': 'Europe/Athens', 'mail': 'test_user@odesk.com', + 'messenger_id': '', 'messenger_type': 'yahoo'} + +user = {'status': 'active', 'first_name': 'TestF', + 'last_name': 'TestL', 'reference': '0001', + 'timezone_offset': '10800', + 'public_url': 'http://www.odesk.com/users/~~000', + 'is_provider': '1', + 'timezone': 'GMT+02:00 Athens, Helsinki, Istanbul', + 'id': 'testuser'} + +team = {'status': 'active', 'parent_team__reference': '0', + 'name': 'Test', + 'reference': '1', + 'company__reference': '1', + 'id': 'test', + 'parent_team__id': 'test_parent', + 'company_name': 'Test', 'is_hidden': '', + 'parent_team__name': 'Test parent'} + +company = {'status': 'active', + 'name': 'Test', + 'reference': '1', + 'company_id': '1', + 'owner_user_id': '1', } + +candidacy_stats = {'job_application_quota': '20', + 'job_application_quota_remaining': '20', + 'number_of_applications': '2', + 'number_of_interviews': '3', + 'number_of_invites': '0', + 'number_of_offers': '0'} + +hr_dict = {'auth_user': auth_user, + 'server_time': '0000', + 'user': user, + 'team': team, + 'company': company, + 'teams': [team, team], + 'companies': [company, company], + 'users': [user, user], + 'tasks': task, + 'userroles': userroles, + 'engagements': engagements, + 'engagement': engagement, + 'offer': offer, + 'offers': offers, + 'job': job, + 'jobs': jobs, + 'candidacy_stats': candidacy_stats} def return_hr_json(): @@ -604,32 +604,32 @@ def patched_urlopen_hr(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_user(): hr = get_client().hr #test get_user - assert hr.get_user(1) == hr_dict[u'user'], hr.get_user(1) + assert hr.get_user(1) == hr_dict['user'], hr.get_user(1) -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_companies(): hr = get_client().hr #test get_companies - assert hr.get_companies() == hr_dict[u'companies'], hr.get_companies() + assert hr.get_companies() == hr_dict['companies'], hr.get_companies() #test get_company - assert hr.get_company(1) == hr_dict[u'company'], hr.get_company(1) + assert hr.get_company(1) == hr_dict['company'], hr.get_company(1) -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_company_teams(): hr = get_client().hr #test get_company_teams assert hr.get_company_teams(1) == hr_dict['teams'], hr.get_company_teams(1) -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_company_users(): hr = get_client().hr #test get_company_users @@ -637,52 +637,52 @@ def test_get_hrv2_company_users(): assert hr.get_company_users(1, False) == hr_dict['users'], \ hr.get_company_users(1, False) -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_teams(): hr = get_client().hr #test get_teams - assert hr.get_teams() == hr_dict[u'teams'], hr.get_teams() + assert hr.get_teams() == hr_dict['teams'], hr.get_teams() #test get_team - assert hr.get_team(1) == hr_dict[u'team'], hr.get_team(1) + assert hr.get_team(1) == hr_dict['team'], hr.get_team(1) -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_team_users(): hr = get_client().hr #test get_team_users - assert hr.get_team_users(1) == hr_dict[u'users'], hr.get_team_users(1) - assert hr.get_team_users(1, False) == hr_dict[u'users'], \ + assert hr.get_team_users(1) == hr_dict['users'], hr.get_team_users(1) + assert hr.get_team_users(1, False) == hr_dict['users'], \ hr.get_team_users(1, False) -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_jobs(): hr = get_client().hr #test get_jobs - assert hr.get_jobs() == hr_dict[u'jobs'], hr.get_jobs() - assert hr.get_job(1) == hr_dict[u'job'], hr.get_job(1) + assert hr.get_jobs() == hr_dict['jobs'], hr.get_jobs() + assert hr.get_job(1) == hr_dict['job'], hr.get_job(1) assert hr.update_job(1, {'status': 'filled'}) == hr_dict, hr.update_job(1, {'status': 'filled'}) assert hr.delete_job(1, 41) == hr_dict, hr.delete_job(1, 41) -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_offers(): hr = get_client().hr #test get_offers - assert hr.get_offers() == hr_dict[u'offers'], hr.get_offers() - assert hr.get_offer(1) == hr_dict[u'offer'], hr.get_offer(1) + assert hr.get_offers() == hr_dict['offers'], hr.get_offers() + assert hr.get_offer(1) == hr_dict['offer'], hr.get_offer(1) -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_engagements(): hr = get_client().hr #test get_engagements - assert hr.get_engagements() == hr_dict[u'engagements'], hr.get_engagements() - assert hr.get_engagement(1) == hr_dict[u'engagement'], hr.get_engagement(1) + assert hr.get_engagements() == hr_dict['engagements'], hr.get_engagements() + assert hr.get_engagement(1) == hr_dict['engagement'], hr.get_engagement(1) -adjustments = {u'adjustment': {u'reference': '100'}} +adjustments = {'adjustment': {'reference': '100'}} def return_hradjustment_json(): @@ -694,15 +694,15 @@ def patched_urlopen_hradjustment(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_hradjustment) +@patch('urllib.request.urlopen', patched_urlopen_hradjustment) def test_hrv2_post_adjustment(): hr = get_client().hr result = hr.post_team_adjustment(1, 2, 100000, 'test', 'test note') - assert result == adjustments[u'adjustment'], result + assert result == adjustments['adjustment'], result -@patch('urllib2.urlopen', patched_urlopen_hr) +@patch('urllib.request.urlopen', patched_urlopen_hr) def test_get_hrv2_candidacy_stats(): hr = get_client().hr #test get_candidacy_stats @@ -711,27 +711,27 @@ def test_get_hrv2_candidacy_stats(): provider_dict = {'profile': - {u'response_time': u'31.0000000000000000', - u'dev_agency_ref': u'', - u'dev_adj_score_recent': u'0', - u'dev_ui_profile_access': u'Public', - u'dev_portrait': u'', - u'dev_ic': u'Freelance Provider', - u'certification': u'', - u'dev_usr_score': u'0', - u'dev_country': u'Ukraine', - u'dev_recent_rank_percentile': u'0', - u'dev_profile_title': u'Python developer', - u'dev_groups': u'', - u'dev_scores': - {u'dev_score': - [{u'description': u'competency and skills for the job, understanding of specifications/instructions', - u'avg_category_score_recent': u'', - u'avg_category_score': u'', - u'order': u'1', u'label': u'Skills'}, - {u'description': u'quality of work deliverables', - u'avg_category_score_recent': u'', - u'avg_category_score': u'', u'order': u'2', u'label': u'Quality'}, + {'response_time': '31.0000000000000000', + 'dev_agency_ref': '', + 'dev_adj_score_recent': '0', + 'dev_ui_profile_access': 'Public', + 'dev_portrait': '', + 'dev_ic': 'Freelance Provider', + 'certification': '', + 'dev_usr_score': '0', + 'dev_country': 'Ukraine', + 'dev_recent_rank_percentile': '0', + 'dev_profile_title': 'Python developer', + 'dev_groups': '', + 'dev_scores': + {'dev_score': + [{'description': 'competency and skills for the job, understanding of specifications/instructions', + 'avg_category_score_recent': '', + 'avg_category_score': '', + 'order': '1', 'label': 'Skills'}, + {'description': 'quality of work deliverables', + 'avg_category_score_recent': '', + 'avg_category_score': '', 'order': '2', 'label': 'Quality'}, ] }}, 'providers': {'test': 'test'}, @@ -755,7 +755,7 @@ def patched_urlopen_provider(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_provider) +@patch('urllib.request.urlopen', patched_urlopen_provider) def test_provider(): pr = get_client().provider @@ -791,18 +791,18 @@ def test_provider(): assert result == provider_dict['profile'] -trays_dict = {'trays': [{u'unread': u'0', - u'type': u'sent', - u'id': u'1', - u'tray_api': u'/api/mc/v1/trays/username/sent.json'}, - {u'unread': u'0', - u'type': u'inbox', - u'id': u'2', - u'tray_api': u'/api/mc/v1/trays/username/inbox.json'}, - {u'unread': u'0', - u'type': u'notifications', - u'id': u'3', - u'tray_api': u'/api/mc/v1/trays/username/notifications.json'}]} +trays_dict = {'trays': [{'unread': '0', + 'type': 'sent', + 'id': '1', + 'tray_api': '/api/mc/v1/trays/username/sent.json'}, + {'unread': '0', + 'type': 'inbox', + 'id': '2', + 'tray_api': '/api/mc/v1/trays/username/inbox.json'}, + {'unread': '0', + 'type': 'notifications', + 'id': '3', + 'tray_api': '/api/mc/v1/trays/username/notifications.json'}]} def return_trays_json(): @@ -814,7 +814,7 @@ def patched_urlopen_trays(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_trays) +@patch('urllib.request.urlopen', patched_urlopen_trays) def test_get_trays(): mc = get_client().mc @@ -840,7 +840,7 @@ def patched_urlopen_tray_content(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_tray_content) +@patch('urllib.request.urlopen', patched_urlopen_tray_content) def test_get_tray_content(): mc = get_client().mc @@ -864,7 +864,7 @@ def patched_urlopen_thread_content(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_thread_content) +@patch('urllib.request.urlopen', patched_urlopen_thread_content) def test_get_thread_content(): mc = get_client().mc @@ -888,7 +888,7 @@ def patched_urlopen_read_thread_content(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_read_thread_content) +@patch('urllib.request.urlopen', patched_urlopen_read_thread_content) def test_put_threads_read_unread(): mc = get_client().mc @@ -902,7 +902,7 @@ def test_put_threads_read_unread(): assert read == read_thread_content_dict, read -@patch('urllib2.urlopen', patched_urlopen_read_thread_content) +@patch('urllib.request.urlopen', patched_urlopen_read_thread_content) def test_put_threads_starred_unstarred(): mc = get_client().mc @@ -913,7 +913,7 @@ def test_put_threads_starred_unstarred(): assert unstarred == read_thread_content_dict, unstarred -@patch('urllib2.urlopen', patched_urlopen_read_thread_content) +@patch('urllib.request.urlopen', patched_urlopen_read_thread_content) def test_put_threads_deleted_undeleted(): mc = get_client().mc @@ -924,7 +924,7 @@ def test_put_threads_deleted_undeleted(): assert undeleted == read_thread_content_dict, undeleted -@patch('urllib2.urlopen', patched_urlopen_read_thread_content) +@patch('urllib.request.urlopen', patched_urlopen_read_thread_content) def test_post_message(): mc = get_client().mc @@ -947,24 +947,24 @@ def test_post_message(): assert reply == read_thread_content_dict, reply -timereport_dict = {u'table': - {u'rows': - [{u'c': - [{u'v': u'20100513'}, - {u'v': u'company1:team1'}, - {u'v': u'1'}, - {u'v': u'1'}, - {u'v': u'0'}, - {u'v': u'1'}, - {u'v': u'Bug 1: Test'}]}], - u'cols': - [{u'type': u'date', u'label': u'worked_on'}, - {u'type': u'string', u'label': u'assignment_team_id'}, - {u'type': u'number', u'label': u'hours'}, - {u'type': u'number', u'label': u'earnings'}, - {u'type': u'number', u'label': u'earnings_offline'}, - {u'type': u'string', u'label': u'task'}, - {u'type': u'string', u'label': u'memo'}]}} +timereport_dict = {'table': + {'rows': + [{'c': + [{'v': '20100513'}, + {'v': 'company1:team1'}, + {'v': '1'}, + {'v': '1'}, + {'v': '0'}, + {'v': '1'}, + {'v': 'Bug 1: Test'}]}], + 'cols': + [{'type': 'date', 'label': 'worked_on'}, + {'type': 'string', 'label': 'assignment_team_id'}, + {'type': 'number', 'label': 'hours'}, + {'type': 'number', 'label': 'earnings'}, + {'type': 'number', 'label': 'earnings_offline'}, + {'type': 'string', 'label': 'task'}, + {'type': 'string', 'label': 'memo'}]}} def return_read_timereport_json(*args, **kwargs): @@ -976,7 +976,7 @@ def patched_urlopen_timereport_content(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_timereport_content) +@patch('urllib.request.urlopen', patched_urlopen_timereport_content) def test_get_provider_timereport(): tc = get_client().timereport @@ -990,7 +990,7 @@ def test_get_provider_timereport(): assert read == timereport_dict, read -@patch('urllib2.urlopen', patched_urlopen_timereport_content) +@patch('urllib.request.urlopen', patched_urlopen_timereport_content) def test_get_company_timereport(): tc = get_client().timereport @@ -1004,7 +1004,7 @@ def test_get_company_timereport(): assert read == timereport_dict, read -@patch('urllib2.urlopen', patched_urlopen_timereport_content) +@patch('urllib.request.urlopen', patched_urlopen_timereport_content) def test_get_agency_timereport(): tc = get_client().timereport @@ -1017,24 +1017,24 @@ def test_get_agency_timereport(): hours=True) assert read == timereport_dict, read -fin_report_dict = {u'table': - {u'rows': - [{u'c': - [{u'v': u'20100513'}, - {u'v': u'odesk:odeskps'}, - {u'v': u'1'}, - {u'v': u'1'}, - {u'v': u'0'}, - {u'v': u'1'}, - {u'v': u'Bug 1: Test'}]}], - u'cols': - [{u'type': u'date', u'label': u'worked_on'}, - {u'type': u'string', u'label': u'assignment_team_id'}, - {u'type': u'number', u'label': u'hours'}, - {u'type': u'number', u'label': u'earnings'}, - {u'type': u'number', u'label': u'earnings_offline'}, - {u'type': u'string', u'label': u'task'}, - {u'type': u'string', u'label': u'memo'}]}} +fin_report_dict = {'table': + {'rows': + [{'c': + [{'v': '20100513'}, + {'v': 'odesk:odeskps'}, + {'v': '1'}, + {'v': '1'}, + {'v': '0'}, + {'v': '1'}, + {'v': 'Bug 1: Test'}]}], + 'cols': + [{'type': 'date', 'label': 'worked_on'}, + {'type': 'string', 'label': 'assignment_team_id'}, + {'type': 'number', 'label': 'hours'}, + {'type': 'number', 'label': 'earnings'}, + {'type': 'number', 'label': 'earnings_offline'}, + {'type': 'string', 'label': 'task'}, + {'type': 'string', 'label': 'memo'}]}} def return_read_fin_report_json(*args, **kwargs): @@ -1046,7 +1046,7 @@ def patched_urlopen_fin_report_content(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_provider_billings(): fr = get_client().finreport @@ -1054,7 +1054,7 @@ def test_get_provider_billings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_provider_teams_billings(): fr = get_client().finreport @@ -1062,7 +1062,7 @@ def test_get_provider_teams_billings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_provider_companies_billings(): fr = get_client().finreport @@ -1070,7 +1070,7 @@ def test_get_provider_companies_billings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_provider_earnings(): fr = get_client().finreport @@ -1078,7 +1078,7 @@ def test_get_provider_earnings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_provider_teams_earnings(): fr = get_client().finreport @@ -1086,7 +1086,7 @@ def test_get_provider_teams_earnings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_provider_companies_earnings(): fr = get_client().finreport @@ -1094,7 +1094,7 @@ def test_get_provider_companies_earnings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_buyer_teams_billings(): fr = get_client().finreport @@ -1102,7 +1102,7 @@ def test_get_buyer_teams_billings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_buyer_companies_billings(): fr = get_client().finreport @@ -1110,7 +1110,7 @@ def test_get_buyer_companies_billings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_buyer_teams_earnings(): fr = get_client().finreport @@ -1118,7 +1118,7 @@ def test_get_buyer_teams_earnings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_buyer_companies_earnings(): fr = get_client().finreport @@ -1126,7 +1126,7 @@ def test_get_buyer_companies_earnings(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_financial_entities(): fr = get_client().finreport @@ -1134,7 +1134,7 @@ def test_get_financial_entities(): assert read == fin_report_dict, read -@patch('urllib2.urlopen', patched_urlopen_fin_report_content) +@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) def test_get_financial_entities_provider(): fr = get_client().finreport @@ -1152,7 +1152,7 @@ def test_get_version(): assert get_version() == '1.2.3 pre-alpha', get_version() -task_dict = {u'tasks': 'task1' +task_dict = {'tasks': 'task1' } @@ -1165,7 +1165,7 @@ def patched_urlopen_task(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_get_company_tasks(): task = get_client().task @@ -1173,7 +1173,7 @@ def test_get_company_tasks(): task.get_company_tasks(1) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_get_team_tasks(): task = get_client().task @@ -1181,7 +1181,7 @@ def test_get_team_tasks(): task.get_team_tasks(1, 1) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_get_user_tasks(): task = get_client().task @@ -1189,7 +1189,7 @@ def test_get_user_tasks(): task.get_user_tasks(1, 1, 1) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_company_tasks_full(): task = get_client().task @@ -1197,7 +1197,7 @@ def test_company_tasks_full(): task.get_company_tasks_full(1) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_get_team_tasks_full(): task = get_client().task @@ -1205,7 +1205,7 @@ def test_get_team_tasks_full(): task.get_team_tasks_full(1, 1) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_get_user_tasks_full(): task = get_client().task @@ -1213,7 +1213,7 @@ def test_get_user_tasks_full(): task.get_user_tasks_full(1, 1, 1) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_get_company_specific_tasks(): task = get_client().task @@ -1221,7 +1221,7 @@ def test_get_company_specific_tasks(): task.get_company_specific_tasks(1, [1, 1]) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_get_team_specific_tasks(): task = get_client().task @@ -1229,7 +1229,7 @@ def test_get_team_specific_tasks(): task.get_team_specific_tasks(1, 1, [1, 1]) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_get_user_specific_tasks(): task = get_client().task @@ -1237,7 +1237,7 @@ def test_get_user_specific_tasks(): task.get_user_specific_tasks(1, 1, 1, [1, 1]) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_post_company_task(): task = get_client().task @@ -1245,7 +1245,7 @@ def test_post_company_task(): task.post_company_task(1, 1, '1', 'ttt') -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_post_team_task(): task = get_client().task @@ -1253,7 +1253,7 @@ def test_post_team_task(): task.post_team_task(1, 1, 1, '1', 'ttt') -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_post_user_task(): task = get_client().task @@ -1261,7 +1261,7 @@ def test_post_user_task(): task.post_user_task(1, 1, 1, 1, '1', 'ttt') -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_put_company_task(): task = get_client().task @@ -1269,7 +1269,7 @@ def test_put_company_task(): task.put_company_task(1, 1, '1', 'ttt') -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_put_team_task(): task = get_client().task @@ -1277,7 +1277,7 @@ def test_put_team_task(): task.put_team_task(1, 1, 1, '1', 'ttt') -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_put_user_task(): task = get_client().task @@ -1285,7 +1285,7 @@ def test_put_user_task(): task.put_user_task(1, 1, 1, 1, '1', 'ttt') -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_delete_company_task(): task = get_client().task @@ -1293,7 +1293,7 @@ def test_delete_company_task(): task.delete_company_task(1, [1, 1]) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_delete_team_task(): task = get_client().task @@ -1301,7 +1301,7 @@ def test_delete_team_task(): task.delete_team_task(1, 1, [1, 1]) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_delete_user_task(): task = get_client().task @@ -1309,7 +1309,7 @@ def test_delete_user_task(): task.delete_user_task(1, 1, 1, [1, 1]) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_delete_all_company_tasks(): task = get_client().task @@ -1317,7 +1317,7 @@ def test_delete_all_company_tasks(): task.delete_all_company_tasks(1) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_delete_all_team_tasks(): task = get_client().task @@ -1325,7 +1325,7 @@ def test_delete_all_team_tasks(): task.delete_all_team_tasks(1, 1) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_delete_all_user_tasks(): task = get_client().task @@ -1333,7 +1333,7 @@ def test_delete_all_user_tasks(): task.delete_all_user_tasks(1, 1, 1) -@patch('urllib2.urlopen', patched_urlopen_task) +@patch('urllib.request.urlopen', patched_urlopen_task) def test_update_batch_tasks(): task = get_client().task @@ -1349,29 +1349,29 @@ def test_gds_namespace(): gds.urlopen('test.url', {}, 'POST') -oconomy_dict = {u'table': - {u'rows': - [{u'c': [{u'v': u'Administrative Support'}, - {u'v': u'2787297.31'}]}, - {u'c': [{u'v': u'Business Services'}, - {u'v': u'1146857.51'}]}, - {u'c': [{u'v': u'Customer Service'}, - {u'v': u'1072926.55'}]}, - {u'c': [{u'v': u'Design & Multimedia'}, - {u'v': u'1730094.73'}]}, - {u'c': [{u'v': u'Networking & Information Systems'}, - {u'v': u'690526.57'}]}, - {u'c': [{u'v': u'Sales & Marketing'}, - {u'v': u'3232511.54'}]}, - {u'c': [{u'v': u'Software Development'}, - {u'v': u'6826354.60'}]}, - {u'c': [{u'v': u'Web Development'}, - {u'v': u'15228679.46'}]}, - {u'c': [{u'v': u'Writing & Translation'}, - {u'v': u'2257654.76'}]}], - u'cols': - [{u'type': u'string', u'label': u'category'}, - {u'type': u'number', u'label': u'amount'}]}} +oconomy_dict = {'table': + {'rows': + [{'c': [{'v': 'Administrative Support'}, + {'v': '2787297.31'}]}, + {'c': [{'v': 'Business Services'}, + {'v': '1146857.51'}]}, + {'c': [{'v': 'Customer Service'}, + {'v': '1072926.55'}]}, + {'c': [{'v': 'Design & Multimedia'}, + {'v': '1730094.73'}]}, + {'c': [{'v': 'Networking & Information Systems'}, + {'v': '690526.57'}]}, + {'c': [{'v': 'Sales & Marketing'}, + {'v': '3232511.54'}]}, + {'c': [{'v': 'Software Development'}, + {'v': '6826354.60'}]}, + {'c': [{'v': 'Web Development'}, + {'v': '15228679.46'}]}, + {'c': [{'v': 'Writing & Translation'}, + {'v': '2257654.76'}]}], + 'cols': + [{'type': 'string', 'label': 'category'}, + {'type': 'number', 'label': 'amount'}]}} def return_read_oconomy_json(*args, **kwargs): @@ -1383,7 +1383,7 @@ def patched_urlopen_oconomy_content(request, *args, **kwargs): return request -@patch('urllib2.urlopen', patched_urlopen_oconomy_content) +@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) def test_get_monthly_summary(): oconomy = get_client().nonauth_oconomy @@ -1391,7 +1391,7 @@ def test_get_monthly_summary(): assert read == oconomy_dict, read -@patch('urllib2.urlopen', patched_urlopen_oconomy_content) +@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) def test_get_hours_worked_by_locations(): oconomy = get_client().oconomy @@ -1399,7 +1399,7 @@ def test_get_hours_worked_by_locations(): assert read == oconomy_dict, read -@patch('urllib2.urlopen', patched_urlopen_oconomy_content) +@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) def test_get_hours_worked_by_weeks(): oconomy = get_client().oconomy @@ -1407,7 +1407,7 @@ def test_get_hours_worked_by_weeks(): assert read == oconomy_dict, read -@patch('urllib2.urlopen', patched_urlopen_oconomy_content) +@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) def test_get_top_countries_by_hours(): oconomy = get_client().oconomy @@ -1415,7 +1415,7 @@ def test_get_top_countries_by_hours(): assert read == oconomy_dict, read -@patch('urllib2.urlopen', patched_urlopen_oconomy_content) +@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) def test_get_earnings_by_categories(): oconomy = get_client().nonauth_oconomy @@ -1423,7 +1423,7 @@ def test_get_earnings_by_categories(): assert read == oconomy_dict, read -@patch('urllib2.urlopen', patched_urlopen_oconomy_content) +@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) def test_get_most_requested_skills(): oconomy = get_client().oconomy diff --git a/setup.py b/setup.py index 56c9541..ff321c3 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ author_email='python@odesk.com', maintainer='Volodymyr Hotsyk', maintainer_email='gotsyk@gmail.com', - install_requires=['oauth2',], + dependency_links = ['https://github.com/hades/python-oauth2/tarball/python3#egg=python-oauth2',], packages=find_packages(), license = 'BSD', download_url ='http://github.com/odesk/python-odesk', From 865b00b7c620f8bbbd171123aa956e76a1b5e197 Mon Sep 17 00:00:00 2001 From: Ilia Vihtinsky Date: Wed, 6 Jun 2012 16:52:56 +0400 Subject: [PATCH 03/19] Fixes. Working oauth example --- examples/examples_oauth.py | 60 ++++++++++++++++++++------------------ odesk/__init__.py | 2 +- odesk/oauth.py | 8 ++--- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/examples/examples_oauth.py b/examples/examples_oauth.py index 58435a5..ec9ec78 100644 --- a/examples/examples_oauth.py +++ b/examples/examples_oauth.py @@ -12,15 +12,19 @@ #TODO: Desktop app example (check if it's working at all - wasn't last time) def web_based_app(public_key, secret_key): - print "Emulating web-based app" + print ("Emulating web-based app") #Instantiating a client without an auth token client = odesk.Client(public_key, secret_key, auth='oauth') - print "Please to this URL (authorize the app if necessary):" - print client.auth.get_authorize_url() - print "After that you should be redirected back to your app URL with " + \ - "additional ?oauth_verifier= parameter" - verifier = raw_input('Enter oauth_verifier: ') + print ("Please to this URL (authorize the app if necessary):") + #import pdb + #pdb.set_trace() + print (client.auth.get_authorize_url()) + print ("After that you should be redirected back to your app URL with " + \ + "additional ?oauth_verifier= parameter") + verifier = input('Enter oauth_verifier: ') oauth_access_token, oauth_access_token_secret = client.auth.get_access_token(verifier) + #import pdb + #pdb.set_trace() #Instantiating a new client, now with a token. #Not strictly necessary here (could just set `client.oauth_access_token` #and `client.oauth_access_token_secret`), but typical for web apps, @@ -30,34 +34,34 @@ def web_based_app(public_key, secret_key): oauth_access_token_secret=oauth_access_token_secret) try: - print "Team rooms:" - print client.team.get_teamrooms() + print ("Team rooms:") + print (client.team.get_teamrooms()) #HRv2 API - print "HR: companies" - print client.hr.get_companies() - print "HR: teams" - print client.hr.get_teams() - print "HR: offers" - print client.hr.get_offers() - print "HR: get_engagements" - print client.hr.get_engagements() - print "HR: userroles" - print client.hr.get_user_role() - print "HR: candidacy stats" - print client.hr.get_candidacy_stats() - print "Get jobs" - print client.provider.get_jobs({'q': 'python'}) - print "Financial: withdrawal methods" - print client.finance.get_withdrawal_methods() - except Exception, e: - print "Exception at %s %s" % (client.last_method, client.last_url) + print ("HR: companies") + print (client.hr.get_companies()) + print ("HR: teams") + print (client.hr.get_teams()) + print ("HR: offers") + print (client.hr.get_offers()) + print ("HR: get_engagements") + print (client.hr.get_engagements()) + print ("HR: userroles") + print (client.hr.get_user_role()) + print ("HR: candidacy stats") + print (client.hr.get_candidacy_stats()) + print ("Get jobs") + print (client.provider.get_jobs({'q': 'python'})) + print ("Financial: withdrawal methods") + print (client.finance.get_withdrawal_methods()) + except Exception as e: + print ("Exception at %s %s" % (client.last_method, client.last_url)) raise e if __name__ == '__main__': - public_key = PUBLIC_KEY or raw_input('Enter public key: ') - secret_key = SECRET_KEY or raw_input('Enter secret key: ') + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') web_based_app(public_key, secret_key) diff --git a/odesk/__init__.py b/odesk/__init__.py index b3f3aa1..e98d49e 100644 --- a/odesk/__init__.py +++ b/odesk/__init__.py @@ -114,7 +114,7 @@ def read(self, url, data={}, method='GET', format='json'): raise_http_error(e) if format == 'json': - result = json.loads(response.read()) + result = json.loads(response.read().decode("utf-8")) return result diff --git a/odesk/oauth.py b/odesk/oauth.py index 321dd26..00ff4f8 100644 --- a/odesk/oauth.py +++ b/odesk/oauth.py @@ -59,8 +59,8 @@ def get_request_token(self): if response.get('status') != '200': raise Exception("Invalid request token response: %s." % content) request_token = dict(urllib.parse.parse_qsl(content)) - self.request_token = request_token.get('oauth_token') - self.request_token_secret = request_token.get('oauth_token_secret') + self.request_token = request_token.get(b'oauth_token') + self.request_token_secret = request_token.get(b'oauth_token_secret') return self.request_token, self.request_token_secret def get_authorize_url(self, callback_url=None): @@ -92,6 +92,6 @@ def get_access_token(self, verifier): if response.get('status') != '200': raise Exception("Invalid access token response: %s." % content) access_token = dict(urllib.parse.parse_qsl(content)) - self.access_token = access_token.get('oauth_token') - self.access_token_secret = access_token.get('oauth_token_secret') + self.access_token = access_token.get(b'oauth_token') + self.access_token_secret = access_token.get(b'oauth_token_secret') return self.access_token, self.access_token_secret From e715c535d0b08e24ed1d658767b9cc7f09f06ae0 Mon Sep 17 00:00:00 2001 From: Ilia Vihtinsky Date: Wed, 6 Jun 2012 17:18:23 +0400 Subject: [PATCH 04/19] Another byte/str fix. Working examples.py --- examples/examples.py | 64 ++++++++++++++++++++++---------------------- odesk/__init__.py | 2 +- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/examples/examples.py b/examples/examples.py index a7ea770..5d5da0d 100644 --- a/examples/examples.py +++ b/examples/examples.py @@ -12,17 +12,17 @@ #TODO: Desktop app example (check if it's working at all - wasn't last time) def web_based_app(public_key, secret_key): - print "Emulating web-based app" + print("Emulating web-based app") #Instantiating a client without an auth token client = odesk.Client(public_key, secret_key) - print "Please to this URL (authorize the app if necessary):" - print client.auth.auth_url() - print "After that you should be redirected back to your app URL with " + \ - "additional ?frob= parameter" - frob = raw_input('Enter frob: ') + print("Please to this URL (authorize the app if necessary):") + print(client.auth.auth_url()) + print("After that you should be redirected back to your app URL with " + \ + "additional ?frob= parameter") + frob = input('Enter frob: ') auth_token, user = client.auth.get_token(frob) - print "Authenticated user:" - print user + print("Authenticated user:") + print(user) #Instantiating a new client, now with a token. #Not strictly necessary here (could just set `client.auth_token`), but #typical for web apps, which wouldn't probably keep client instances @@ -30,36 +30,36 @@ def web_based_app(public_key, secret_key): client = odesk.Client(public_key, secret_key, auth_token) try: - print "Team rooms:" - print client.team.get_teamrooms() + print("Team rooms:") + print(client.team.get_teamrooms()) #HRv2 API - print "HR: companies" - print client.hr.get_companies() - print "HR: teams" - print client.hr.get_teams() - print "HR: offers" - print client.hr.get_offers() - print "HR: get_engagements" - print client.hr.get_engagements() - print "HR: userroles" - print client.hr.get_user_role() - print "HR: candidacy stats" - print client.hr.get_candidacy_stats() - print "Get jobs" - print client.provider.get_jobs({'q': 'python'}) - print "Financial: withdrawal methods" - print client.finance.get_withdrawal_methods() - print "Revoke access" - print client.auth.revoke_token() - except Exception, e: - print "Exception at %s %s" % (client.last_method, client.last_url) + print("HR: companies") + print(client.hr.get_companies()) + print("HR: teams") + print(client.hr.get_teams()) + print("HR: offers") + print(client.hr.get_offers()) + print("HR: get_engagements") + print(client.hr.get_engagements()) + print("HR: userroles") + print(client.hr.get_user_role()) + print("HR: candidacy stats") + print(client.hr.get_candidacy_stats()) + print("Get jobs") + print(client.provider.get_jobs({'q': 'python'})) + print("Financial: withdrawal methods") + print(client.finance.get_withdrawal_methods()) + print("Revoke access") + print(client.auth.revoke_token()) + except Exception as e: + print("Exception at %s %s" % (client.last_method, client.last_url)) raise e if __name__ == '__main__': - public_key = PUBLIC_KEY or raw_input('Enter public key: ') - secret_key = SECRET_KEY or raw_input('Enter secret key: ') + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') web_based_app(public_key, secret_key) diff --git a/odesk/__init__.py b/odesk/__init__.py index e98d49e..55cafca 100644 --- a/odesk/__init__.py +++ b/odesk/__init__.py @@ -99,7 +99,7 @@ def urlopen(self, url, data={}, method='GET'): url += '?' + query request = HttpRequest(url=url, data=None, method=method) else: - request = HttpRequest(url=url, data=query, method=method) + request = HttpRequest(url=url, data=query.encode("utf-8"), method=method) return urllib.request.urlopen(request) def read(self, url, data={}, method='GET', format='json'): From 3f268983d0e81302cc7aa68ffca76bcb6abe58d4 Mon Sep 17 00:00:00 2001 From: Ilia Vihtinsky Date: Wed, 6 Jun 2012 17:37:18 +0400 Subject: [PATCH 05/19] oconomy example --- examples/oconomy.py | 78 +++++++++++++++++++++------------------------ odesk/namespaces.py | 7 ++-- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/examples/oconomy.py b/examples/oconomy.py index f15a511..c27197d 100644 --- a/examples/oconomy.py +++ b/examples/oconomy.py @@ -12,54 +12,48 @@ #TODO: Desktop app example (check if it's working at all - wasn't last time) def oconomy(public_key, secret_key): - print "Emulating web-based app" + print("Emulating web-based app") #Instantiating a client without an auth token client = odesk.Client(public_key, secret_key) - print "Please to this URL (authorize the app if necessary):" - print client.auth.auth_url() - print "After that you should be redirected back to your app URL with " + \ - "additional ?frob= parameter" - frob = raw_input('Enter frob: ') + print("Please to this URL (authorize the app if necessary):") + print(client.auth.auth_url()) + print("After that you should be redirected back to your app URL with " + \ + "additional ?frob= parameter") + frob = input('Enter frob: ') auth_token, user = client.auth.get_token(frob) - print "Authenticated user:" - print user - #Instantiating a new client, now with a token. - #Not strictly necessary here (could just set `client.auth_token`), but - #typical for web apps, which wouldn't probably keep client instances + print("Authenticated user:") + print(user) + #Instantiating a new client, now with a token. + #Not strictly necessary here (could just set `client.auth_token`), but + #typical for web apps, which wouldn't probably keep client instances #between requests client = odesk.Client(public_key, secret_key, auth_token) - print client.oconomy.get_summary(2010,12) - - print client.oconomy.get_hours_worked_by_locations() - print client.oconomy.get_hours_worked_by_weeks() - print client.oconomy.get_top_countries_by_hours() - print client.oconomy.get_charges_by_categories() - print client.oconomy.get_most_requested_skills() - - print client.gds_oconomy.get_summary(2010,12) - - print client.gds_oconomy.get_hours_worked_by_locations() - print client.gds_oconomy.get_hours_worked_by_weeks() - print client.gds_oconomy.get_top_countries_by_hours() - print client.gds_oconomy.get_charges_by_categories() - print client.gds_oconomy.get_most_requested_skills() + print(client.oconomy.get_summary(2010,12)) + + print(client.oconomy.get_hours_worked_by_locations()) + print(client.oconomy.get_hours_worked_by_weeks()) + print(client.oconomy.get_top_countries_by_hours()) + print(client.oconomy.get_charges_by_categories()) + print(client.oconomy.get_most_requested_skills()) + + print(client.nonauth_oconomy.get_hours_worked_by_locations()) + print(client.nonauth_oconomy.get_hours_worked_by_weeks()) + print("top countries by hours") + print(client.nonauth_oconomy.get_top_countries_by_hours()) + print(client.nonauth_oconomy.get_most_requested_skills()) + + print("monthly summary") + print(client.nonauth_oconomy.get_monthly_summary('201011')) + print("hours worked by locations") + print(client.nonauth_oconomy.get_hours_worked_by_locations()) + print("earnings by categories") + print(client.nonauth_oconomy.get_earnings_by_categories()) + print("most requested skills") + print(client.oconomy.get_most_requested_skills()) + - print "monthly summary" - print client.oconomy.get_monthly_summary('201011') - print "hours worked by locations" - print client.oconomy.get_hours_worked_by_locations() - print "hours worked by weeks" - print client.oconomy.get_hours_worked_by_weeks() - print "top countries by hours" - print client.oconomy.get_top_countries_by_hours() - print "earnings by categories" - print client.oconomy.get_earnings_by_categories() - print "most requested skills" - print client.oconomy.get_most_requested_skills() - - if __name__ == '__main__': - public_key = PUBLIC_KEY or raw_input('Enter public key: ') - secret_key = SECRET_KEY or raw_input('Enter secret key: ') + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') oconomy(public_key, secret_key) diff --git a/odesk/namespaces.py b/odesk/namespaces.py index 1b9cac5..c3431f6 100644 --- a/odesk/namespaces.py +++ b/odesk/namespaces.py @@ -64,7 +64,7 @@ def read(self, url, data={}, method='GET'): except urllib.error.HTTPError as e: raise_http_error(e) - result = json.loads(response.read()) + result = json.loads(response.read().decode("utf-8")) return result def get(self, url, data={}): @@ -79,7 +79,8 @@ class NonauthGdsNamespace(GdsNamespace): ''' def urlopen(self, url, data={}, method='GET'): if method == 'GET': - request = HttpRequest(url=url, data=data.copy(), - method=method) + query = self.client.urlencode(data) + url += '?' + query + request = HttpRequest(url=url, data=None, method=method) return urllib.request.urlopen(request) return None From b6cecec949941fa2051fe883de14d09e88bdc5c2 Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 13:08:00 +0400 Subject: [PATCH 06/19] Fixed setup.py --- setup.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index ff321c3..d893da3 100644 --- a/setup.py +++ b/setup.py @@ -5,18 +5,19 @@ README = readme.read() readme.close() -version = __import__('odesk').get_version() +version = "0.1" -setup(name='python-odesk', +setup(name='python-odesk3', version=version, - description='Python bindings to oDesk API', + description='Python3 bindings to oDesk API', long_description=README, author='oDesk', author_email='python@odesk.com', maintainer='Volodymyr Hotsyk', maintainer_email='gotsyk@gmail.com', - dependency_links = ['https://github.com/hades/python-oauth2/tarball/python3#egg=python-oauth2',], + install_requires=['oauth2',], + dependency_links = ['https://github.com/hades/python-oauth2/tarball/python3#egg=oauth2',], packages=find_packages(), license = 'BSD', download_url ='http://github.com/odesk/python-odesk', From f33756ec66963136282c5f461656d7023786992e Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 13:27:06 +0400 Subject: [PATCH 07/19] Change docs --- README | 8 ++++---- README.md | 6 +++--- getting_started.rst | 5 ++++- index.rst | 6 +++--- requirements.py | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README b/README index 9e73dc0..f9eadf7 100644 --- a/README +++ b/README @@ -1,10 +1,10 @@ Copyright (c) 2010-2011, oDesk http://www.odesk.com All rights reserved. -Python3 bindings to oDesk API +Python3 bindings to oDesk API. Python3 port of python-odesk. -* Git repo: http://github.com/odesk/python-odesk3 -* Issues: http://github.com/odesk/python-odesk3/issues -* Documentation: http://odesk.github.com/python-odesk3/ +* Git repo: http://github.com/vihtinsky/python-odesk3 +* Issues: http://github.com/odesk/python-odesk/issues +* Documentation: http://odesk.github.com/python-odesk/ diff --git a/README.md b/README.md index d449b85..2f40b3e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ All rights reserved. Python3 bindings to oDesk API ======================================= -* [Git repo](http://github.com/odesk/python-odesk3) -* [Issues](http://github.com/odesk/python-odesk3/issues) -* [Documentation](http://odesk.github.com/python-odesk3/) +* [Git repo](http://github.com/vihtinsky/python-odesk3) +* [Issues](http://github.com/odesk/python-odesk/issues) +* [Documentation](http://odesk.github.com/python-odesk/) diff --git a/getting_started.rst b/getting_started.rst index 1c1f8b2..ab40ab2 100644 --- a/getting_started.rst +++ b/getting_started.rst @@ -12,6 +12,9 @@ Requirements ----------------- You need to install oauth2 to run the python-odesk3, and mock and nosetests if you plan to develop python-odesk and/or run library's tests. +Oauth2(for python3):: + pip install -e https://github.com/hades/python-oauth2/tarball/python3#egg=oauth2 + Mock:: pip install mock @@ -37,7 +40,7 @@ To install:: Also, you can retrieve fresh version of python-odesk from GitHub:: - git clone git://github.com/odesk/python-odesk3.git + git clone git://github.com/vihtinsky/python-odesk3.git .. _settings: diff --git a/index.rst b/index.rst index b7f0af6..e7ce07b 100644 --- a/index.rst +++ b/index.rst @@ -19,7 +19,7 @@ Python3 bindings to oDesk API Urls ********************* -* Git repo: http://github.com/odesk/python-odesk3 -* Issues: http://github.com/odesk/python-odesk3/issues -* Documentation: http://odesk.github.com/python-odesk3/ +* Git repo: http://github.com/vihtinsky/python-odesk +* Issues: http://github.com/odesk/python-odesk/issues +* Documentation: http://odesk.github.com/python-odesk/ diff --git a/requirements.py b/requirements.py index cc5559a..9e1c3f8 100644 --- a/requirements.py +++ b/requirements.py @@ -1,3 +1,3 @@ nose mock -oauth2 +https://github.com/hades/python-oauth2/tarball/python3#egg=oauth2 From e02e90f2bccfd74b7663d5d41d4e1f88b0fc9158 Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 14:05:04 +0400 Subject: [PATCH 08/19] Fix updating of snapshot memo --- examples/user_snapshot.py | 28 +++++++++++++--------------- odesk/routers/team.py | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/examples/user_snapshot.py b/examples/user_snapshot.py index f03e7da..d8d4b52 100644 --- a/examples/user_snapshot.py +++ b/examples/user_snapshot.py @@ -9,34 +9,32 @@ PUBLIC_KEY = None SECRET_KEY = None -#TODO: Desktop app example (check if it's working at all - wasn't last time) def user_snapshots(public_key, secret_key): - print "Emulating web-based app" + print("Emulating web-based app") #Instantiating a client without an auth token client = odesk.Client(public_key, secret_key) - print "Please to this URL (authorize the app if necessary):" - print client.auth.auth_url() - print "After that you should be redirected back to your app URL with " + \ - "additional ?frob= parameter" - frob = raw_input('Enter frob: ') + print("Please to this URL (authorize the app if necessary):") + print(client.auth.auth_url()) + print("After that you should be redirected back to your app URL with " + \ + "additional ?frob= parameter") + frob = input('Enter frob: ') auth_token, user = client.auth.get_token(frob) - print "Authenticated user:" - print user + print("Authenticated user:") + print(user) #Instantiating a new client, now with a token. #Not strictly necessary here (could just set `client.auth_token`), but #typical for web apps, which wouldn't probably keep client instances #between requests client = odesk.Client(public_key, secret_key, auth_token) - print client.team.get_snapshot('company1', 'user1') - print client.team.update_snapshot('company1', 'user1', memo='Updated Memo') - print client.team.delete_snapshot('company1', 'user1', datetime=datetime.utcnow()) + print(client.team.get_snapshot('company1', 'user1')) + print(client.team.update_snapshot('company1', 'user1', memo='Updated Memo')) + print(client.team.delete_snapshot('company1', 'user1', datetime=datetime.utcnow())) - if __name__ == '__main__': - public_key = PUBLIC_KEY or raw_input('Enter public key: ') - secret_key = SECRET_KEY or raw_input('Enter secret key: ') + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') user_snapshots(public_key, secret_key) diff --git a/odesk/routers/team.py b/odesk/routers/team.py index dfd955f..b7ba651 100644 --- a/odesk/routers/team.py +++ b/odesk/routers/team.py @@ -80,7 +80,7 @@ def update_snapshot(self, company_id, user_id, datetime=None, url = 'snapshots/%s/%s' % (str(company_id), str(user_id)) if datetime: url += '/%s' % datetime.isoformat() - return self.post(url, {'memo': memo}) + return self.put(url, {'memo': memo}) def delete_snapshot(self, company_id, user_id, datetime=None): """ From 7f82b0606d25bbfd549141a6701e4cdfca501f17 Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 15:34:38 +0400 Subject: [PATCH 09/19] Fixed tests --- odesk/tests.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/odesk/tests.py b/odesk/tests.py index 97f08f1..f4ca0ff 100644 --- a/odesk/tests.py +++ b/odesk/tests.py @@ -78,7 +78,7 @@ def test_base_client(): def return_sample_json(): - return json.dumps(sample_json_dict) + return json.dumps(sample_json_dict).encode("utf-8") def patched_urlopen(request, *args, **kwargs): @@ -103,19 +103,19 @@ def test_base_client_urlopen(): {'url': 'http://test.url', 'data': {}, 'method': 'POST', - 'result_data': 'api_sig=ba343f176db8166c4b7e88911e7e46ec&api_key=public', + 'result_data': b'api_sig=ba343f176db8166c4b7e88911e7e46ec&api_key=public', 'result_url': 'http://test.url', 'result_method': 'POST'}, {'url': 'http://test.url', 'data': {}, 'method': 'PUT', - 'result_data': 'api_sig=52cbaea073a5d47abdffc7fc8ccd839b&api_key=public&http_method=put', + 'result_data': b'api_sig=52cbaea073a5d47abdffc7fc8ccd839b&api_key=public&http_method=put', 'result_url': 'http://test.url', 'result_method': 'POST'}, {'url': 'http://test.url', 'data': {}, 'method': 'DELETE', - 'result_data': 'api_sig=8621f072b1492fbd164d808307ba72b9&api_key=public&http_method=delete', + 'result_data': b'api_sig=8621f072b1492fbd164d808307ba72b9&api_key=public&http_method=delete', 'result_url': 'http://test.url', 'result_method': 'POST'}, ] @@ -329,7 +329,7 @@ def test_auth(): def return_frob_json(): - return json.dumps(frob_dict) + return json.dumps(frob_dict).encode("utf-8") def patched_urlopen_frob(request, *args, **kwargs): @@ -348,7 +348,7 @@ def test_auth_get_frob(): def return_token_json(): - return json.dumps(token_dict) + return json.dumps(token_dict).encode("utf-8") def patched_urlopen_token(request, *args, **kwargs): @@ -413,7 +413,7 @@ def test_check_token_false(): def return_teamrooms_json(): - return json.dumps(teamrooms_dict) + return json.dumps(teamrooms_dict).encode("utf-8") def patched_urlopen_teamrooms(request, *args, **kwargs): @@ -596,7 +596,7 @@ def test_team(): def return_hr_json(): - return json.dumps(hr_dict) + return json.dumps(hr_dict).encode("utf-8") def patched_urlopen_hr(request, *args, **kwargs): @@ -686,7 +686,7 @@ def test_get_hrv2_engagements(): def return_hradjustment_json(): - return json.dumps(adjustments) + return json.dumps(adjustments).encode("utf-8") def patched_urlopen_hradjustment(request, *args, **kwargs): @@ -747,7 +747,7 @@ def test_get_hrv2_candidacy_stats(): def return_provider_json(): - return json.dumps(provider_dict) + return json.dumps(provider_dict).encode("utf-8") def patched_urlopen_provider(request, *args, **kwargs): @@ -806,7 +806,7 @@ def test_provider(): def return_trays_json(): - return json.dumps(trays_dict) + return json.dumps(trays_dict).encode("utf-8") def patched_urlopen_trays(request, *args, **kwargs): @@ -832,7 +832,7 @@ def test_get_trays(): def return_tray_content_json(): - return json.dumps(tray_content_dict) + return json.dumps(tray_content_dict).encode("utf-8") def patched_urlopen_tray_content(request, *args, **kwargs): @@ -856,7 +856,7 @@ def test_get_tray_content(): def return_thread_content_json(): - return json.dumps(thread_content_dict) + return json.dumps(thread_content_dict).encode("utf-8") def patched_urlopen_thread_content(request, *args, **kwargs): @@ -880,7 +880,7 @@ def test_get_thread_content(): def return_read_thread_content_json(): - return json.dumps(read_thread_content_dict) + return json.dumps(read_thread_content_dict).encode("utf-8") def patched_urlopen_read_thread_content(request, *args, **kwargs): @@ -968,7 +968,7 @@ def test_post_message(): def return_read_timereport_json(*args, **kwargs): - return json.dumps(timereport_dict) + return json.dumps(timereport_dict).encode("utf-8") def patched_urlopen_timereport_content(request, *args, **kwargs): @@ -1038,7 +1038,7 @@ def test_get_agency_timereport(): def return_read_fin_report_json(*args, **kwargs): - return json.dumps(fin_report_dict) + return json.dumps(fin_report_dict).encode("utf-8") def patched_urlopen_fin_report_content(request, *args, **kwargs): @@ -1157,7 +1157,7 @@ def test_get_version(): def return_task_dict_json(*args, **kwargs): - return json.dumps(task_dict) + return json.dumps(task_dict).encode("utf-8") def patched_urlopen_task(request, *args, **kwargs): @@ -1375,7 +1375,7 @@ def test_gds_namespace(): def return_read_oconomy_json(*args, **kwargs): - return json.dumps(oconomy_dict) + return json.dumps(oconomy_dict).encode("utf-8") def patched_urlopen_oconomy_content(request, *args, **kwargs): @@ -1448,13 +1448,13 @@ def test_oauth_full_url(): def patched_httplib2_request(*args, **kwargs): return {'status': '200'},\ - 'oauth_callback_confirmed=1&oauth_token=709d434e6b37a25c50e95b0e57d24c46&oauth_token_secret=193ef27f57ab4e37' + b'oauth_callback_confirmed=1&oauth_token=709d434e6b37a25c50e95b0e57d24c46&oauth_token_secret=193ef27f57ab4e37' @patch('httplib2.Http.request', patched_httplib2_request) def test_oauth_get_request_token(): oa = setup_oauth() - assert oa.get_request_token() == ('709d434e6b37a25c50e95b0e57d24c46',\ - '193ef27f57ab4e37') + assert oa.get_request_token() == (b'709d434e6b37a25c50e95b0e57d24c46',\ + b'193ef27f57ab4e37') @patch('httplib2.Http.request', patched_httplib2_request) def test_oauth_get_authorize_url(): @@ -1466,7 +1466,7 @@ def test_oauth_get_authorize_url(): def patched_httplib2_access(*args, **kwargs): return {'status': '200'},\ - 'oauth_token=aedec833d41732a584d1a5b4959f9cd6&oauth_token_secret=9d9cccb363d2b13e' + b'oauth_token=aedec833d41732a584d1a5b4959f9cd6&oauth_token_secret=9d9cccb363d2b13e' @patch('httplib2.Http.request', patched_httplib2_access) def test_oauth_get_access_token(): @@ -1474,4 +1474,4 @@ def test_oauth_get_access_token(): oa.request_token = '709d434e6b37a25c50e95b0e57d24c46' oa.request_token_secret = '193ef27f57ab4e37' assert oa.get_access_token('9cbcbc19f8acc2d85a013e377ddd4118') ==\ - ('aedec833d41732a584d1a5b4959f9cd6', '9d9cccb363d2b13e') + (b'aedec833d41732a584d1a5b4959f9cd6', b'9d9cccb363d2b13e') From b78a30ca0efa0219dcbf2902df11d8767f2b330a Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 15:52:05 +0400 Subject: [PATCH 10/19] Finreport example --- examples/fin_reports.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/examples/fin_reports.py b/examples/fin_reports.py index 62aadd4..465320f 100644 --- a/examples/fin_reports.py +++ b/examples/fin_reports.py @@ -4,6 +4,7 @@ (C) 2010 oDesk """ import odesk +import odesk.utils from datetime import date @@ -14,31 +15,31 @@ #TODO: Desktop app example (check if it's working at all - wasn't last time) def fin_reports(public_key, secret_key): - print "Emulating web-based app" + print("Emulating web-based app") #Instantiating a client without an auth token client = odesk.Client(public_key, secret_key) - print "Please to this URL (authorize the app if necessary):" - print client.auth.auth_url() - print "After that you should be redirected back to your app URL with " + \ - "additional ?frob= parameter" - frob = raw_input('Enter frob: ') + print("Please to this URL (authorize the app if necessary):") + print(client.auth.auth_url()) + print("After that you should be redirected back to your app URL with " + \ + "additional ?frob= parameter") + frob = input('Enter frob: ') auth_token, user = client.auth.get_token(frob) - print "Authenticated user:" - print user - #Instantiating a new client, now with a token. - #Not strictly necessary here (could just set `client.auth_token`), but - #typical for web apps, which wouldn't probably keep client instances + print("Authenticated user:") + print(user) + #Instantiating a new client, now with a token. + #Not strictly necessary here (could just set `client.auth_token`), but + #typical for web apps, which wouldn't probably keep client instances #between requests client = odesk.Client(public_key, secret_key, auth_token) - print client.finreports.get_provider_billings('1111', - odesk.Query(select=['date', 'type', - 'amount'], - where=((odesk.Q('date') <= date.today())))) + print(client.finreport.get_provider_billings('11111', + odesk.utils.Query(select=['date', 'type', + 'amount'], + where=((odesk.utils.Q('date') <= date.today()))))) + - if __name__ == '__main__': - public_key = PUBLIC_KEY or raw_input('Enter public key: ') - secret_key = SECRET_KEY or raw_input('Enter secret key: ') + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') fin_reports(public_key, secret_key) From 9c7b043b954e54208d4198a4f929ed05ae5fa26c Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 18:34:41 +0400 Subject: [PATCH 11/19] Timereports and jobs examples --- examples/get_create_update_jobs.py | 26 ++++++------- examples/time_reports.py | 59 +++++++++++++++--------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/examples/get_create_update_jobs.py b/examples/get_create_update_jobs.py index af6d157..bc5eb30 100644 --- a/examples/get_create_update_jobs.py +++ b/examples/get_create_update_jobs.py @@ -12,17 +12,17 @@ #TODO: Desktop app example (check if it's working at all - wasn't last time) def hr_post_job(public_key, secret_key): - print "Emulating web-based app" + print("Emulating web-based app") #Instantiating a client without an auth token client = odesk.Client(public_key, secret_key) - print "Please to this URL (authorize the app if necessary):" - print client.auth.auth_url() - print "After that you should be redirected back to your app URL with " + \ - "additional ?frob= parameter" - frob = raw_input('Enter frob: ') + print("Please to this URL (authorize the app if necessary):") + print(client.auth.auth_url()) + print("After that you should be redirected back to your app URL with " + \ + "additional ?frob= parameter") + frob = input('Enter frob: ') auth_token, user = client.auth.get_token(frob) - print "Authenticated user:" - print user + print("Authenticated user:") + print(user) #Instantiating a new client, now with a token. #Not strictly necessary here (could just set `client.auth_token`), but #typical for web apps, which wouldn't probably keep client instances @@ -39,17 +39,17 @@ def hr_post_job(public_key, secret_key): 'subcategory': 'Other - Web Development', } try: - print client.hr.post_job(job_data) - except Exception, e: - print "Exception at %s %s" % (client.last_method, client.last_url) + print(client.hr.post_job(job_data)) + except Exception as e: + print("Exception at %s %s" % (client.last_method, client.last_url)) raise e if __name__ == '__main__': - public_key = PUBLIC_KEY or raw_input('Enter public key: ') - secret_key = SECRET_KEY or raw_input('Enter secret key: ') + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') hr_post_job(public_key, secret_key) diff --git a/examples/time_reports.py b/examples/time_reports.py index 040195c..2e99b6c 100644 --- a/examples/time_reports.py +++ b/examples/time_reports.py @@ -4,6 +4,7 @@ (C) 2010 oDesk """ import odesk +import odesk.utils from datetime import date PUBLIC_KEY = None @@ -12,41 +13,41 @@ #TODO: Desktop app example (check if it's working at all - wasn't last time) def time_reports(public_key, secret_key): - print "Emulating web-based app" + print("Emulating web-based app") #Instantiating a client without an auth token client = odesk.Client(public_key, secret_key) - print "Please to this URL (authorize the app if necessary):" - print client.auth.auth_url() - print "After that you should be redirected back to your app URL with " + \ - "additional ?frob= parameter" - frob = raw_input('Enter frob: ') + print("Please to this URL (authorize the app if necessary):") + print(client.auth.auth_url()) + print("After that you should be redirected back to your app URL with " + \ + "additional ?frob= parameter") + frob = input('Enter frob: ') auth_token, user = client.auth.get_token(frob) - print "Authenticated user:" - print user - #Instantiating a new client, now with a token. - #Not strictly necessary here (could just set `client.auth_token`), but - #typical for web apps, which wouldn't probably keep client instances + print("Authenticated user:") + print(user) + #Instantiating a new client, now with a token. + #Not strictly necessary here (could just set `client.auth_token`), but + #typical for web apps, which wouldn't probably keep client instances #between requests client = odesk.Client(public_key, secret_key, auth_token) - print client.time_reports.get_provider_report('user1', - odesk.Query(select=odesk.Query.DEFAULT_TIMEREPORT_FIELDS, - where=(odesk.Q('worked_on') <= date.today()) &\ - (odesk.Q('worked_on') > '2010-05-01'))) - - print client.time_reports.get_provider_report('user1', - odesk.Query(select=odesk.Query.DEFAULT_TIMEREPORT_FIELDS, - where=(odesk.Q('worked_on') <= date.today()) &\ - (odesk.Q('worked_on') > '2010-05-01')), hours=True) - - print client.time_reports.get_agency_report('company1', 'agency1', - odesk.Query(select=odesk.Query.DEFAULT_TIMEREPORT_FIELDS, - where=(odesk.Q('worked_on') <= date.today()) &\ - (odesk.Q('worked_on') > '2010-05-01')), hours=True) - - + print(client.timereport.get_provider_report('user1', + odesk.utils.Query(select=odesk.utils.Query.DEFAULT_TIMEREPORT_FIELDS, + where=(odesk.utils.Q('worked_on') <= date.today()) &\ + (odesk.utils.Q('worked_on') > '2012-05-01')))) + + print(client.timereport.get_provider_report('user1', + odesk.utils.Query(select=odesk.utils.Query.DEFAULT_TIMEREPORT_FIELDS, + where=(odesk.utils.Q('worked_on') <= date.today()) &\ + (odesk.utils.Q('worked_on') > '2012-05-01')), hours=True)) + + print(client.timereport.get_agency_report('company1', 'agency1', + odesk.utils.Query(select=odesk.utils.Query.DEFAULT_TIMEREPORT_FIELDS, + where=(odesk.utils.Q('worked_on') <= date.today()) &\ + (odesk.utils.Q('worked_on') > '2010-05-01')), hours=True)) + + if __name__ == '__main__': - public_key = PUBLIC_KEY or raw_input('Enter public key: ') - secret_key = SECRET_KEY or raw_input('Enter secret key: ') + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') time_reports(public_key, secret_key) From c36ae9d2f945573665ff639691a737934f643bcf Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 19:42:17 +0400 Subject: [PATCH 12/19] Provider example --- examples/provider.py | 62 +++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/examples/provider.py b/examples/provider.py index dfb3f4d..2e89694 100644 --- a/examples/provider.py +++ b/examples/provider.py @@ -9,50 +9,42 @@ PUBLIC_KEY = None SECRET_KEY = None + #TODO: Desktop app example (check if it's working at all - wasn't last time) def provider(public_key, secret_key): - print "Emulating web-based app" + print("Emulating web-based app") #Instantiating a client without an auth token client = odesk.Client(public_key, secret_key) - print "Please to this URL (authorize the app if necessary):" - print client.auth.auth_url() - print "After that you should be redirected back to your app URL with " + \ - "additional ?frob= parameter" - frob = raw_input('Enter frob: ') + print("Please to this URL (authorize the app if necessary):") + print(client.auth.auth_url()) + print("After that you should be redirected back to your app URL with " + \ + "additional ?frob= parameter") + frob = input('Enter frob: ') auth_token, user = client.auth.get_token(frob) - print "Authenticated user:" - print user - #Instantiating a new client, now with a token. - #Not strictly necessary here (could just set `client.auth_token`), but - #typical for web apps, which wouldn't probably keep client instances + print("Authenticated user:") + print(user) + #Instantiating a new client, now with a token. + #Not strictly necessary here (could just set `client.auth_token`), but + #typical for web apps, which wouldn't probably keep client instances #between requests client = odesk.Client(public_key, secret_key, auth_token) - # get skills - print "Provider skills:" - print client.provider.get_skills('~~someref') - # add new skill - print "Adding provider skill" - print client.provider.add_skill('~~someref', {'skill':'skill'}) - # update a skill by giving a skill_id and new data - print "Updating provider skill" - print client.provider.update_skill('~~someref', 123, {'skill':'skill'}) - # delete a skill by giving a skill_id - print "Deleting provider skill" - print client.provider.delete_skill('~~someref', 123) - # get quickinfo - print "Get quick info" - print client.provider.get_quickinfo('~~someref') - # update a quickinfo by giving new data - client.provider.update_quickinfo('~~someref', {'skill':'skill'}) - print client.provider.get_affiliates('someref') - print "Revoke access" - print client.auth.revoke_token() - - + print("Search providers:") + print(client.provider.get_providers({'q':'python'})) + print("Search jobs:") + print(client.provider.get_jobs({'q':'wowza'})) + print("Provider all:") + #someref is like 71de2d463c748623 + print(client.provider.get_provider('~~someref')) + print("Provider brief:") + print(client.provider.get_provider_brief('~~someref')) + print("Revoke access") + print(client.auth.revoke_token()) + + if __name__ == '__main__': - public_key = PUBLIC_KEY or raw_input('Enter public key: ') - secret_key = SECRET_KEY or raw_input('Enter secret key: ') + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') provider(public_key, secret_key) From 93adfaf72be659c79f0f20ae2b362c8de506de57 Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 20:06:03 +0400 Subject: [PATCH 13/19] simple_messager example --- examples/simple_messager.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/simple_messager.py b/examples/simple_messager.py index 7d49194..00a3af6 100644 --- a/examples/simple_messager.py +++ b/examples/simple_messager.py @@ -12,33 +12,33 @@ #TODO: Desktop app example (check if it's working at all - wasn't last time) def simple_messager(public_key, secret_key): - print "Emulating web-based app" + print("Emulating web-based app") #Instantiating a client without an auth token client = odesk.Client(public_key, secret_key) - print "Please to this URL (authorize the app if necessary):" - print client.auth.auth_url() - print "After that you should be redirected back to your app URL with " + \ - "additional ?frob= parameter" - frob = raw_input('Enter frob: ') + print("Please to this URL (authorize the app if necessary):") + print(client.auth.auth_url()) + print("After that you should be redirected back to your app URL with " + \ + "additional ?frob= parameter") + frob = input('Enter frob: ') auth_token, user = client.auth.get_token(frob) - print "Authenticated user:" - print user - #Instantiating a new client, now with a token. - #Not strictly necessary here (could just set `client.auth_token`), but - #typical for web apps, which wouldn't probably keep client instances + print("Authenticated user:") + print(user) + #Instantiating a new client, now with a token. + #Not strictly necessary here (could just set `client.auth_token`), but + #typical for web apps, which wouldn't probably keep client instances #between requests client = odesk.Client(public_key, secret_key, auth_token) - print client.mc.get_trays() - #print client.mc.get_tray_content('username', 'inbox') - #print client.mc.get_thread_content('username', '00') - print client.mc.post_message('username', 'username2', 'test from api', 'test body') + print(client.mc.get_trays()) + #print(client.mc.get_tray_content('my_username', 'inbox')) + #print(client.mc.get_thread_content('my_username', '111111')) + print(client.mc.post_message('sender', 'recipient', 'test from api', 'test body')) if __name__ == '__main__': - public_key = PUBLIC_KEY or raw_input('Enter public key: ') - secret_key = SECRET_KEY or raw_input('Enter secret key: ') + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') simple_messager(public_key, secret_key) From 37f64e14dec0230f6bc5bd974a616f2361bcba61 Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 21:17:38 +0400 Subject: [PATCH 14/19] Fix PUT, POST and DELETE with oAuth --- odesk/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/odesk/__init__.py b/odesk/__init__.py index 55cafca..244f152 100644 --- a/odesk/__init__.py +++ b/odesk/__init__.py @@ -90,8 +90,9 @@ def urlopen(self, url, data={}, method='GET'): self.last_data = data if isinstance(self.auth, OAuth): + http_method = 'GET' if method=='GET' else 'POST' query = self.auth.urlencode(url, self.oauth_access_token,\ - self.oauth_access_token_secret, data) + self.oauth_access_token_secret, data, http_method) else: query = self.urlencode(data) From 235412dcc7a938237dcdf10eece589df871f946e Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Thu, 7 Jun 2012 21:56:47 +0400 Subject: [PATCH 15/19] Fix tasks with oAuth. Tasks example. --- examples/tasks.py | 59 +++++++++++++++++++++++++++++++++++++++++++ odesk/routers/task.py | 4 ++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 examples/tasks.py diff --git a/examples/tasks.py b/examples/tasks.py new file mode 100644 index 0000000..b537ac8 --- /dev/null +++ b/examples/tasks.py @@ -0,0 +1,59 @@ +import odesk +#oAuth key +PUBLIC_KEY = None +SECRET_KEY = None + + +def web_based_app(public_key, secret_key): + print ("Emulating web-based app") + #Instantiating a client without an auth token + client = odesk.Client(public_key, secret_key, auth='oauth') + + print ("Please to this URL (authorize the app if necessary):") + print (client.auth.get_authorize_url()) + + print ("After that you should be redirected back to your app URL with " + \ + "additional ?oauth_verifier= parameter") + verifier = input('Enter oauth_verifier: ') + + oauth_access_token, oauth_access_token_secret = client.auth.get_access_token(verifier) + + #Instantiating a new client, now with a token. + #Not strictly necessary here (could just set `client.oauth_access_token` + #and `client.oauth_access_token_secret`), but typical for web apps, + #which wouldn't probably keep client instances between requests + + client = odesk.Client(public_key, secret_key, auth='oauth', + oauth_access_token=oauth_access_token, + oauth_access_token_secret=oauth_access_token_secret) + + try: + print ("Tasks list:") + print (client.task.get_user_tasks('company_id', 'team_id', 'user_id')) + #Post new task + print(client.task.post_user_task(company_id='company', + team_id='team', user_id='provider', code='TEST_TASK', + description='Test api task', url='http://task_url.py' + )) + #Update task + print(client.task.post_user_task(company_id='company', + team_id='team', user_id='provider', code='TEST_TASK', + description='Test api updated', url='http://task_url.py' + )) + #Should be list of task_codes. If one task list of 1 element + print(client.task.delete_user_task(company_id='company', + team_id='team', user_id='provider', task_codes=["TEST_TASK", "TASK_2"] + )) + + except Exception as e: + print ("Exception at %s %s" % (client.last_method, client.last_url)) + raise e + + + +if __name__ == '__main__': + public_key = PUBLIC_KEY or input('Enter public key: ') + secret_key = SECRET_KEY or input('Enter secret key: ') + + web_based_app(public_key, secret_key) + diff --git a/odesk/routers/task.py b/odesk/routers/task.py index a02458c..174f3e6 100644 --- a/odesk/routers/task.py +++ b/odesk/routers/task.py @@ -105,7 +105,9 @@ def get_user_tasks_full(self, company_id, team_id, user_id): return result["tasks"] or [] def _generate_many_tasks_url(self, task_codes): - return ';'.join(urllib.parse.quote(str(c)) for c in task_codes) + tasks = ';'.join(urllib.parse.quote(str(c)) for c in task_codes) + #for correct work of oAuth signing + return urllib.parse.quote(tasks) def get_company_specific_tasks(self, company_id, task_codes): """ From 2a184c912fbc4d9b0bd877dc3f0eb0a2914ba533 Mon Sep 17 00:00:00 2001 From: Ilia Vihtinsky Date: Mon, 8 Apr 2013 13:04:47 +0400 Subject: [PATCH 16/19] Update namespaces.py Use oAuth in GdsNamespace.urlopen --- odesk/namespaces.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/odesk/namespaces.py b/odesk/namespaces.py index c3431f6..da35a38 100644 --- a/odesk/namespaces.py +++ b/odesk/namespaces.py @@ -47,14 +47,31 @@ class GdsNamespace(Namespace): base_url = 'https://www.odesk.com/gds/' def urlopen(self, url, data={}, method='GET'): + from odesk.oauth import OAuth data = data.copy() - query = self.client.urlencode(data) + + #FIXME: Http method hack. Should be removed once oDesk supports true + #HTTP methods + if method in ['PUT', 'DELETE']: + data['http_method'] = method.lower() + #End of hack + + self.client.last_method = method + self.client.last_url = url + self.client.last_data = data + + if isinstance(self.client.auth, OAuth): + query = self.client.auth.urlencode(url, self.client.oauth_access_token,\ + self.client.oauth_access_token_secret, data) + else: + query = self.client.urlencode(data) if method == 'GET': url += '?' + query request = HttpRequest(url=url, data=None, method=method) - return urllib.request.urlopen(request) + return urllib2.urlopen(request) return None + def read(self, url, data={}, method='GET'): """ Returns parsed Python object or raises an error From fc3b8d2acd0cf260d5b34ff9bc7208d61644905c Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Fri, 9 Aug 2013 14:24:08 +0400 Subject: [PATCH 17/19] Modify setup.py for 2to3 --- setup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d893da3..7924807 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,10 @@ import os +import sys +if sys.version_info[0] == 3: + import setuptools + if setuptools.__version__ < "0.7": + print("This setup.py requeries setuptools>=0.7\n") + sys.exit(0) from setuptools import setup, find_packages readme = open(os.path.join(os.path.dirname(__file__), 'README')) @@ -15,8 +21,9 @@ author='oDesk', author_email='python@odesk.com', maintainer='Volodymyr Hotsyk', + use_2to3 = True, maintainer_email='gotsyk@gmail.com', - install_requires=['oauth2',], + install_requires=['oauth2', 'mock', 'nose'], dependency_links = ['https://github.com/hades/python-oauth2/tarball/python3#egg=oauth2',], packages=find_packages(), license = 'BSD', From dab07f912f4d7e1ccd20bcf66ceab66aade987c2 Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Fri, 9 Aug 2013 19:59:45 +0400 Subject: [PATCH 18/19] Support python2 and python3(with 2to3) --- odesk/__init__.py | 24 ++++--- odesk/exceptions.py | 10 +-- odesk/http.py | 6 +- odesk/namespaces.py | 6 +- odesk/oauth.py | 10 +-- odesk/routers/mc.py | 4 +- odesk/routers/task.py | 6 +- odesk/tests.py | 160 +++++++++++++++++++++--------------------- 8 files changed, 117 insertions(+), 109 deletions(-) diff --git a/odesk/__init__.py b/odesk/__init__.py index 244f152..6046e36 100644 --- a/odesk/__init__.py +++ b/odesk/__init__.py @@ -23,7 +23,7 @@ def get_version(): import hashlib import logging -import urllib.request, urllib.parse, urllib.error +import urllib2, urllib import json from odesk.auth import Auth @@ -33,6 +33,14 @@ def get_version(): __all__ = ["get_version", "Client", "utils"] +def _utf8_str(obj): + try: + return unicode(obj).encode("utf8") + except UnicodeDecodeError, e: + # input could be an utf8 encoded + logging.debug(e) + obj.decode("utf8") # check if it is a valid utf8 string + return obj def signed_urlencode(secret, query={}): """ @@ -43,18 +51,18 @@ def signed_urlencode(secret, query={}): >>> signed_urlencode('some$ecret', {'spam':42,'foo':'bar'}) 'api_sig=11b1fc2e6555297bdc144aed0a5e641c&foo=bar&spam=42' """ - message = secret + message = _utf8_str(secret) for key in sorted(query.keys()): try: - message += str(key) + str(query[key]) + message += _utf8_str(key) + _utf8_str(query[key]) except Exception as e: logging.debug("[python-odesk] Error while trying to sign key: %s and query %s" % (key, query[key])) raise e _query = {} - _query['api_sig'] = hashlib.md5(message.encode('utf-8')).hexdigest() + _query['api_sig'] = hashlib.md5(message).hexdigest() for k, v in query.items(): - _query[k] = str(v) - return urllib.parse.urlencode(_query) + _query[_utf8_str(k)] = _utf8_str(v) + return urllib.urlencode(_query) class BaseClient(object): @@ -101,7 +109,7 @@ def urlopen(self, url, data={}, method='GET'): request = HttpRequest(url=url, data=None, method=method) else: request = HttpRequest(url=url, data=query.encode("utf-8"), method=method) - return urllib.request.urlopen(request) + return urllib2.urlopen(request) def read(self, url, data={}, method='GET', format='json'): """ @@ -111,7 +119,7 @@ def read(self, url, data={}, method='GET', format='json'): url += '.' + format try: response = self.urlopen(url, data, method) - except urllib.error.HTTPError as e: + except urllib2.HTTPError as e: raise_http_error(e) if format == 'json': diff --git a/odesk/exceptions.py b/odesk/exceptions.py index 183d211..6838e57 100644 --- a/odesk/exceptions.py +++ b/odesk/exceptions.py @@ -5,7 +5,7 @@ """ import logging -import urllib.request, urllib.error, urllib.parse +import urllib2, urllib class BaseException(Exception): @@ -14,19 +14,19 @@ def __init__(self, *args, **kwargs): super(BaseException, self).__init__() -class HTTP400BadRequestError(urllib.error.HTTPError, BaseException): +class HTTP400BadRequestError(urllib2.HTTPError, BaseException): pass -class HTTP401UnauthorizedError(urllib.error.HTTPError, BaseException): +class HTTP401UnauthorizedError(urllib2.HTTPError, BaseException): pass -class HTTP403ForbiddenError(urllib.error.HTTPError, BaseException): +class HTTP403ForbiddenError(urllib2.HTTPError, BaseException): pass -class HTTP404NotFoundError(urllib.error.HTTPError, BaseException): +class HTTP404NotFoundError(urllib2.HTTPError, BaseException): pass diff --git a/odesk/http.py b/odesk/http.py index 09d7dbd..c1b9869 100644 --- a/odesk/http.py +++ b/odesk/http.py @@ -4,7 +4,7 @@ (C) 2012 oDesk """ -import urllib.request +import urllib2 from odesk.exceptions import (HTTP400BadRequestError, HTTP401UnauthorizedError, HTTP403ForbiddenError, HTTP404NotFoundError) @@ -28,7 +28,7 @@ def raise_http_error(e): raise e -class HttpRequest(urllib.request.Request): +class HttpRequest(urllib2.Request): """ A hack around Request class that allows to specify HTTP method explicitly """ @@ -36,7 +36,7 @@ class HttpRequest(urllib.request.Request): def __init__(self, *args, **kwargs): #Request is an old-style class, so can't use `super` method = kwargs.pop('method', 'GET') - urllib.request.Request.__init__(self, *args, **kwargs) + urllib2.Request.__init__(self, *args, **kwargs) self.method = method def get_method(self): diff --git a/odesk/namespaces.py b/odesk/namespaces.py index da35a38..5de898e 100644 --- a/odesk/namespaces.py +++ b/odesk/namespaces.py @@ -4,7 +4,7 @@ (C) 2012 oDesk """ -import urllib.request, urllib.error +import urllib2 import json from odesk.http import raise_http_error, HttpRequest @@ -78,7 +78,7 @@ def read(self, url, data={}, method='GET'): """ try: response = self.urlopen(url, data, method) - except urllib.error.HTTPError as e: + except urllib2.HTTPError as e: raise_http_error(e) result = json.loads(response.read().decode("utf-8")) @@ -99,5 +99,5 @@ def urlopen(self, url, data={}, method='GET'): query = self.client.urlencode(data) url += '?' + query request = HttpRequest(url=url, data=None, method=method) - return urllib.request.urlopen(request) + return urllib2.urlopen(request) return None diff --git a/odesk/oauth.py b/odesk/oauth.py index 00ff4f8..4da366a 100644 --- a/odesk/oauth.py +++ b/odesk/oauth.py @@ -5,7 +5,7 @@ """ import time -import urllib.parse +import urlparse, urllib import oauth2 as oauth @@ -58,7 +58,7 @@ def get_request_token(self): response, content = client.request(self.request_token_url, 'POST') if response.get('status') != '200': raise Exception("Invalid request token response: %s." % content) - request_token = dict(urllib.parse.parse_qsl(content)) + request_token = dict(urlparse.parse_qsl(content)) self.request_token = request_token.get(b'oauth_token') self.request_token_secret = request_token.get(b'oauth_token_secret') return self.request_token, self.request_token_secret @@ -70,10 +70,10 @@ def get_authorize_url(self, callback_url=None): oauth_token = getattr(self, 'request_token', None) or\ self.get_request_token()[0] if callback_url: - params = urllib.parse.urlencode({'oauth_token': oauth_token,\ + params = urllib.urlencode({'oauth_token': oauth_token,\ 'oauth_callback': callback_url}) else: - params = urllib.parse.urlencode({'oauth_token': oauth_token}) + params = urllib.urlencode({'oauth_token': oauth_token}) return '%s?%s' % (self.authorize_url, params) def get_access_token(self, verifier): @@ -91,7 +91,7 @@ def get_access_token(self, verifier): response, content = client.request(self.access_token_url, 'POST') if response.get('status') != '200': raise Exception("Invalid access token response: %s." % content) - access_token = dict(urllib.parse.parse_qsl(content)) + access_token = dict(urlparse.parse_qsl(content)) self.access_token = access_token.get(b'oauth_token') self.access_token_secret = access_token.get(b'oauth_token_secret') return self.access_token, self.access_token_secret diff --git a/odesk/routers/mc.py b/odesk/routers/mc.py index d17a3a5..b989622 100644 --- a/odesk/routers/mc.py +++ b/odesk/routers/mc.py @@ -4,7 +4,7 @@ (C) 2012 oDesk """ -import urllib.parse +import urllib from odesk.namespaces import Namespace @@ -75,7 +75,7 @@ def get_thread_content(self, username, thread_id, paging_offset=0, return result["thread"] def _generate_many_threads_url(self, threads_ids): - return ';'.join(urllib.parse.quote(str(i)) for i in threads_ids) + return ';'.join(urllib.quote(str(i)) for i in threads_ids) def put_threads_read_unread(self, username, thread_ids, read=True): """ diff --git a/odesk/routers/task.py b/odesk/routers/task.py index 174f3e6..a0e0817 100644 --- a/odesk/routers/task.py +++ b/odesk/routers/task.py @@ -4,7 +4,7 @@ (C) 2012 oDesk """ -import urllib.parse +import urllib from odesk.namespaces import Namespace @@ -105,9 +105,9 @@ def get_user_tasks_full(self, company_id, team_id, user_id): return result["tasks"] or [] def _generate_many_tasks_url(self, task_codes): - tasks = ';'.join(urllib.parse.quote(str(c)) for c in task_codes) + tasks = ';'.join(urllib.quote(str(c)) for c in task_codes) #for correct work of oAuth signing - return urllib.parse.quote(tasks) + return urllib.quote(tasks) def get_company_specific_tasks(self, company_id, task_codes): """ diff --git a/odesk/tests.py b/odesk/tests.py index f4ca0ff..4da4ec1 100644 --- a/odesk/tests.py +++ b/odesk/tests.py @@ -12,7 +12,7 @@ from odesk.routers.team import Team from mock import Mock, patch -import urllib.request, urllib.error, urllib.parse +import urllib2, urllib try: import json @@ -86,7 +86,7 @@ def patched_urlopen(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen) +@patch('urllib2.urlopen', patched_urlopen) def test_base_client_urlopen(): public_key = 'public' secret_key = 'secret' @@ -136,7 +136,7 @@ def test_base_client_urlopen(): def patched_urlopen_error(request, code=400, *args, **kwargs): - raise urllib.error.HTTPError(url=request.get_full_url(), + raise urllib2.HTTPError(url=request.get_full_url(), code=code, msg=str(code), hdrs='', fp=None) @@ -160,32 +160,32 @@ def patched_urlopen_500(request, *args, **kwargs): return patched_urlopen_error(request, 500, *args, **kwargs) -@patch('urllib.request.urlopen', patched_urlopen_400) +@patch('urllib2.urlopen', patched_urlopen_400) def base_client_read_400(bc, url): return bc.read(url) -@patch('urllib.request.urlopen', patched_urlopen_401) +@patch('urllib2.urlopen', patched_urlopen_401) def base_client_read_401(bc, url): return bc.read(url) -@patch('urllib.request.urlopen', patched_urlopen_403) +@patch('urllib2.urlopen', patched_urlopen_403) def base_client_read_403(bc, url): return bc.read(url) -@patch('urllib.request.urlopen', patched_urlopen_404) +@patch('urllib2.urlopen', patched_urlopen_404) def base_client_read_404(bc, url): return bc.read(url) -@patch('urllib.request.urlopen', patched_urlopen_500) +@patch('urllib2.urlopen', patched_urlopen_500) def base_client_read_500(bc, url): return bc.read(url) -@patch('urllib.request.urlopen', patched_urlopen) +@patch('urllib2.urlopen', patched_urlopen) def test_base_client_read(): """ test cases: @@ -250,7 +250,7 @@ class NotJsonException(Exception): #test get, 500 error try: result = base_client_read_500(bc=bc, url=test_url) - except urllib.error.HTTPError as e: + except urllib2.HTTPError as e: if e.code == 500: pass else: @@ -266,7 +266,7 @@ def get_client(): return Client(public_key, secret_key, api_token) -@patch('urllib.request.urlopen', patched_urlopen) +@patch('urllib2.urlopen', patched_urlopen) def test_client(): c = get_client() test_url = "http://test.url" @@ -284,7 +284,7 @@ def test_client(): assert result == sample_json_dict, result -@patch('urllib.request.urlopen', patched_urlopen) +@patch('urllib2.urlopen', patched_urlopen) def test_namespace(): ns = Namespace(get_client()) test_url = "http://test.url" @@ -337,7 +337,7 @@ def patched_urlopen_frob(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_frob) +@patch('urllib2.urlopen', patched_urlopen_frob) def test_auth_get_frob(): #test get_frob au = setup_auth() @@ -356,7 +356,7 @@ def patched_urlopen_token(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_token) +@patch('urllib2.urlopen', patched_urlopen_token) def test_auth_get_token(): #test get_frob au = setup_auth() @@ -365,7 +365,7 @@ def test_auth_get_token(): assert auth_user == token_dict['auth_user'], auth_user -@patch('urllib.request.urlopen', patched_urlopen_token) +@patch('urllib2.urlopen', patched_urlopen_token) def test_check_token_true(): #check if ok au = setup_auth() @@ -377,14 +377,14 @@ def test_check_token_true(): assert "Not Raised" -@patch('urllib.request.urlopen', patched_urlopen_token) +@patch('urllib2.urlopen', patched_urlopen_token) def test_revoke_token_true(): #check if ok au = setup_auth() assert au.revoke_token(), au.revoke_token() -@patch('urllib.request.urlopen', patched_urlopen_403) +@patch('urllib2.urlopen', patched_urlopen_403) def test_check_token_false(): #check if denied au = setup_auth() @@ -421,7 +421,7 @@ def patched_urlopen_teamrooms(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_teamrooms) +@patch('urllib2.urlopen', patched_urlopen_teamrooms) def test_team(): te = Team(get_client()) @@ -604,7 +604,7 @@ def patched_urlopen_hr(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_user(): hr = get_client().hr @@ -612,7 +612,7 @@ def test_get_hrv2_user(): assert hr.get_user(1) == hr_dict['user'], hr.get_user(1) -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_companies(): hr = get_client().hr #test get_companies @@ -622,14 +622,14 @@ def test_get_hrv2_companies(): assert hr.get_company(1) == hr_dict['company'], hr.get_company(1) -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_company_teams(): hr = get_client().hr #test get_company_teams assert hr.get_company_teams(1) == hr_dict['teams'], hr.get_company_teams(1) -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_company_users(): hr = get_client().hr #test get_company_users @@ -637,7 +637,7 @@ def test_get_hrv2_company_users(): assert hr.get_company_users(1, False) == hr_dict['users'], \ hr.get_company_users(1, False) -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_teams(): hr = get_client().hr #test get_teams @@ -647,7 +647,7 @@ def test_get_hrv2_teams(): assert hr.get_team(1) == hr_dict['team'], hr.get_team(1) -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_team_users(): hr = get_client().hr #test get_team_users @@ -656,7 +656,7 @@ def test_get_hrv2_team_users(): hr.get_team_users(1, False) -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_jobs(): hr = get_client().hr #test get_jobs @@ -666,7 +666,7 @@ def test_get_hrv2_jobs(): assert hr.delete_job(1, 41) == hr_dict, hr.delete_job(1, 41) -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_offers(): hr = get_client().hr #test get_offers @@ -674,7 +674,7 @@ def test_get_hrv2_offers(): assert hr.get_offer(1) == hr_dict['offer'], hr.get_offer(1) -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_engagements(): hr = get_client().hr #test get_engagements @@ -694,7 +694,7 @@ def patched_urlopen_hradjustment(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_hradjustment) +@patch('urllib2.urlopen', patched_urlopen_hradjustment) def test_hrv2_post_adjustment(): hr = get_client().hr @@ -702,7 +702,7 @@ def test_hrv2_post_adjustment(): assert result == adjustments['adjustment'], result -@patch('urllib.request.urlopen', patched_urlopen_hr) +@patch('urllib2.urlopen', patched_urlopen_hr) def test_get_hrv2_candidacy_stats(): hr = get_client().hr #test get_candidacy_stats @@ -755,7 +755,7 @@ def patched_urlopen_provider(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_provider) +@patch('urllib2.urlopen', patched_urlopen_provider) def test_provider(): pr = get_client().provider @@ -814,7 +814,7 @@ def patched_urlopen_trays(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_trays) +@patch('urllib2.urlopen', patched_urlopen_trays) def test_get_trays(): mc = get_client().mc @@ -840,7 +840,7 @@ def patched_urlopen_tray_content(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_tray_content) +@patch('urllib2.urlopen', patched_urlopen_tray_content) def test_get_tray_content(): mc = get_client().mc @@ -864,7 +864,7 @@ def patched_urlopen_thread_content(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_thread_content) +@patch('urllib2.urlopen', patched_urlopen_thread_content) def test_get_thread_content(): mc = get_client().mc @@ -888,7 +888,7 @@ def patched_urlopen_read_thread_content(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_read_thread_content) +@patch('urllib2.urlopen', patched_urlopen_read_thread_content) def test_put_threads_read_unread(): mc = get_client().mc @@ -902,7 +902,7 @@ def test_put_threads_read_unread(): assert read == read_thread_content_dict, read -@patch('urllib.request.urlopen', patched_urlopen_read_thread_content) +@patch('urllib2.urlopen', patched_urlopen_read_thread_content) def test_put_threads_starred_unstarred(): mc = get_client().mc @@ -913,7 +913,7 @@ def test_put_threads_starred_unstarred(): assert unstarred == read_thread_content_dict, unstarred -@patch('urllib.request.urlopen', patched_urlopen_read_thread_content) +@patch('urllib2.urlopen', patched_urlopen_read_thread_content) def test_put_threads_deleted_undeleted(): mc = get_client().mc @@ -924,7 +924,7 @@ def test_put_threads_deleted_undeleted(): assert undeleted == read_thread_content_dict, undeleted -@patch('urllib.request.urlopen', patched_urlopen_read_thread_content) +@patch('urllib2.urlopen', patched_urlopen_read_thread_content) def test_post_message(): mc = get_client().mc @@ -976,7 +976,7 @@ def patched_urlopen_timereport_content(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_timereport_content) +@patch('urllib2.urlopen', patched_urlopen_timereport_content) def test_get_provider_timereport(): tc = get_client().timereport @@ -990,7 +990,7 @@ def test_get_provider_timereport(): assert read == timereport_dict, read -@patch('urllib.request.urlopen', patched_urlopen_timereport_content) +@patch('urllib2.urlopen', patched_urlopen_timereport_content) def test_get_company_timereport(): tc = get_client().timereport @@ -1004,7 +1004,7 @@ def test_get_company_timereport(): assert read == timereport_dict, read -@patch('urllib.request.urlopen', patched_urlopen_timereport_content) +@patch('urllib2.urlopen', patched_urlopen_timereport_content) def test_get_agency_timereport(): tc = get_client().timereport @@ -1046,7 +1046,7 @@ def patched_urlopen_fin_report_content(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_provider_billings(): fr = get_client().finreport @@ -1054,7 +1054,7 @@ def test_get_provider_billings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_provider_teams_billings(): fr = get_client().finreport @@ -1062,7 +1062,7 @@ def test_get_provider_teams_billings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_provider_companies_billings(): fr = get_client().finreport @@ -1070,7 +1070,7 @@ def test_get_provider_companies_billings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_provider_earnings(): fr = get_client().finreport @@ -1078,7 +1078,7 @@ def test_get_provider_earnings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_provider_teams_earnings(): fr = get_client().finreport @@ -1086,7 +1086,7 @@ def test_get_provider_teams_earnings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_provider_companies_earnings(): fr = get_client().finreport @@ -1094,7 +1094,7 @@ def test_get_provider_companies_earnings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_buyer_teams_billings(): fr = get_client().finreport @@ -1102,7 +1102,7 @@ def test_get_buyer_teams_billings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_buyer_companies_billings(): fr = get_client().finreport @@ -1110,7 +1110,7 @@ def test_get_buyer_companies_billings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_buyer_teams_earnings(): fr = get_client().finreport @@ -1118,7 +1118,7 @@ def test_get_buyer_teams_earnings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_buyer_companies_earnings(): fr = get_client().finreport @@ -1126,7 +1126,7 @@ def test_get_buyer_companies_earnings(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_financial_entities(): fr = get_client().finreport @@ -1134,7 +1134,7 @@ def test_get_financial_entities(): assert read == fin_report_dict, read -@patch('urllib.request.urlopen', patched_urlopen_fin_report_content) +@patch('urllib2.urlopen', patched_urlopen_fin_report_content) def test_get_financial_entities_provider(): fr = get_client().finreport @@ -1165,7 +1165,7 @@ def patched_urlopen_task(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_get_company_tasks(): task = get_client().task @@ -1173,7 +1173,7 @@ def test_get_company_tasks(): task.get_company_tasks(1) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_get_team_tasks(): task = get_client().task @@ -1181,7 +1181,7 @@ def test_get_team_tasks(): task.get_team_tasks(1, 1) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_get_user_tasks(): task = get_client().task @@ -1189,7 +1189,7 @@ def test_get_user_tasks(): task.get_user_tasks(1, 1, 1) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_company_tasks_full(): task = get_client().task @@ -1197,7 +1197,7 @@ def test_company_tasks_full(): task.get_company_tasks_full(1) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_get_team_tasks_full(): task = get_client().task @@ -1205,7 +1205,7 @@ def test_get_team_tasks_full(): task.get_team_tasks_full(1, 1) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_get_user_tasks_full(): task = get_client().task @@ -1213,7 +1213,7 @@ def test_get_user_tasks_full(): task.get_user_tasks_full(1, 1, 1) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_get_company_specific_tasks(): task = get_client().task @@ -1221,7 +1221,7 @@ def test_get_company_specific_tasks(): task.get_company_specific_tasks(1, [1, 1]) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_get_team_specific_tasks(): task = get_client().task @@ -1229,7 +1229,7 @@ def test_get_team_specific_tasks(): task.get_team_specific_tasks(1, 1, [1, 1]) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_get_user_specific_tasks(): task = get_client().task @@ -1237,7 +1237,7 @@ def test_get_user_specific_tasks(): task.get_user_specific_tasks(1, 1, 1, [1, 1]) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_post_company_task(): task = get_client().task @@ -1245,7 +1245,7 @@ def test_post_company_task(): task.post_company_task(1, 1, '1', 'ttt') -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_post_team_task(): task = get_client().task @@ -1253,7 +1253,7 @@ def test_post_team_task(): task.post_team_task(1, 1, 1, '1', 'ttt') -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_post_user_task(): task = get_client().task @@ -1261,7 +1261,7 @@ def test_post_user_task(): task.post_user_task(1, 1, 1, 1, '1', 'ttt') -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_put_company_task(): task = get_client().task @@ -1269,7 +1269,7 @@ def test_put_company_task(): task.put_company_task(1, 1, '1', 'ttt') -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_put_team_task(): task = get_client().task @@ -1277,7 +1277,7 @@ def test_put_team_task(): task.put_team_task(1, 1, 1, '1', 'ttt') -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_put_user_task(): task = get_client().task @@ -1285,7 +1285,7 @@ def test_put_user_task(): task.put_user_task(1, 1, 1, 1, '1', 'ttt') -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_delete_company_task(): task = get_client().task @@ -1293,7 +1293,7 @@ def test_delete_company_task(): task.delete_company_task(1, [1, 1]) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_delete_team_task(): task = get_client().task @@ -1301,7 +1301,7 @@ def test_delete_team_task(): task.delete_team_task(1, 1, [1, 1]) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_delete_user_task(): task = get_client().task @@ -1309,7 +1309,7 @@ def test_delete_user_task(): task.delete_user_task(1, 1, 1, [1, 1]) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_delete_all_company_tasks(): task = get_client().task @@ -1317,7 +1317,7 @@ def test_delete_all_company_tasks(): task.delete_all_company_tasks(1) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_delete_all_team_tasks(): task = get_client().task @@ -1325,7 +1325,7 @@ def test_delete_all_team_tasks(): task.delete_all_team_tasks(1, 1) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_delete_all_user_tasks(): task = get_client().task @@ -1333,7 +1333,7 @@ def test_delete_all_user_tasks(): task.delete_all_user_tasks(1, 1, 1) -@patch('urllib.request.urlopen', patched_urlopen_task) +@patch('urllib2.urlopen', patched_urlopen_task) def test_update_batch_tasks(): task = get_client().task @@ -1383,7 +1383,7 @@ def patched_urlopen_oconomy_content(request, *args, **kwargs): return request -@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) +@patch('urllib2.urlopen', patched_urlopen_oconomy_content) def test_get_monthly_summary(): oconomy = get_client().nonauth_oconomy @@ -1391,7 +1391,7 @@ def test_get_monthly_summary(): assert read == oconomy_dict, read -@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) +@patch('urllib2.urlopen', patched_urlopen_oconomy_content) def test_get_hours_worked_by_locations(): oconomy = get_client().oconomy @@ -1399,7 +1399,7 @@ def test_get_hours_worked_by_locations(): assert read == oconomy_dict, read -@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) +@patch('urllib2.urlopen', patched_urlopen_oconomy_content) def test_get_hours_worked_by_weeks(): oconomy = get_client().oconomy @@ -1407,7 +1407,7 @@ def test_get_hours_worked_by_weeks(): assert read == oconomy_dict, read -@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) +@patch('urllib2.urlopen', patched_urlopen_oconomy_content) def test_get_top_countries_by_hours(): oconomy = get_client().oconomy @@ -1415,7 +1415,7 @@ def test_get_top_countries_by_hours(): assert read == oconomy_dict, read -@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) +@patch('urllib2.urlopen', patched_urlopen_oconomy_content) def test_get_earnings_by_categories(): oconomy = get_client().nonauth_oconomy @@ -1423,7 +1423,7 @@ def test_get_earnings_by_categories(): assert read == oconomy_dict, read -@patch('urllib.request.urlopen', patched_urlopen_oconomy_content) +@patch('urllib2.urlopen', patched_urlopen_oconomy_content) def test_get_most_requested_skills(): oconomy = get_client().oconomy From 71388bf14a66a24e63e7d04a06e091b07fd92a91 Mon Sep 17 00:00:00 2001 From: Ilya Vihtinsky Date: Fri, 9 Aug 2013 21:16:13 +0400 Subject: [PATCH 19/19] add fixer for tests.py --- fixers/__init__.py | 0 fixers/fix_patch_in_tests.py | 15 +++++++++++++++ setup.py | 1 + 3 files changed, 16 insertions(+) create mode 100644 fixers/__init__.py create mode 100644 fixers/fix_patch_in_tests.py diff --git a/fixers/__init__.py b/fixers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fixers/fix_patch_in_tests.py b/fixers/fix_patch_in_tests.py new file mode 100644 index 0000000..9147681 --- /dev/null +++ b/fixers/fix_patch_in_tests.py @@ -0,0 +1,15 @@ +from lib2to3.fixer_base import BaseFix +from lib2to3.pgen2 import token + +class FixPatchInTests(BaseFix): + + _accept_type = token.STRING + + def match(self, node): + if node.value.strip("'\"") == 'urllib2.urlopen': + return True + return False + + def transform(self, node, results): + node.value = "'urllib.request.urlopen'" + node.changed() diff --git a/setup.py b/setup.py index 7924807..e98b0bf 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,7 @@ author_email='python@odesk.com', maintainer='Volodymyr Hotsyk', use_2to3 = True, + use_2to3_fixers = ['fixers'], maintainer_email='gotsyk@gmail.com', install_requires=['oauth2', 'mock', 'nose'], dependency_links = ['https://github.com/hades/python-oauth2/tarball/python3#egg=oauth2',],