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

add SplashHtmlResponse (extended #115) #160

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

iAnanich
Copy link
Contributor

Contains rebased @atultherejput commits from #115 with more test cases and little improvements.

atultherajput and others added 15 commits January 18, 2018 00:41
* new `test/test_response.py` file
* new `test/test_response/test_response_types` test function

`test_response_types` checks for compatibility of `Splash*Response`
classes with Scrapy's `*Response` classes with `issubclass` func
* use it in `test_middlewares.py` for `test_splash_request`
* use it inside `SplashMiddleware._change_response_class` method
* case when response is instance of any `Splash*` class in
`splash_scrapy_text_response` tuple of pairs
@codecov
Copy link

codecov bot commented Jan 19, 2018

Codecov Report

Merging #160 into master will increase coverage by 0.09%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #160      +/-   ##
==========================================
+ Coverage   92.66%   92.76%   +0.09%     
==========================================
  Files           9        9              
  Lines         586      594       +8     
  Branches      118      120       +2     
==========================================
+ Hits          543      551       +8     
  Misses         21       21              
  Partials       22       22
Impacted Files Coverage Δ
scrapy_splash/responsetypes.py 100% <ø> (ø) ⬆️
scrapy_splash/__init__.py 100% <100%> (ø) ⬆️
scrapy_splash/response.py 94.23% <100%> (+0.17%) ⬆️
scrapy_splash/middleware.py 89.88% <88.88%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fb8c41...6340dad. Read the comment docs.

@@ -14,6 +14,7 @@
from scrapy.exceptions import NotConfigured
from scrapy.http.headers import Headers
from scrapy.http.response.text import TextResponse
from scrapy.http.response.html import HtmlResponse
Copy link
Contributor

Choose a reason for hiding this comment

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

I don’t see where this import is used in your changes.

from scrapy_splash.response import splash_scrapy_text_responses
splash_text_response_types = tuple(x for x, y in splash_scrapy_text_responses)

if not isinstance(response, (SplashResponse, splash_text_response_types)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Your new SplashHtmlResponse class inherits from SplashTextResponse. Doesn’t that make these changes and some changes below unnecessary?


splash_scrapy_content_types = (
(SplashTextResponse, TextResponse, b'text/*'),
(SplashHtmlResponse, HtmlResponse, b'text/html'),
Copy link
Contributor

@Gallaecio Gallaecio Apr 5, 2019

Choose a reason for hiding this comment

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

💄 Since these lines are not too long, and this variable is only used once, maybe the variable could be removed and its content moved below, inline?

@@ -82,25 +94,26 @@ def test_splash_request():
assert json.loads(to_native_str(req2.body)) == expected_body

# check response post-processing
response = TextResponse("http://127.0.0.1:8050/render.html",
response = scrapy_response_type(
url="http://127.0.0.1:8050/render.html",
Copy link
Contributor

Choose a reason for hiding this comment

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

💄 Too much indentation, I would say.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree

headers={b'Content-Type': b'text/html'},
body=b"<html><body>Hello</body></html>")
headers={b'Content-Type': content_type},
body=b"<html><body>Hello</body></html>", )
Copy link
Contributor

Choose a reason for hiding this comment

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

💄 The added comma is not necessary.

It makes sense to add commas at the end if the closing parenthesis is on a different line, that allows to keep a clean diff when adding new parameters. But if you keep the closing parenthesis on the same line, there is no benefit to it.

assert response2 is not response
assert response2.real_url == req2.url
assert response2.url == req.url
assert response2.body == b"<html><body>Hello</body></html>"
assert response2.css("body").extract_first() == "<body>Hello</body>"
assert response2.headers == {b'Content-Type': [b'text/html']}
assert response2.headers == {b'Content-Type': [content_type, ]}
Copy link
Contributor

Choose a reason for hiding this comment

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

💄 That comma is only needed for tuples, not lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

idk, it makes it looking more like a list rather an object.

@Gallaecio
Copy link
Contributor

For reference: Fixes #114

@Gallaecio
Copy link
Contributor

@iAnanich It’s been a while, any chance you will resume this work, or should we close?

@codecov-io
Copy link

Codecov Report

Merging #160 into master will increase coverage by 0.12%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #160      +/-   ##
==========================================
+ Coverage   92.63%   92.76%   +0.12%     
==========================================
  Files           9        9              
  Lines         584      594      +10     
  Branches      117      120       +3     
==========================================
+ Hits          541      551      +10     
  Misses         21       21              
  Partials       22       22
Impacted Files Coverage Δ
scrapy_splash/responsetypes.py 100% <ø> (ø) ⬆️
scrapy_splash/__init__.py 100% <100%> (ø) ⬆️
scrapy_splash/response.py 94.23% <100%> (+0.17%) ⬆️
scrapy_splash/middleware.py 89.88% <88.88%> (+0.19%) ⬆️
scrapy_splash/utils.py 97.01% <0%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2aaa79d...6340dad. Read the comment docs.

@iAnanich
Copy link
Contributor Author

@Gallaecio yeah, a long time.
So what needs to be done?
I don't remember how, but I got around the problem.

@Gallaecio
Copy link
Contributor

Gallaecio commented Feb 25, 2020

So what needs to be done?

Please, have a look at my feedback above when you have time, see if you can address it.

@lucaguarro
Copy link

Is this being worked on?

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.

5 participants