You'll be glad to know that's fixed in Django 1.10: 
https://github.com/django/django/commit/e0837f2cb12de5e95e621d19b186b0da43bcdee2

On Wednesday, August 24, 2016 at 10:27:37 AM UTC-4, Gergely Polonkai wrote:
>
> It just turned out that value_list(…, flat=True) returns a QuerySet, not a 
> list. So expected_json couldn’t be equal to the actual result. It took a 
> bit of debugging as repr() displays [1, 2, 3], not QuerySet(1, 2, 3) or 
> something.
>
> Derek <game...@gmail.com <javascript:>> ezt írta (időpont: 2016. aug. 
> 24., Sze, 16:03):
>
>> Assuming that the long function you have embedded inside your dictionary 
>> simply generates a list i.e.
>>    cloned_build.groupings.get(group=group1)
>>    .field_values
>>    .exclude(template=approvable_template)
>>    .values_list('id', flat=True)[:]
>>
>> results in:
>>    [1,2,3]
>>
>> Then some examples of possible tests:
>>
>>
>> expected_json = {
>>             'status': 'ok',
>>             'invalid-fields': {},
>>             'updated-fields': [1,2,3]
>>         }
>> actual_json = {
>>             'invalid-fields': {},
>>             'status': 'ok',
>>             'updated-fields': [1,2,3]
>>         }
>> invalid_json = {
>>             'invalid-fields': {},
>>             'status': 'ok',
>>             'updated-fields': [2,3]
>>         }
>>
>> assert cmp(expected_json, actual_json) == 0  # same
>> assert cmp(expected_json, invalid_json) == -1  # different
>>
>> Hope this helps.  For more background & discussion, see:
>>
>>
>> http://stackoverflow.com/questions/4527942/comparing-two-dictionaries-in-python
>>
>>
>>
>> On Wednesday, 24 August 2016 12:11:18 UTC+2, Gergely Polonkai wrote:
>>>
>>> Hello,
>>>
>>> I have a test that fetches some JSON data from my API and compares it 
>>> with the expected result, which is generated like this:
>>>
>>>         expected_json = {
>>>             'status': 'ok',
>>>             'invalid-fields': {},
>>>             'updated-fields': cloned_build.groupings.get(group=group1)
>>>             .field_values
>>>             .exclude(template=approvable_template)
>>>             .values_list('id', flat=True)[:],
>>>         }
>>>
>>> At the end, I get this error:
>>>
>>> AssertionError: {u'status': u'ok', u'invalid-fields': {}, 
>>> u'updated-fields': [13, 14, 15]} != {u'status': u'ok', u'invalid-fields': 
>>> {}, u'updated-fields': [13, 14, 15]}
>>>   {u'invalid-fields': {}, u'status': u'ok', u'updated-fields': [13, 14, 
>>> 15]}
>>>
>>>
>>> It seems the two dicts are equal, but assertEquals thinks they are not. 
>>> Am I missing something here?
>>>
>>> Best,
>>> Gergely
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/ac51f934-5320-45c1-8dc8-aca658fde881%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/ac51f934-5320-45c1-8dc8-aca658fde881%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6e27b36b-9693-492e-baf6-b34d9596ee87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to