collective / sphinxcontrib-httpexample

Adds example directive for sphinx-contrib httpdomain
23 stars 20 forks source link

Loading request/response from external file is broken #41

Closed lukasgraf closed 5 years ago

lukasgraf commented 5 years ago

With the change from #38 the loading requests/responses from filesystem files got broken.

Steps to reproduce


Specifically it's 05035394 that breaks it: Before that change, the HTTPExample directive processed it's data like this:

After that, self.content was set to request_content (wherever it came from, file on disk or literal directive content):

        # reset the content to just the request
        self.content = request_content

With the change from 05035394, the stripping of fields got mangled into the logic for splitting request and response. The loading from disk parts were still left in place, but completely negated by ignoring request_contents, and always setting self.content to request_content_no_fields:

        # reset the content to the request, stripped of the reST fields
        self.content = request_content_no_fields

Unfortunately this bug slipped through because there's no test that really exercises loading from files (or makes any assertion on the result).

The fix in my opinion would be to separate loading of request/response (from disk, or from directive content + split) from any post-processing (like stripping fields) that's being done to it.

datakurre commented 5 years ago

@lukasgraf I’m sorry about this. Thanks for such a detailed report. Obviously the previous release should work as long as this remains unfixed.

lukasgraf commented 5 years ago

@datakurre no worries.

I tried to write a failing test for the filesystem loading, and create a PR, but honestly I didn't quite see how I could easily test this. The fixtures + snapshots work great for testing the builders (that get passed in an HTTP request), but because the loading from FS happens in the directive, I didn't quite know where to start.

When trying to carefully refactor the code introduced with #38, I noticed that I could comment out this block without any tests failing. So I couldn't even be sure my fix wouldn't break that feature, that's why I just stuck with creating an issue for now 😉

datakurre commented 5 years ago

Should be fixed in 0.10.3

lukasgraf commented 5 years ago

@datakurre thank you! Just tested with the plone.restapi docs, it is indeed fixed for our use case in 0.10.3 👍