URL: https://github.com/freeipa/freeipa/pull/1446
Author: felipevolpone
 Title: #1446: Fixing test_backup_and_restore assert to do not rely on the 
order of returned data
Action: opened

PR body:
"""
Since we cannot assume that LDAP will return data in an ordered way,
the test should be changed to do not rely on that.

Instead of just comparing the output of the show-user command, this change
first order the groups returned in the 'Member of Group' field before
compare them.

https://pagure.io/freeipa/issue/7339

The result (green tests) can be checked here:
https://fedorapeople.org/groups/freeipa/prci/jobs/c43c46d0-f4aa-11e7-925b-001a4a2316ab/

This PR depends on the PR #1354 
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1446/head:pr1446
git checkout pr1446
From 6c1f2dbc93a79d559428f4535d2b968e65831da0 Mon Sep 17 00:00:00 2001
From: Felipe Barreto <fbarr...@redhat.com>
Date: Mon, 8 Jan 2018 16:25:39 -0200
Subject: [PATCH] Fixing test_backup_and_restore assert to do not rely on the
 order

Since we cannot assume that LDAP will return data in any ordered way,
the test should be changed to do not rely on that.

Instead of just comparing the output of the show-user command, this change
first order the groups returned in the 'Member of Group' field before
compare them.

https://pagure.io/freeipa/issue/7339
---
 ipatests/test_integration/test_backup_and_restore.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/ipatests/test_integration/test_backup_and_restore.py b/ipatests/test_integration/test_backup_and_restore.py
index 4912bc2476..2723ada766 100644
--- a/ipatests/test_integration/test_backup_and_restore.py
+++ b/ipatests/test_integration/test_backup_and_restore.py
@@ -65,6 +65,26 @@ def check_admin_in_ldap(host):
 def check_admin_in_cli(host):
     result = host.run_command(['ipa', 'user-show', 'admin'])
     assert 'User login: admin' in result.stdout_text, result.stdout_text
+    output = result.stdout_text.split('\n')
+
+    # LDAP do not guarantee any order, so the test cannot assume it. Based on
+    # that, the code bellow order the 'Member of groups' field to able to
+    # assert it latter.
+
+    # field that contains the data to be ordered
+    GROUPS_MEMBER_FIELD = 9
+
+    # e.g: Member of groups: admins, trust admins
+    groups_field = output[GROUPS_MEMBER_FIELD].split(':')
+    label_part = groups_field[0]  # Member of groups
+    groups_part = groups_field[1:][0]  # admins, trust admins
+
+    # ordening groups and then putting them together separated by a comma
+    groups_orderned = ','.join(sorted(groups_part.split(','),
+                                      key=lambda group: group.strip()))
+
+    output[GROUPS_MEMBER_FIELD] = '{}:{}'.format(label_part, groups_orderned)
+    result.stdout_text = '\n'.join(output)
     return result
 
 
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to