From 7edd89281203c82450655cc230425df7c9a574b3 Mon Sep 17 00:00:00 2001 From: jmoore Date: Mon, 27 Jan 2020 16:04:30 +0100 Subject: [PATCH] test_user: don't assume single-threaded (see #6206) `omero user list` was compared to the output of iadmin.lookupExperimenters(). Depending on the interval, other users could have been added. Now we assume monotonically increasing users. --- .../test/integration/clitest/test_user.py | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/components/tools/OmeroPy/test/integration/clitest/test_user.py b/components/tools/OmeroPy/test/integration/clitest/test_user.py index ff4f2f5aa09..184126ffa74 100644 --- a/components/tools/OmeroPy/test/integration/clitest/test_user.py +++ b/components/tools/OmeroPy/test/integration/clitest/test_user.py @@ -68,22 +68,35 @@ def testList(self, capsys, sort_key, group_format): self.cli.invoke(self.args, strict=True) # Read from the stdout + before = self.sf.getAdminService().lookupExperimenters() out, err = capsys.readouterr() ids = get_user_ids(out, sort_key=sort_key) + after = self.sf.getAdminService().lookupExperimenters() - # Check all users are listed + # Check all users are listed under the assumption that + # users won't be _deleted_ by other threads. if sort_key == 'login': - sorted_list = sorted(self.users, key=lambda x: x.omeName.val) + sorted_before = sorted(before, key=lambda x: x.omeName.val) + sorted_after = sorted(after, key=lambda x: x.omeName.val) elif sort_key == 'first-name': - sorted_list = sorted(self.users, key=lambda x: x.firstName.val) + sorted_before = sorted(before, key=lambda x: x.firstName.val) + sorted_after = sorted(after, key=lambda x: x.firstName.val) elif sort_key == 'last-name': - sorted_list = sorted(self.users, key=lambda x: x.lastName.val) + sorted_before = sorted(before, key=lambda x: x.lastName.val) + sorted_after = sorted(after, key=lambda x: x.lastName.val) elif sort_key == 'email': - sorted_list = sorted(self.users, key=lambda x: ( + sorted_before = sorted(before, key=lambda x: ( + x.email and x.email.val or "")) + sorted_after = sorted(after, key=lambda x: ( x.email and x.email.val or "")) else: - sorted_list = sorted(self.users, key=lambda x: x.id.val) - assert ids == [user.id.val for user in sorted_list] + sorted_before = sorted(before, key=lambda x: x.id.val) + sorted_after = sorted(after, key=lambda x: x.id.val) + + for lhs, rhs in (([user.id.val for user in sorted_before], ids), + (ids, [user.id.val for user in sorted_after])): + assert len(lhs) <= len(rhs) + assert lhs == rhs[0:len(lhs)] @pytest.mark.parametrize("style", [None, "sql", "csv", "plain", "json"]) def testListWithStyles(self, capsys, style):