Skip to content
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

serializer.data returns ReturnDict and OrderedDict instead of dict object. #2364

Closed
learner010 opened this issue Dec 29, 2014 · 9 comments
Closed

Comments

@learner010
Copy link

I have written a model serializer class for a model. When I test to see if it serializes properly I get following error.
AssertionError: ReturnDict([(u'id', 1), ('apple', OrderedDict([(u'id', 1), ('data', u'this is a apple data.')])) ...
I tried converting it to dict wrapping aserializer.data to dict function like
dict(aserializer.data)
I get following error.
AssertionError: {'status': False, 'http': OrderedDict([(u'id', 1), ...

How to get dictionary data from a serializer.

@jpadilla
Copy link
Member

There's some information lacking to be completely helpful, like how exactly are you doing to "test to see if it serializes properly..." but you should be able to do something like the following depending on how you're using the serializer.

serializer = YourSerializer(instance)
assert serializer.data == {'id': 1, 'username': 'admin'}

There are many examples on doing this around the test cases that should help out more.

Other than that if you need more help with this, usage questions should be asked on the mailing list, Stack Overflow or IRC.

@xordoquy
Copy link
Collaborator

@jpadilla I already ran into that one. I'll work on the test case tonight.

@xordoquy xordoquy reopened this Dec 29, 2014
@xordoquy
Copy link
Collaborator

Also note that this is likely the root cause for #2360

@tomchristie
Copy link
Member

The 'ReturnDict' type is mostly just an implementation detail. It is an ordered dictionary type. You shouldn't need to convert it to a ppdict primitive.

@tomchristie tomchristie changed the title aserializer.data returns ReturnDict and OrderedDict instead of dict object. serializer.data returns ReturnDict and OrderedDict instead of dict object. Dec 29, 2014
@learner010
Copy link
Author

how to test the serializer.data(ReturnDict) against python dictionay({'akey': 1} ).

@tomchristie
Copy link
Member

This works just fine...

assert serializer.data == some_expected_value

@xordoquy
Copy link
Collaborator

Didn't manage to reproduce it. Will open a ticket if I face this again.

@xordoquy
Copy link
Collaborator

xordoquy commented Jan 6, 2015

Just fall on it again.
The assert works under Python 3 but fails for Python 2.7

@xordoquy xordoquy reopened this Jan 6, 2015
@xordoquy
Copy link
Collaborator

xordoquy commented Jan 6, 2015

Forget the previous comment.

@xordoquy xordoquy closed this as completed Jan 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants