testing django: reason for unexpected http status code

  • Last Update :
  • Techknowledgy :

Regarding your mocking, try something like:

with patch.object(HttpResponseBase, '__init__', None):
   response = client.get(url)

I used this solution to find the problem:

import django
django.http.response.HttpResponseBase.__init__ = None
response = client.get(url)

Suggestion : 2

It works with "model.object.filter" but not with ".create" or ".get".,Sounds like a problem with the pyAMF serializer for Django objects.,observable to return many json objects from server will contain all at once or iterate through?,django rest - create object with less fields

using "primitives" instead of Django objects avoid the problem:

 return {
    'grupo': {
       "id": g.id
    },
    'membros': None,
    'reponsavel': None
 }

Set the logger on the gateway, e.g.:

import logging

from pyamf.remoting.gateway.django
import DjangoGateway

services = {}

gw = DjangoGateway(services, logger = logging)

Suggestion : 3

When DEBUG is False, Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater). This gives the administrators immediate notification of any errors. The ADMINS will get a description of the error, a complete Python traceback, and details about the HTTP request that caused the error.,To activate this behavior, put the email addresses of the recipients in the ADMINS setting.,Property that returns a pathlib.Path representing the absolute filesystem path to a template for rendering the HTML representation of the exception. Defaults to the Django provided template.,Property that returns a pathlib.Path representing the absolute filesystem path to a template for rendering the plain-text representation of the exception. Defaults to the Django provided template.

import re
IGNORABLE_404_URLS = [
   re.compile(r '\.(php|cgi)$'),
   re.compile(r '^/phpmyadmin/'),
]
import re
IGNORABLE_404_URLS = [
   re.compile(r '^/apple-touch-icon.*\.png$'),
   re.compile(r '^/favicon\.ico$'),
   re.compile(r '^/robots\.txt$'),
]
from django.views.decorators.debug
import sensitive_variables

@sensitive_variables('user', 'pw', 'cc')
def process_info(user):
   pw = user.pass_word
cc = user.credit_card_number
name = user.name
   ...
@sensitive_variables()
def my_function():
   ...
@sensitive_variables('user', 'pw', 'cc')
@some_decorator
@another_decorator
def process_info(user):
   ...
from django.views.decorators.debug
import sensitive_post_parameters

@sensitive_post_parameters('pass_word', 'credit_card_number')
def record_user_profile(request):
   UserProfile.create(
      user = request.user,
      password = request.POST['pass_word'],
      credit_card = request.POST['credit_card_number'],
      name = request.POST['name'],
   )
   ...