bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.45k stars 424 forks source link

TenantClient - PUT and PATCH method return 415_UNSUPPORTED_MEDIA_TYPE #649

Open punto-bi opened 4 years ago

punto-bi commented 4 years ago

First of all, thanks for your hard work in creating this package. It's really usefull. I've been learning how to use it this last week and until now, I have made a lot of progress. But I'm stuck testing my REST app.

I'm using Django==3.0.7 and djangorestframework==3.11.0. POST method work fine, but PUT and PATCH methods return the status code = 415.

This is the format that I'm using for testing:

http_request = {
    "first_name": "",
    "last_name": ""
}
response = tenant.put("/api/v1/auth/user", http_request)

Where tenant = TenantClient(self.tenant)

I tried to scpecify the format content_type='application/json', but it kept returning the same error.

Also I tried parsing the dict to json: data=json.dumps(http_request), but it doesn't work either.

Is there another way to test both methods?

Thanks

tartieret commented 3 years ago

You just have to specify the content-type to solve this issue, for example:


client = TenantClient(self.tenant)
data = {
    "first_name": "",
    "last_name": ""
}
response = client.put(url, data=data, content_type="application/json")

That should work :D

tartieret commented 3 years ago

Also, I notice that you use the url "/api/v1/auth/user". Depending on how you set up your url conf in rest framework, this can trigger a redirect if you define the url as "/api/v1/auth/user/" (trailing slash)