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

Denis Laxalde denis.laxalde at logilab.fr
Wed Feb 14 15:32:41 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 fa43b368824b1d6b1f2020d1f155bf3bc3bd1ecf
# Parent  85c64e5dd3da4a4a2dd59057abc8d3554b6bcba1
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r fa43b368824b
# 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