test_helpers: Make use_db_models generic.

We use this decorator on subclasses of `MigrationsTestCase`, which does
not have `self`s being `MigrationsTestCase`, but the corresponding
subclass.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-07-15 14:15:06 -04:00
committed by Tim Abbott
parent 3404282927
commit 9d1ef72f08

View File

@@ -570,10 +570,13 @@ def create_s3_buckets(*bucket_names: str) -> List[Bucket]:
return buckets
TestCaseT = TypeVar("TestCaseT", bound="MigrationsTestCase")
def use_db_models(
method: Callable[["MigrationsTestCase", StateApps], None]
) -> Callable[["MigrationsTestCase", StateApps], None]: # nocoverage
def method_patched_with_mock(self: "MigrationsTestCase", apps: StateApps) -> None:
method: Callable[[TestCaseT, StateApps], None]
) -> Callable[[TestCaseT, StateApps], None]: # nocoverage
def method_patched_with_mock(self: TestCaseT, apps: StateApps) -> None:
ArchivedAttachment = apps.get_model("zerver", "ArchivedAttachment")
ArchivedMessage = apps.get_model("zerver", "ArchivedMessage")
ArchivedUserMessage = apps.get_model("zerver", "ArchivedUserMessage")