Skip to content

Commit

Permalink
Add a Bugsy.authenticated property
Browse files Browse the repository at this point in the history
Allow to check if we are authenticated against the server.
  • Loading branch information
parkouss committed Feb 5, 2016
1 parent 0b33416 commit 9d39f88
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bugsy/bugsy.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ def __init__(

self._have_auth = True

@property
def authenticated(self):
"""
True if this instance is authenticated against the server.
>>> bugzilla = Bugsy()
>>> assert not bugzilla.authenticated
"""
return self._have_auth

def get(self, bug_number):
"""
Get a bug from Bugzilla. If there is a login token created during
Expand Down
21 changes: 21 additions & 0 deletions tests/test_bugsy.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,24 @@ def test_we_can_handle_errors_when_retrieving_bugs():
assert str(e) == "Message: Bug 111111111111 does not exist. Code: 101"
except Exception as e:
assert False, "Wrong type of exception was thrown"

def test_we_can_know_when_bugsy_is_not_authenticated():
bugzilla = Bugsy()
assert not bugzilla.authenticated

@responses.activate
def test_we_can_know_when_bugsy_is_authenticated_using_password():
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
body='{"token": "foobar"}', status=200,
content_type='application/json', match_querystring=True)
bugzilla = Bugsy("foo", "bar")
assert bugzilla.authenticated

@responses.activate
def test_we_can_know_when_bugsy_is_authenticated_using_apikey():
responses.add(responses.GET,
'https://bugzilla.mozilla.org/rest/valid_login?login=foo&api_key=goodkey',
body='true', status=200, content_type='application/json',
match_querystring=True)
bugzilla = Bugsy(username='foo', api_key='goodkey')
assert bugzilla.authenticated

0 comments on commit 9d39f88

Please sign in to comment.