Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed up sign-in by only signing into one service (resolves #14) #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
5 changes: 2 additions & 3 deletions src/printapp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def login():
abort(401)

try:
printstatus.get_uniflow_client(username, password)
except printstatus.InvalidCredentialsError:
abort(401)
if not printstatus.is_username_and_password_valid(username, password):
abort(401)
except printstatus.NetworkError:
abort(504)
except printstatus.ScrapingError:
Expand Down
9 changes: 9 additions & 0 deletions src/printapp/printstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
def get_uniflow_client(username, password):
return _UniflowClient(username, password)

def is_username_and_password_valid(username, password):
"""Return True iff given username and password is valid.
"""
budget_scraper = _BudgetScraper()
try:
budget_scraper.sign_in(username, password)
except InvalidCredentialsError:
return False
return True

class _UniflowClient:
def __init__(self, username, password):
Expand Down
12 changes: 12 additions & 0 deletions src/printapp/test/test-scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ def test_blank_credentials(self):
'invalidUser', '')
self.assertRaises(InvalidCredentialsError, get_uniflow_client,
'', 'invalidPassword')
def test_is_username_and_password_valid(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a blank line above this line.

self.invalid_username = "lil0"
self.invalid_password = "password"

#good username, good password
self.assertTrue(is_username_and_password_valid(self.username, self.password))
#good username, bad password
self.assertFalse(is_username_and_password_valid(self.username, self.invalid_password))
#bad username, good password
#self.assertFalse(is_username_and_password_valid(self.invalid_username, self.password))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment this line

#bad username, bad password
self.assertFalse(is_username_and_password_valid(self.invalid_username, self.invalid_password))