Hi. How can I run a twisted test suite from a script where the reactor is already running? Call run() on a TrialRunner starts the reactor, but I'm already using twisted in my script to build the test suite.
I'm trying to run this example, but when I try to switch to POST, it keeps saying the request is never sent. I tried to change the params to data, json, change the body to None, but I can't figure out why it's not working, or how I have to specify a post request to RequestSequence: https://github.com/twisted/treq/blob/master/doc...
runciter
adourado: did you replace all the gets with posts?
adourado
Yes
When i do that, it says the request was never sent
I commented out the second test, to figure out the first one first, but yeah, I changed to post both in the make_a_request function and in the ResponseSequence spec
latest version
well, apparently I was missing something, it worked now
must be your magical aura, @runciter
runciter
i do what i can ;)
adourado
The url HAS to end with '/', is that right? I'm getting a StubbingError if it doesn't
for post, at least
mesozoic has quit
jamesaxl joined the channel
runciter
adourado: the URL in the treq.post call has to match a URL in the RequestSequence
adourado
They are matching, but if they don't have a '/' at the end, it fails with StubbingError
runciter
well, it has to match the URL that's next in the sequence
I tried with https://bla.com/bla, and it does works well. Just the domain, without a path, though, fails
Should also note, I'm using pytest-twisted, rather than trial
jamesaxl joined the channel
runciter
oh
adourado: can you provide me with an example that runs? i don't have get_server_info :(
adourado
Sorry, forgot about that. It just returns a mapping from strings to strings, so, {"a":"b"} should work
I noticed that all the values in the params part on the spec have to be lists, is that correct?
runciter
adourado: yes
adourado: if you have {b'param': b'value'}, treq sees that as {b'param': [b'v', b'a', b'l', b'u', b'e']}
adourado
what about nested dicts?
runciter
if the keys are bytes, it'll work, but that doesn't make any sense for URL parameters
adourado
hmmm, but it's a post, I wanna send post data. It's not supposed to go in params?
If it's not, how do I tell RequestSequence that it's not on params?
runciter
post parameters also can't contain nested dictionaries
they follow the same rules as URL parameters
well, it's a little more complicated than that, but it's the case that x-www-form-urlencoded bodies can represent key-value pairs with duplicate keys, but not nested key-value pairs
adourado
well, my system is sending nested dicts on post data since always, so I think I'm using the wrong word here?
energizer joined the channel
Like, we even use a Agent and everything
runciter
are you posting JSON?
yeah, you're posting JSON
adourado
*yes
runciter
that's very different :)
adourado
makes sense. So how do I tell RequestSequence that the post body is json?