mirror of
https://github.com/zulip/zulip.git
synced 2025-10-31 20:13:46 +00:00
tests: Kill off find_one() helper.
This was only recently added. Using tuple assignment raises the same errors, so the indirection probably isn't worth it.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from contextlib import contextmanager
|
||||
from email.utils import parseaddr
|
||||
from fakeldap import MockLDAP
|
||||
from typing import (cast, Any, Callable, Dict, Iterable,
|
||||
from typing import (cast, Any, Dict, Iterable,
|
||||
Iterator, List, Optional,
|
||||
Tuple, Union, Set)
|
||||
|
||||
@@ -821,40 +821,6 @@ class ZulipTestCase(TestCase):
|
||||
r for r in data
|
||||
if r['id'] == db_id][0]
|
||||
|
||||
def find_one(self,
|
||||
lst: List[Any],
|
||||
predicate: Callable[[Any], bool],
|
||||
member_name: str) -> Any:
|
||||
matches = [
|
||||
item for item in lst
|
||||
if predicate(item)
|
||||
]
|
||||
|
||||
if len(matches) == 1:
|
||||
# Happy path!
|
||||
return matches[0]
|
||||
|
||||
if True: # nocoverage
|
||||
print('\nERROR: findOne fails on this list:\n')
|
||||
print('[')
|
||||
|
||||
for item in lst:
|
||||
print(' ', item, ',')
|
||||
|
||||
print(']')
|
||||
|
||||
if len(matches) == 0:
|
||||
raise ValueError(
|
||||
'No matches: {}'.format(member_name)
|
||||
)
|
||||
|
||||
raise ValueError(
|
||||
'Too many matches ({}): {}'.format(
|
||||
len(matches),
|
||||
member_name
|
||||
)
|
||||
)
|
||||
|
||||
def init_default_ldap_database(self) -> None:
|
||||
"""
|
||||
Takes care of the mock_ldap setup, loads
|
||||
|
||||
@@ -1451,11 +1451,10 @@ class GetProfileTest(ZulipTestCase):
|
||||
result = self.api_get(hamlet, "/api/v1/users")
|
||||
self.assert_json_success(result)
|
||||
|
||||
my_user = self.find_one(
|
||||
result.json()['members'],
|
||||
lambda user: user['email'] == hamlet.email,
|
||||
'member for Hamlet'
|
||||
)
|
||||
(my_user,) = [
|
||||
user for user in result.json()['members']
|
||||
if user['email'] == hamlet.email
|
||||
]
|
||||
|
||||
self.assertEqual(
|
||||
my_user['avatar_url'],
|
||||
|
||||
Reference in New Issue
Block a user