mirror of https://github.com/zulip/zulip.git
tests: Fix test coverage on recent commit.
I guess `test_classes` has 100% line coverage enforcement, which is a bit tricky for error handling. This fixes that, as well as making the name snake_case and improving the format of the errors.
This commit is contained in:
parent
80acbb9fdf
commit
42ee2f5e86
|
@ -821,10 +821,10 @@ class ZulipTestCase(TestCase):
|
||||||
r for r in data
|
r for r in data
|
||||||
if r['id'] == db_id][0]
|
if r['id'] == db_id][0]
|
||||||
|
|
||||||
def findOne(self,
|
def find_one(self,
|
||||||
lst: List[Any],
|
lst: List[Any],
|
||||||
predicate: Callable[[Any], bool],
|
predicate: Callable[[Any], bool],
|
||||||
member_name: str) -> Any:
|
member_name: str) -> Any:
|
||||||
matches = [
|
matches = [
|
||||||
item for item in lst
|
item for item in lst
|
||||||
if predicate(item)
|
if predicate(item)
|
||||||
|
@ -834,23 +834,27 @@ class ZulipTestCase(TestCase):
|
||||||
# Happy path!
|
# Happy path!
|
||||||
return matches[0]
|
return matches[0]
|
||||||
|
|
||||||
print('\nERROR: findOne fails on this list:\n')
|
if True: # nocoverage
|
||||||
|
print('\nERROR: findOne fails on this list:\n')
|
||||||
|
print('[')
|
||||||
|
|
||||||
for item in lst:
|
for item in lst:
|
||||||
print(item)
|
print(' ', item, ',')
|
||||||
|
|
||||||
|
print(']')
|
||||||
|
|
||||||
|
if len(matches) == 0:
|
||||||
|
raise ValueError(
|
||||||
|
'No matches: {}'.format(member_name)
|
||||||
|
)
|
||||||
|
|
||||||
if len(matches) == 0:
|
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'No matches: {}'.format(member_name)
|
'Too many matches ({}): {}'.format(
|
||||||
|
len(matches),
|
||||||
|
member_name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
raise ValueError(
|
|
||||||
'Too many matches ({}): {}'.format(
|
|
||||||
len(matches),
|
|
||||||
member_name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def init_default_ldap_database(self) -> None:
|
def init_default_ldap_database(self) -> None:
|
||||||
"""
|
"""
|
||||||
Takes care of the mock_ldap setup, loads
|
Takes care of the mock_ldap setup, loads
|
||||||
|
|
|
@ -1387,7 +1387,7 @@ class GetProfileTest(ZulipTestCase):
|
||||||
result = self.api_get(hamlet, "/api/v1/users")
|
result = self.api_get(hamlet, "/api/v1/users")
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
my_user = self.findOne(
|
my_user = self.find_one(
|
||||||
result.json()['members'],
|
result.json()['members'],
|
||||||
lambda user: user['email'] == hamlet.email,
|
lambda user: user['email'] == hamlet.email,
|
||||||
'member for Hamlet'
|
'member for Hamlet'
|
||||||
|
|
Loading…
Reference in New Issue