コード例 #1
0
def test_readonly_middleware_is_writable(_request):
    with patch('django_replicated.dbchecker.is_writable') as is_writable_mock:
        is_writable_mock.return_value = False

        ReadOnlyMiddleware().process_request(_request)

        assert _request.service_is_readonly
コード例 #2
0
def test_readonly_middleware_check_db(_request):
    with patch('django_replicated.dbchecker.check_db') as check_db_mock:
        check_db_mock.return_value = True

        ReadOnlyMiddleware().process_request(_request)

        check_db_mock.assert_not_called()
        assert not _request.service_is_readonly
        assert check_db_mock.call_count == 2