[PATCH 2 of 3 saem_ref v3] Sort both result and expect responses in "archive-units" tests

Denis Laxalde denis.laxalde at logilab.fr
Wed Feb 14 16:22:13 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1518443233 -3600
#      Mon Feb 12 14:47:13 2018 +0100
# Node ID fddd9de51104d6c18b0240dc1e38483d9afff61e
# Parent  1697d9a202be0649a03f71d078ff81733779545b
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r fddd9de51104
# EXP-Topic ark/postgres-generated
Sort both result and expect responses in "archive-units" tests

Previously, we only sorted response body (JSON) obtained by calling the
web service as we controlled sorting of the expected value (it's sorted
by ARK identifiers, which is sequential). As we are moving away from
sequential ARK identifiers, the expected value will no longer be sorted.
Thus we now sort both actual and expected values.

diff --git a/test/test_views.py b/test/test_views.py
--- a/test/test_views.py
+++ b/test/test_views.py
@@ -532,53 +532,57 @@ class ListArchivalUnitsServiceTC(CubicWe
         with self.admin_access.web_request(
                 headers={'Accept': 'application/json'}) as req:
             result = json.loads(self.app_handle_request(req, 'archival-units'))
+            expected = [
+                {
+                    'ark': archival_unit.ark,
+                    'name': 'Archival Dptmt',
+                    'state': 'published',
+                    'url': archival_unit.absolute_url(),
+                    'authority': {
+                        'ark': org.ark,
+                        'name': org.name,
+                        'url': org.absolute_url(),
+                    },
+                    'deposit-units': [
+                        {
+                            'ark': dep_unit.ark,
+                            'name': dep_unit.name,
+                            'state': 'published',
+                            'url': dep_unit.absolute_url(),
+                            'authority': {
+                                'ark': org.ark,
+                                'name': org.name,
+                                'url': org.absolute_url(),
+                            },
+                        },
+                        {
+                            'ark': deprecated_dep_unit.ark,
+                            'name': deprecated_dep_unit.name,
+                            'state': 'deprecated',
+                            'url': deprecated_dep_unit.absolute_url(),
+                            'authority': {
+                                'ark': org.ark,
+                                'name': org.name,
+                                'url': org.absolute_url(),
+                            },
+                        },
+                        {
+                            'ark': dep2_unit.ark,
+                            'name': dep2_unit.name,
+                            'state': 'published',
+                            'url': dep2_unit.absolute_url(),
+                            'authority': {
+                                'ark': org2.ark,
+                                'name': org2.name,
+                                'url': org2.absolute_url(),
+                            },
+                        },
+                    ],
+                },
+            ]
             result[0]['deposit-units'].sort()
-            self.assertEqual(
-                result,
-                [{'ark': archival_unit.ark,
-                  'name': 'Archival Dptmt',
-                  'state': 'published',
-                  'url': archival_unit.absolute_url(),
-                  'authority': {
-                      'ark': org.ark,
-                      'name': org.name,
-                      'url': org.absolute_url(),
-                  },
-                  'deposit-units': [
-                      {
-                          'ark': dep_unit.ark,
-                          'name': dep_unit.name,
-                          'state': 'published',
-                          'url': dep_unit.absolute_url(),
-                          'authority': {
-                              'ark': org.ark,
-                              'name': org.name,
-                              'url': org.absolute_url(),
-                          },
-                      },
-                      {
-                          'ark': deprecated_dep_unit.ark,
-                          'name': deprecated_dep_unit.name,
-                          'state': 'deprecated',
-                          'url': deprecated_dep_unit.absolute_url(),
-                          'authority': {
-                              'ark': org.ark,
-                              'name': org.name,
-                              'url': org.absolute_url(),
-                          },
-                      },
-                      {
-                          'ark': dep2_unit.ark,
-                          'name': dep2_unit.name,
-                          'state': 'published',
-                          'url': dep2_unit.absolute_url(),
-                          'authority': {
-                              'ark': org2.ark,
-                              'name': org2.name,
-                              'url': org2.absolute_url(),
-                          },
-                      },
-                  ]}])
+            expected[0]['deposit-units'].sort()
+            self.assertEqual(result, expected)
 
 
 class TimelineViewsTC(CubicWebTC):



More information about the saem-devel mailing list