def test_canonical_json(self): recipe = RecipeFactory.build( action=ActionFactory(name='action'), approval=None, arguments={'foo': 1, 'bar': 2}, enabled=False, filter_expression='2 + 2 == 4', name='canonical', last_updated=datetime(2016, 6, 27, 13, 54, 51, 1234, tzinfo=timezone.utc), ) recipe.save(skip_last_updated=True) # Yes, this is really ugly, but we really do need to compare an exact # byte sequence, since this is used for hashing and signing expected = ( '{' '"action":"action",' '"approval":null,' '"arguments":{"bar":2,"foo":1},' '"current_approval_request":null,' '"enabled":false,' '"filter_expression":"2 + 2 == 4",' '"id":%(id)s,' '"is_approved":false,' '"last_updated":"2016-06-27T13:54:51.001234Z",' '"name":"canonical",' '"revision_id":%(revision_id)s' '}' ) % { 'id': recipe.id, 'revision_id': recipe.revision_id, } expected = expected.encode() assert recipe.canonical_json() == expected