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

Re-raising exception on deliver (fixes #49) #50

Closed
wants to merge 5 commits into from

Conversation

DrDub
Copy link

@DrDub DrDub commented Dec 7, 2016

In python3 it would be nice to chain it with smtplib.SMTPException.

In python3 it would be nice to chain it with smtplib.SMTPException.
@DrDub
Copy link
Author

DrDub commented Dec 7, 2016

Most intriguing. All these new errors on Travis come from this change?
I guess I'll have t expand this PR then.

@moggers87
Copy link
Owner

Yeah, those tests will need fixing. You'll also need to create a test for the new behaviour

@codecov-io
Copy link

codecov-io commented Dec 8, 2016

Current coverage is 93.58% (diff: 100%)

Merging #50 into master will increase coverage by 0.13%

@@             master        #50   diff @@
==========================================
  Files            15         15          
  Lines          1497       1497          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           1399       1401     +2   
+ Misses           98         96     -2   
  Partials          0          0          

Powered by Codecov. Last update cf5e0a9...00f2542

@DrDub
Copy link
Author

DrDub commented Dec 8, 2016

OK, now it works and added an extra test case for the behavior (test_relay_asserts_no_relay).
It launches a smtp.DebuggingServer in a separate process at setup.
Interestingly, before the failing tests were not really "testing" that much because it was just hitting this exception and returning silently. I believe highlighting this (and fixing the tests) to be the most important aspect of this change.

Copy link
Owner

@moggers87 moggers87 left a comment

Choose a reason for hiding this comment

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

The fix looks good, but I have some issues with tests.

@patch("salmon.server.smtplib.SMTP")
def test_relay_smtp(client_mock):
relay = server.Relay("localhost", port=8899)
relay = server.Relay("localhost", port=7899)
Copy link
Owner

Choose a reason for hiding this comment

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

This is an unnecessary change: we mock out smtplib.SMTP already.

@@ -16,7 +16,7 @@
from .setup_env import setup_salmon_dirs, teardown_salmon_dirs


relay = relay(port=8899)
relay = relay(port=7899)
Copy link
Owner

Choose a reason for hiding this comment

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

Why was the port number changed?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, that port was in use in my machine, 8899 is not such an unusual port.

@@ -164,7 +172,7 @@ def test_relay_smtp_ssl(client_mock):
def test_relay_deliver_mx_hosts(query):
query.return_value = [Mock()]
query.return_value[0].exchange = "localhost"
relay = server.Relay(None, port=8899)
relay = server.Relay(None, port=7899)
Copy link
Owner

Choose a reason for hiding this comment

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

We should mock out smtplib here too

@@ -191,7 +199,7 @@ def test_relay_resolve_relay_host(query):


def test_relay_reply():
relay = server.Relay("localhost", port=8899)
relay = server.Relay("localhost", port=7899)
Copy link
Owner

Choose a reason for hiding this comment

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

Ditto



def setup_package():
for path in dirs:
os.mkdir(path)
DUMMY_RELAY=subprocess.Popen("python -m smtpd -n -c DebuggingServer localhost:7899 > logs/smtpd.log", shell=True)
time.sleep(10)
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we need this - see my comments on the relay tests

Copy link
Author

Choose a reason for hiding this comment

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

It all boils down to this comment on the original code:

https://github.com/moggers87/salmon/blob/master/tests/salmon_tests/server_tests.py#L126
"this test actually delivers to a test server"

My understanding of the lamson testing code is that it assumes you're running a stmp at 8899. By virtue of silently failing if there is none, all these tests seem to be correct, when they were not.

The relay was not being tested. It was failing and continuing silently.

My initial fix was to set a "in_test" argument in Relay to mimic that behavior, but that didn't work with command_tests.

How do you want to reuse the smtplib mock?

Copy link
Owner

Choose a reason for hiding this comment

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

That's an old comment, it should be removed ☺

As far as I can see, all the tests that fail without a test server are all testing sending, not receiving.

You can use mock like tihs:

@patch("salmon.server.smtplib.SMTP")
def test_server_test(client_mock):
    # test code

This is the documentation for the mock library we're using: http://www.voidspace.org.uk/python/mock/

@DrDub
Copy link
Author

DrDub commented Dec 19, 2016

OK, I think this could be it. Thanks for your help.

If this is a go, let me know and I'll rebase it.

@moggers87
Copy link
Owner

Looks good to me, if you can undo your changes to the port numbers[1] used in tests and remove the unused imports in tests/salmon_tests/__init__.py then this is good to be merged.

Sorry for the delay in reviewing your latest changes!

[1]: I'll open a separate bug for dealing with port number clashes during testing. No matter what we choose, it will be in use on someone's system somewhere so let's do things properly :)

@moggers87
Copy link
Owner

Closing this PR as I've fixed this issue in master by not catching the exception at all. There's no real reason to catch an exception, log it, and then re-raise it.

@moggers87 moggers87 closed this Sep 9, 2017
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