-
Notifications
You must be signed in to change notification settings - Fork 300
AttributeError: 'NoneType' object has no attribute 'get' #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Did you use the |
@abdulhaq-e Oh, I wasn't using them. I changed the code to use serializers from ( This is the view:
And this is my serializer:
But still, the same error occurs :/ BTW, it works perfectly in browser (and any client), and even works using original |
Just a wild guess, can you try:
|
I think the solution I gave you in the previous comment will work. In DRF test module, the
Anyway, if what I'm saying is correct, passing The tests written for this package either used the standard Django Unittest or pytest and some used the testing classes provided by DRF. For the latter, |
@abdulhaq-e shouldn't Anyway, I tried it, it didn't raise the same error, but the test failed
Response body:
data:
|
Easy fix, you can't pass the data as a python object, you need to serialise it to json
|
After inspecting DRF test module, no it's not the same. By passing |
@abdulhaq-e Now I'm confused :/ The original (using default DRF) test was:
There was no need to |
@abdulhaq-e Btw, using
So, I have to manually put the data in JSON API format, before
Then serialize it, and your test will finally pass :) |
For creating/updating resources, you have to send a resource object which has to exist under a top level member named
The renderer does that for you when passing
An error will be raised. I believe the renderer in DRF Json API can be enhanced to allow tests such as yours. |
@abdulhaq-e I do agree that DRF JSON needs some enhancements regarding to testing So, I will leave this issue open Thanks @abdulhaq-e :) |
I'm going to close this issue since it's a rather generic thread about test configuration. If you feel like we could implement something better with regards to renderer defaults then you're definitely welcome to open a PR or a more specific issue. |
Hi, there
Since yesterday, I'm stuck on this error in my test script:
Particularly, this is the line of my code causing the error:
response = self.client.post(url, data)
And this is the line of your code that responsible of the error
view = renderer_context.get("view", None)
Simply because
renderer_context
is NoneAll my test was passing before switching to this library (using default DRF renders)
Here is my configurations:
Am I doing something wrong ?
The text was updated successfully, but these errors were encountered: