Exemple #1
0
 def render(self, context: Dict = None, request: HttpRequest = None) -> str:
     with block_db():
         return super().render(context, request)
 def test_selective_blocking_allowed(self, blocked: str) -> None:
     not_blocked = DATABASE_ALIASES - {blocked}
     # No error raised, because queries aren't on blocked DB.
     with block_db(databases=[blocked]):
         for db in not_blocked:
             ExampleModel.objects.using(db).create()
 def test_selective_blocking_blocked(self, blocked: str) -> None:
     with pytest.raises(DatabaseAccessBlocked):
         with block_db(databases=[blocked]):
             ExampleModel.objects.using(blocked).create()
 def test_evaluated_queryset_allowed(self, database: str) -> None:
     queryset = list(ExampleModel.objects.using(database).all())
     with block_db():
         for model in queryset:
             pass
 def test_queryset_evaluation_blocked(self, database: str) -> None:
     queryset = ExampleModel.objects.using(database).all()
     with pytest.raises(DatabaseAccessBlocked):
         with block_db():
             list(queryset)
Exemple #6
0
 def test_evaluated_queryset_allowed(self) -> None:
     ExampleModel.objects.create()
     queryset = list(ExampleModel.objects.all())
     with block_db():
         for model in queryset:
             pass