I'm writing unit tests for some of our code and I need to compare a JSON response with a dictionary value returned via code. The dictionary keys and some values are raw byte strings: str
whereas the HTTP Response data, after json.loads
have unicode keys and values. When I use self.assertDictEqual(expected, actual)
I end up with a ton of differences!
It looks like json.loads
can take an object_hook
and return byte strings, but I was wondering if Python/Django UnitTest
framework has a simpler solution.
Edit: The possible duplicate solves my original problem - I tried it and it works! Now, I'm facing a similar issue with int
vs long
: u'user': 86160L != u'user': 86160
. Is there an intelligent comparison mechanism that accounts for these differences - basically forces conversions to unicode
and long
if it detects the corresponding key/value is of this type?
Also, How do you deal with these issues while writing TestCases?