[PATCH 09 of 11 saem_ref] Sort both result and expect responses in "archive-units" tests

Denis Laxalde denis.laxalde at logilab.fr
Mon Feb 12 15:20:45 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 c23060f902915e77cfde70d3e9a2b4252a17f550
# Parent  cdc498fe733dd4496575c874140c10e21e66fd3f
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r c23060f90291
# 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