-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
Fix SMTP STARTTLS for Twisted >= 21.2.0 (5386) #5406
Fix SMTP STARTTLS for Twisted >= 21.2.0 (5386) #5406
Conversation
…igher than 21.2.0 to use STARTTLS
Codecov Report
@@ Coverage Diff @@
## master #5406 +/- ##
==========================================
+ Coverage 88.61% 88.80% +0.19%
==========================================
Files 163 162 -1
Lines 10627 10988 +361
Branches 1809 1795 -14
==========================================
+ Hits 9417 9758 +341
- Misses 935 949 +14
- Partials 275 281 +6
|
Is it OK to set the attribute after the class initialization, instead of passing it to the class init method? Could you include some kind of test for the change (a test that would fail if the change was reverted)? |
Note that usually we check the Twisted version with |
As for the assignment question, it should be fine BUT the attribute is Not sure what can a test do unless we can mock a SMTP server with STARTTLS, but it may be possible to run some code with just the factory itself (e.g. |
Thank you for your input, I will try to fix that next week |
Made the changes but I still need test it with the server and add unit tests |
I made some code changes implementing the suggestions in your comments. Thank you @wRAR What I am struggling with are the unit tests. How can I test the
Any ideas? |
Regarding tests, I thought about running some methods that cause |
Wouldn't I then test only the twisted library instead of the |
Right, I understand now what did you mean. Maybe we can extract the factory creation? Otherwise we need a mock SMTP server, as the purpose of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved comment but not all checks ran through. I'm not sure what the issue could be:
FAILED tests/test_engine_stop_download_bytes.py::EngineTest::test_deprecated_has_capacity
= 1 failed, 2697 passed, 119 skipped, 26 xfailed, 529 warnings in 1187.61s (0:19:47) =
ERROR: InvocationError for command /home/runner/work/scrapy/scrapy/.tox/pypy3-pinned/bin/pytest --durations=10 docs scrapy tests (exited with code 1)
Can anyone point me in the right direction?
We have a few tests that may fail randomly. Let me re-run them. |
Have you tried to call some more high-level TLS-related methods that check |
…lidate behaviour of adding a hostname
I think I got it now. I found a method that triggers |
The coverage report tells me that the body of this
It seems like the coverage run is executed with a lower version of twisted. |
According to the pull request coverage report it gets called at least 6 times. So I think we can ignore the codecov/patch issue. |
Good to know! We'd still have to reach the coverage target though right? I'm not so sure how do to that though because the only other line which is not covered is line 135 which is executing the new function for the factory creation. I would have to evoke the |
@wRAR do you think I should just write a test for |
To test |
Right @wRAR. Not sure if mocking a SMTP would be beneficial here. As the only purpose would be to cover this one function call. Do you think the coverage target miss can be ignored then? Since the only other line is apparently being executed by the tests. |
I wonder if we can exploit mitmproxy for a testing SMTP server, as we do for other tests that need a server. |
The current test implementation matches what I wanted to see initially, and as I wrote earlier, |
Pass hostname to the ESMTPSenderFactory when the twisted version is higher than 21.2.0 to use STARTTLS.
Fixes #5386