Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions bitbucket/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,20 @@ def dispatch(self, method, url, auth=None, params=None, **kwargs):
False,
'Unauthorized access, '
'please check your credentials.')
elif status >= 400 and status < 500:
return (False, 'Service not found.')
elif status == 404:
return (False, dict(message='Service not found', reason=error, code=status))
elif status == 400:
return (False, dict(message='Bad request sent to server.', reason=error, code=status))
elif status == 401:
return (False, dict(message='Not enough privileges.', reason=error, code=status))
elif status == 403:
return (False, dict(message='Not authorized.', reason=error, code=status))
elif status == 402 or status >= 405:
return (False, dict(message='Request error.', reason=error, code=status))
elif status >= 500 and status < 600:
return (False, 'Server error.')
return (False, dict(message='Server error.', reason=error, code=status))
else:
return (False, error)
return (False, dict(message='Unidentified error.', reason=error, code=status))

def url(self, action, **kwargs):
""" Construct and return the URL for a specific API service. """
Expand All @@ -270,6 +278,8 @@ def get_user(self, username=None):
return (response[0], response[1]['user'])
except TypeError:
pass
except KeyError:
pass
return response

def get_tags(self, repo_slug=None):
Expand Down
2 changes: 2 additions & 0 deletions bitbucket/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def public(self, username=None):
return (response[0], response[1]['repositories'])
except TypeError:
pass
except KeyError:
pass
return response

def all(self):
Expand Down
8 changes: 6 additions & 2 deletions bitbucket/tests/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def test_get_none_user(self):
self.bb.username = None
success, result = self.bb.get_user()
self.assertFalse(success)
self.assertEqual(result, 'Service not found.')
self.assertEqual(result['message'], 'Service not found')
self.assertEqual(result['reason'], 'NOT FOUND')
self.assertEqual(result['code'], 404)

def test_get_public_repos(self):
""" Test public_repos on specific user."""
Expand All @@ -134,7 +136,9 @@ def test_get_none_public_repos(self):
self.bb.username = None
success, result = self.bb.repository.public()
self.assertFalse(success)
self.assertEqual(result, 'Service not found.')
self.assertEqual(result['message'], 'Service not found')
self.assertEqual(result['reason'], 'NOT FOUND')
self.assertEqual(result['code'], 404)

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