test_classes: Generalize assert_length helper.

Make it so that `assert_length` can be used for not
just lists but all `Collections`.

This is prep for using this helper consistently for
all tests.
This commit is contained in:
Abhijeet Prasad Bodas 2021-05-17 09:09:37 +05:30 committed by Tim Abbott
parent ddfb9b5200
commit 4d45b45640
1 changed files with 4 additions and 3 deletions

View File

@ -10,6 +10,7 @@ from datetime import timedelta
from typing import (
Any,
Callable,
Collection,
Dict,
Iterable,
Iterator,
@ -864,14 +865,14 @@ Output:
"""
self.assertEqual(self.get_json_error(result, status_code=status_code), msg)
def assert_length(self, items: List[Any], count: int) -> None:
def assert_length(self, items: Collection[Any], count: int) -> None:
actual_count = len(items)
if actual_count != count: # nocoverage
print("ITEMS:\n")
print("\nITEMS:\n")
for item in items:
print(item)
print(f"\nexpected length: {count}\nactual length: {actual_count}")
raise AssertionError("List is unexpected size!")
raise AssertionError(f"{str(type(items))} is of unexpected size!")
def assert_json_error_contains(
self, result: HttpResponse, msg_substring: str, status_code: int = 400