File tree Expand file tree Collapse file tree 4 files changed +18
-19
lines changed Expand file tree Collapse file tree 4 files changed +18
-19
lines changed Original file line number Diff line number Diff line change 2
2
Parsing and validating the YAML configuration occurs within this module
3
3
"""
4
4
import logging
5
- from functools import lru_cache
6
5
7
6
from pydantic import ValidationError
8
7
from pydantic_yaml import parse_yaml_raw_as
@@ -18,12 +17,6 @@ class ConfigError(Exception):
18
17
"""Error when an exception occurs during processing config"""
19
18
20
19
21
- @lru_cache
22
- def get_actions () -> Actions :
23
- """Load actions from file determined by ENV name"""
24
- return get_actions_from_file (f"config/config.{ settings .env } .yaml" )
25
-
26
-
27
20
def get_actions_from_file (jbi_config_file : str ) -> Actions :
28
21
"""Convert and validate YAML configuration to `Action` objects"""
29
22
try :
@@ -34,3 +27,10 @@ def get_actions_from_file(jbi_config_file: str) -> Actions:
34
27
except ValidationError as exception :
35
28
logger .exception (exception )
36
29
raise ConfigError ("Errors exist." ) from exception
30
+
31
+
32
+ def get_actions (env = settings .env ):
33
+ return get_actions_from_file (f"config/config.{ env } .yaml" )
34
+
35
+
36
+ ACTIONS = get_actions ()
Original file line number Diff line number Diff line change 9
9
from fastapi .responses import HTMLResponse
10
10
from fastapi .templating import Jinja2Templates
11
11
12
- from jbi .configuration import get_actions
12
+ from jbi .configuration import ACTIONS
13
13
from jbi .environment import Settings , get_settings , get_version
14
14
from jbi .models import Actions , BugzillaWebhookRequest
15
15
from jbi .runner import IgnoreInvalidRequestError , execute_action
16
16
from jbi .services import bugzilla , jira
17
17
18
18
SettingsDep = Annotated [Settings , Depends (get_settings )]
19
- ActionsDep = Annotated [Actions , Depends (get_actions )]
19
+ ActionsDep = Annotated [Actions , Depends (lambda : ACTIONS )]
20
20
VersionDep = Annotated [dict , Depends (get_version )]
21
21
BugzillaServiceDep = Annotated [bugzilla .BugzillaService , Depends (bugzilla .get_service )]
22
22
JiraServiceDep = Annotated [jira .JiraService , Depends (jira .get_service )]
Original file line number Diff line number Diff line change @@ -83,8 +83,7 @@ def settings():
83
83
84
84
@pytest .fixture (autouse = True )
85
85
def actions ():
86
- get_actions .cache_clear ()
87
- return get_actions ()
86
+ return get_actions
88
87
89
88
90
89
@pytest .fixture (autouse = True )
Original file line number Diff line number Diff line change 1
- from unittest import mock
2
-
3
1
import pytest
4
2
5
- from jbi import configuration , environment
3
+ from jbi import configuration
6
4
7
5
8
6
def test_mock_jbi_files ():
@@ -22,8 +20,10 @@ def test_actual_jbi_files():
22
20
)
23
21
24
22
25
- def test_filename_uses_env ():
26
- configuration .get_actions .cache_clear ()
27
- with mock .patch ("jbi.configuration.get_actions_from_file" ) as mocked :
28
- configuration .get_actions ()
29
- mocked .assert_called_with ("config/config.local.yaml" )
23
+ def test_filename_uses_env (mocker , actions , settings ):
24
+ get_actions_from_file_spy = mocker .spy (configuration , "get_actions_from_file" )
25
+ assert settings .env == "local"
26
+
27
+ configuration .get_actions ()
28
+
29
+ get_actions_from_file_spy .assert_called_with ("config/config.local.yaml" )
You can’t perform that action at this time.
0 commit comments