Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
returning 204s for DELETE, webtest complains that there is content
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Iain Duncan  
View profile  
 More options Jul 27 2012, 4:21 pm
From: Iain Duncan <iainduncanli...@gmail.com>
Date: Fri, 27 Jul 2012 13:21:01 -0700
Local: Fri, Jul 27 2012 4:21 pm
Subject: returning 204s for DELETE, webtest complains that there is content

Hi, I'm implementing a set of views to return json to work with Dojo object
stores. From what I can gather, Dojo best wants me to return a 204 status
after a successful delete.
The view is registered as using the json renderer. It changes the response
status to 204 and returns None to the json renderer (or an empty dict, I've
tried both). Web test however is throwing an assertion error with the
message that there is content with my 204 response.

The call in my webtest test:

res = self.app.delete('/json/person/%i' % item.id, status=204)

The view code that I hoped would work:

class JsonItemDeleteView(JsonView):
    def __call__(self):
        try:
            self.model.delete_obj(self.context)
            self.request.response.status = '204 No Content'
            # status 204 means there should be *no* response body
            return None
        except Exception, e:
            log.info("Error deleting %s, %s" % (self.context, e) )
            json_dict = {}
            self.request.response.status = '500 Internal Server Error'
            json_dict['error'] = 'Error: The item was not able to be
deleted'
            return json_dict

Traceback:
 File
"/home/xornot/trunk/DojoSkunk/eggs/WebTest-1.3.4-py2.7.egg/webtest/lint.py" ,
line 443, in check_content_type
    "which must not return content.") % code)
AssertionError: Content-Type header found in a 204 response, which must not
return content.

Any help greatly appreciated!
iain


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gael Pasgrimaud  
View profile  
 More options Jul 27 2012, 4:26 pm
From: Gael Pasgrimaud <g...@gawel.org>
Date: Fri, 27 Jul 2012 22:26:14 +0200
Local: Fri, Jul 27 2012 4:26 pm
Subject: Re: returning 204s for DELETE, webtest complains that there is content
On 27/07/2012 22:21, Iain Duncan wrote:

> Hi, I'm implementing a set of views to return json to work with Dojo
> object stores. From what I can gather, Dojo best wants me to return a
> 204 status after a successful delete.
> The view is registered as using the json renderer. It changes the
> response status to 204 and returns None to the json renderer (or an
> empty dict, I've tried both). Web test however is throwing an assertion
> error with the message that there is content with my 204 response.

Try to return pyramid.httpexceptions.HTTPNoContent()


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Iain Duncan  
View profile  
 More options Jul 27 2012, 4:30 pm
From: Iain Duncan <iainduncanli...@gmail.com>
Date: Fri, 27 Jul 2012 13:30:43 -0700
Local: Fri, Jul 27 2012 4:30 pm
Subject: Re: returning 204s for DELETE, webtest complains that there is content

On Fri, Jul 27, 2012 at 1:26 PM, Gael Pasgrimaud <g...@gawel.org> wrote:
> On 27/07/2012 22:21, Iain Duncan wrote:

>> Hi, I'm implementing a set of views to return json to work with Dojo
>> object stores. From what I can gather, Dojo best wants me to return a
>> 204 status after a successful delete.
>> The view is registered as using the json renderer. It changes the
>> response status to 204 and returns None to the json renderer (or an
>> empty dict, I've tried both). Web test however is throwing an assertion
>> error with the message that there is content with my 204 response.

> Try to return pyramid.httpexceptions.**HTTPNoContent()

Thanks Gael. Is that considered better practice than doing the following,
which also makes it pass but seems hacky? I'm worried that if I raise
HTTPNoContent, is it a text/json reponse? Or is that a non issue because
it's a 204? ( ie are json 204s and html 204s identical? )

my hacky fix:
 self.request.response.status = '204 No Content'
 self.request.response.headers.pop('Content-Type')
 return None

thanks
Iain


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gael Pasgrimaud  
View profile  
 More options Jul 27 2012, 4:46 pm
From: Gael Pasgrimaud <g...@gawel.org>
Date: Fri, 27 Jul 2012 22:46:39 +0200
Local: Fri, Jul 27 2012 4:46 pm
Subject: Re: returning 204s for DELETE, webtest complains that there is content
On 27/07/2012 22:30, Iain Duncan wrote:

That's a non issue because if you don't have a content you don't need a
content-type. And you should not have one. This is why webtest raise.

> my hacky fix:
>   self.request.response.status = '204 No Content'
>   self.request.response.headers.pop('Content-Type')
>   return None

I guess the result is the same. But you can just return a Response
instance. eg: HTTPNoContent(). No need to raise it.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Iain Duncan  
View profile  
 More options Jul 30 2012, 1:17 pm
From: Iain Duncan <iainduncanli...@gmail.com>
Date: Mon, 30 Jul 2012 10:17:28 -0700
Local: Mon, Jul 30 2012 1:17 pm
Subject: Re: returning 204s for DELETE, webtest complains that there is content

Thanks for the clarification.

iain


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »