Fix tests and update headers#175
Conversation
- add a new fixture for multiple studio apartments, pulled direct from daft - rewrite tests that previously called out to the live website, to use fixtures
daftlistings/daft.py
Outdated
| "platform": "web", | ||
| } | ||
|
|
||
| def set_headers(self, headers: dict): |
There was a problem hiding this comment.
Ah, I can make dict -> Dict[str, str] to have better typing
|
Yes mocking the endpoint is better and then have some kind of "integration test" that checks the POST. Can you check please your gist it just gives me 100% fail? I think there is an issue with the code, e.g. |
|
Ah whoops sorry, that was on older one from a previous impl. I’ve updated the gist (https://gist.github.com/groegercesg/f31113d9417c174bcd3c297e7a6fd282) - that should work now. If I had to guess we will get slight different pass rates, as I don’t think the random useragent command allows a custom seed - so it’ll be different user agents used. |
|
Looking at the failing values for user-agent strings, it seems they are all a version of Chrome <130. Regardless, it would be a bad idea to make setting the Can you add a commit that puts in a default user agent string please, then we should be good to go 👍 |
89c5b4f to
a3be80c
Compare
a3be80c to
20dce0f
Compare
|
Hmm, yeah makes sense to not force users to pick one. I've added a commit with a new default user agent that works, and I've updated the unit tests as well. |
|
Thank you @groegercesg this is a very useful addition to the package 🔥 |
First of all, thanks for the excellent Repo - really useful!
I used it around a year ago with great success, but when I pulled it recently, I was consistently getting
403 Forbidden. After some digging I realised this was Daft blocking requests based on the UserAgent. In this PR, I'm introducing two things:Development
I ran black (
black .) and the unit tests (python -m unittest discover -s tests), let me know if I should do something else to comply with the coding standards of this package.User Agent Testing
As a side note for anyone interested, the default user agent
""seems to basically be blocked 100% of the time - resulting an a 403 Forbidden. I did a quick bit of testing with fake-useragent, and saw much better success rates using more recent ones:Here's a quick gist of how I did the test: https://gist.github.com/groegercesg/f31113d9417c174bcd3c297e7a6fd282
Feedback wanted
daftlistingswith something like fake-useragent, and we can try a couple user agents (up to some sensible limit) to make the request be accepted