22import os
33import tempfile
44from configparser import ConfigParser
5+ from pathlib import Path
56from unittest import TestCase
67from unittest .mock import patch
78
@@ -30,7 +31,6 @@ def test_init_via_token(self, get_team_use_case):
3031 @patch ("lib.core.usecases.GetTeamUseCase" )
3132 def test_init_via_config_json (self , get_team_use_case ):
3233 with tempfile .TemporaryDirectory () as config_dir :
33- constants .HOME_PATH = config_dir
3434 config_ini_path = f"{ config_dir } /config.ini"
3535 config_json_path = f"{ config_dir } /config.json"
3636 with patch ("lib.core.CONFIG_INI_FILE_LOCATION" , config_ini_path ), patch (
@@ -48,7 +48,6 @@ def test_init_via_config_json(self, get_team_use_case):
4848
4949 def test_init_via_config_json_invalid_json (self ):
5050 with tempfile .TemporaryDirectory () as config_dir :
51- constants .HOME_PATH = config_dir
5251 config_ini_path = f"{ config_dir } /config.ini"
5352 config_json_path = f"{ config_dir } /config.json"
5453 with patch ("lib.core.CONFIG_INI_FILE_LOCATION" , config_ini_path ), patch (
@@ -65,7 +64,6 @@ def test_init_via_config_json_invalid_json(self):
6564 @patch ("lib.core.usecases.GetTeamUseCase" )
6665 def test_init_via_config_ini (self , get_team_use_case ):
6766 with tempfile .TemporaryDirectory () as config_dir :
68- constants .HOME_PATH = config_dir
6967 config_ini_path = f"{ config_dir } /config.ini"
7068 config_json_path = f"{ config_dir } /config.json"
7169 with patch ("lib.core.CONFIG_INI_FILE_LOCATION" , config_ini_path ), patch (
@@ -88,6 +86,34 @@ def test_init_via_config_ini(self, get_team_use_case):
8886 self ._token .split ("=" )[- 1 ]
8987 )
9088
89+ @patch ("lib.core.usecases.GetTeamUseCase" )
90+ def test_init_via_config_relative_filepath (self , get_team_use_case ):
91+ with tempfile .TemporaryDirectory (dir = Path ("~" ).expanduser ()) as config_dir :
92+ config_ini_path = f"{ config_dir } /config.ini"
93+ config_json_path = f"{ config_dir } /config.json"
94+ with patch ("lib.core.CONFIG_INI_FILE_LOCATION" , config_ini_path ), patch (
95+ "lib.core.CONFIG_JSON_FILE_LOCATION" , config_json_path
96+ ):
97+ with open (f"{ config_dir } /config.ini" , "w" ) as config_ini :
98+ config_parser = ConfigParser ()
99+ config_parser .optionxform = str
100+ config_parser ["DEFAULT" ] = {
101+ "SA_TOKEN" : self ._token ,
102+ "LOGGING_LEVEL" : "DEBUG" ,
103+ }
104+ config_parser .write (config_ini )
105+ for kwargs in (
106+ {},
107+ {"config_path" : f"~/{ Path (config_dir ).name } /config.ini" },
108+ ):
109+ sa = SAClient (** kwargs )
110+ assert sa .controller ._config .API_TOKEN == self ._token
111+ assert sa .controller ._config .LOGGING_LEVEL == "DEBUG"
112+ assert sa .controller ._config .API_URL == constants .BACKEND_URL
113+ assert get_team_use_case .call_args_list [0 ].kwargs ["team_id" ] == int (
114+ self ._token .split ("=" )[- 1 ]
115+ )
116+
91117 @patch ("lib.core.usecases.GetTeamUseCase" )
92118 @patch .dict (os .environ , {"SA_URL" : "SOME_URL" , "SA_TOKEN" : "SOME_TOKEN=123" })
93119 def test_init_env (self , get_team_use_case ):
@@ -103,7 +129,6 @@ def test_init_env_invalid_token(self):
103129
104130 def test_init_via_config_ini_invalid_token (self ):
105131 with tempfile .TemporaryDirectory () as config_dir :
106- constants .HOME_PATH = config_dir
107132 config_ini_path = f"{ config_dir } /config.ini"
108133 config_json_path = f"{ config_dir } /config.json"
109134 with patch ("lib.core.CONFIG_INI_FILE_LOCATION" , config_ini_path ), patch (
0 commit comments