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

added try/except block to handle authentication errors #17

Merged
merged 9 commits into from
Nov 19, 2018

Conversation

Mat001
Copy link
Contributor

@Mat001 Mat001 commented Nov 18, 2018

@trp07 Added try/except block in _get_session() method.
It handles auth errors such as incorrect password.Per: https://docs.python.org/3.6/library/smtplib.html#smtplib.SMTPResponseException

@coveralls
Copy link

coveralls commented Nov 18, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 3faf2e3 on Mat001:handle_invalid_password into 7b126d7 on trp07:master.

@Mat001
Copy link
Contributor Author

Mat001 commented Nov 18, 2018

@trp07 Added 'raise' statement to try/except block in _get_session method.
That resolved couple issues: parameters in tests for SMTPResponseException are now accepted. And in verbose mode it would still say Login successful after the autyh failure message, raise stopped that, as it stops the program at that point.
Looks clean now :).

…eally getting back error response. Instead we use mock
e = get_email

with pytest.raises(SMTPResponseException):
print('Exception was not raised, but it should be.')
Copy link
Member

Choose a reason for hiding this comment

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

Get rid of this print statement

e = get_email

with pytest.raises(Exception):
print('Exception was not raised, but it should be.')
Copy link
Member

Choose a reason for hiding this comment

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

get rid of this print statement

try:
session.login(self.from_, self._auth)
except SMTPResponseException as e:
# decodes bytestring from response to unicode string for readability
Copy link
Member

Choose a reason for hiding this comment

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

get rid of this comment

@Mat001
Copy link
Contributor Author

Mat001 commented Nov 19, 2018

Prints removed.

@Mat001
Copy link
Contributor Author

Mat001 commented Nov 19, 2018

@trp07 Should be good now

@@ -18,6 +18,7 @@
from ._utils import credential_property
from ._utils import validate_property
from ._utils import timestamp
from smtplib import SMTPResponseException
Copy link
Member

Choose a reason for hiding this comment

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

reorder this to be underneath the "import smtplib" at the top. Typical import hierarchy from top-to-bottom goes: standard library modules, then third-party modules, then internal package modules.

@trp07
Copy link
Member

trp07 commented Nov 19, 2018

@Mat001, thanks a ton for the work. I added a few comments.

@trp07
Copy link
Member

trp07 commented Nov 19, 2018

Thanks!

@trp07 trp07 merged commit 1254b48 into HomeMadePy:master Nov 19, 2018
@Mat001 Mat001 deleted the handle_invalid_password branch November 19, 2018 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants