Thank you very much!
I'll try that!

Best regards,
Carsten


Am 11.11.20 um 02:28 schrieb David Nugent:
> Make your own request.
> 
> I don't see the need here but incase I'm missing something: request is just a 
> HTTPRequest 
> <https://docs.djangoproject.com/en/3.1/ref/request-response/#httprequest-objects>
>  instance. You can instantiate it like any other python class. The only 
> downside is that the request you manufacture won't have middleware applied or 
> in fact anything else that is populated and processed before it gets to your 
> handler (headers, method, parsed url parts, content and so on).
> 
> This may not actually be an issue in test scenarios, depending on your need, 
> and in this case on the backing store 
> <https://docs.djangoproject.com/en/3.1/ref/contrib/messages/#storage-backends>
>  used by the messages framework.  If it is set to session, then you'll need 
> to obtain a session from the client and stick it onto your request object if 
> you want that to persist through your subsequent test requests.
> 
> HTH /d
> 
>> On 10 Nov 2020, at 18:41, Carsten Fuchs <[email protected] 
>> <mailto:[email protected]>> wrote:
>>
>> Dear group,
>>
>> in my tests I would like to test the processing of messages in the view.
>>
>> For example:
>>
>>    def test_is_message_properly_handled(self):
>>        # The problem: We have no `request` here!
>>        messages.info <http://messages.info>(request, 'Hello')
>>        response = self.client.get("/handling-messages-view/")
>>        # asserts …
>>
>> This is an artificial example and I'm aware that I could submit a POST 
>> request and then use `follow=True` so that eventually the messages are 
>> processed. But I would like to setup messages and their processing 
>> independently as shown above.
>> The problem is that we don't have the `request` instance that is used by the 
>> test client.
>> Is this possible?
>>
>> Best regards,
>> Carsten
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1f9785eb-089f-491c-d9f5-2682f2e0a5ff%40cafu.de.

Reply via email to