File tree Expand file tree Collapse file tree 3 files changed +19
-18
lines changed Expand file tree Collapse file tree 3 files changed +19
-18
lines changed Original file line number Diff line number Diff line change
1
+ import logging
2
+
1
3
import orjson
2
4
from dramatiq import set_broker , set_encoder
3
5
from dramatiq .broker import Broker
@@ -26,15 +28,17 @@ def decode(self, data: bytes) -> MessageData:
26
28
27
29
28
30
def init_dramatiq (config : AppConfig ):
29
- DramatiqInstrumentor ().instrument ()
30
31
broker : Broker
31
- if config . ENVIRONMENT == "test" :
32
- broker = StubBroker ()
33
- # broker.emit_after("process_boot")
34
- elif config .DRAMATIQ .REDIS_URL is not None :
32
+
33
+ DramatiqInstrumentor (). instrument ()
34
+
35
+ if config .DRAMATIQ .REDIS_URL is not None :
35
36
broker = RedisBroker (url = config .DRAMATIQ .REDIS_URL )
36
37
else :
37
- raise RuntimeError ("Running a non-test environment without Redis URL set" )
38
+ broker = StubBroker ()
39
+ # broker.emit_after("process_boot")
40
+ if config .ENVIRONMENT != "test" :
41
+ logging .critical ("Running a non-test environment without Redis URL set" )
38
42
broker .add_middleware (AsyncIO ())
39
43
set_broker (broker )
40
44
set_encoder (ORJSONEncoder ())
Original file line number Diff line number Diff line change
1
+ import logging
1
2
from unittest .mock import MagicMock , patch
2
3
3
4
import orjson
@@ -61,12 +62,12 @@ def test_init_dramatiq_with_redis():
61
62
assert isinstance (get_encoder (), ORJSONEncoder )
62
63
63
64
64
- def test_init_dramatiq_without_redis_url ():
65
+ def test_init_dramatiq_without_redis_url (caplog ):
65
66
"""Test if an exception is raised when in non-test environment without Redis URL."""
66
67
config = AppConfig (
67
68
ENVIRONMENT = "production" , DRAMATIQ = DramatiqConfig (REDIS_URL = None )
68
69
) # Mock config
69
- with pytest .raises (
70
- RuntimeError , match = "Running a non-test environment without Redis URL set"
71
- ):
70
+ with caplog .at_level (logging .CRITICAL ):
72
71
init_dramatiq (config )
72
+
73
+ assert "Running a non-test environment without Redis URL set" in caplog .text
Original file line number Diff line number Diff line change 1
1
from unittest .mock import patch
2
2
3
- import pytest
4
-
5
3
from common .config import AppConfig
6
4
from http_app import create_app
7
5
8
6
9
7
def test_with_default_config () -> None :
10
- """Test create_app fails without passing test config."""
11
- with (
12
- patch ("common.bootstrap.init_storage" , return_value = None ),
13
- pytest .raises (RuntimeError ),
14
- ):
15
- create_app ()
8
+ """Test create_app without passing test config."""
9
+ with patch ("common.bootstrap.init_storage" , return_value = None ):
10
+ app = create_app ()
11
+ assert app .debug is False
16
12
17
13
18
14
def test_with_debug_config () -> None :
You can’t perform that action at this time.
0 commit comments