Wednesday, August 24, 2016

Re: Strange failing test

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+unsubscribe@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/ac51f934-5320-45c1-8dc8-aca658fde881%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment