@@ -22,7 +22,7 @@ def test_init_default(self, monkeypatch):
2222 assert editor .raise_on_failure is True
2323
2424 def test_init_with_parameters (self ):
25- token = Secret .from_token ("test_token " )
25+ token = Secret .from_token ("test-token " )
2626 editor = GithubFileEditor (github_token = token , repo = "owner/repo" , branch = "feature" , raise_on_failure = False )
2727 assert editor .github_token == token
2828 assert editor .default_repo == "owner/repo"
@@ -33,7 +33,7 @@ def test_init_with_parameters(self):
3333 GithubFileEditor (github_token = "not_a_secret" )
3434
3535 def test_to_dict (self , monkeypatch ):
36- monkeypatch .setenv ("ENV_VAR" , "test_token " )
36+ monkeypatch .setenv ("ENV_VAR" , "test-token " )
3737
3838 token = Secret .from_env_var ("ENV_VAR" )
3939
@@ -52,7 +52,7 @@ def test_to_dict(self, monkeypatch):
5252 }
5353
5454 def test_from_dict (self , monkeypatch ):
55- monkeypatch .setenv ("ENV_VAR" , "test_token " )
55+ monkeypatch .setenv ("ENV_VAR" , "test-token " )
5656 data = {
5757 "type" : "haystack_integrations.components.connectors.github.file_editor.GithubFileEditor" ,
5858 "init_parameters" : {
@@ -72,16 +72,17 @@ def test_from_dict(self, monkeypatch):
7272
7373 @patch ("requests.get" )
7474 @patch ("requests.put" )
75- def test_run_edit (self , mock_put , mock_get ):
75+ def test_run_edit (self , mock_put , mock_get , monkeypatch ):
76+ monkeypatch .setenv ("GITHUB_TOKEN" , "test-token" )
77+
7678 mock_get .return_value .json .return_value = {
7779 "content" : "SGVsbG8gV29ybGQ=" , # Base64 encoded "Hello World"
7880 "sha" : "abc123" ,
7981 }
8082 mock_get .return_value .raise_for_status .return_value = None
8183 mock_put .return_value .raise_for_status .return_value = None
8284
83- token = Secret .from_token ("test_token" )
84- editor = GithubFileEditor (github_token = token )
85+ editor = GithubFileEditor ()
8586
8687 result = editor .run (
8788 command = Command .EDIT ,
@@ -97,7 +98,7 @@ def test_run_edit(self, mock_put, mock_get):
9798 headers = {
9899 "Accept" : "application/vnd.github.v3+json" ,
99100 "User-Agent" : "Haystack/GithubFileEditor" ,
100- "Authorization" : "Bearer test_token " ,
101+ "Authorization" : "Bearer test-token " ,
101102 },
102103 params = {"ref" : "main" },
103104 timeout = 10 ,
@@ -112,7 +113,9 @@ def test_run_edit(self, mock_put, mock_get):
112113
113114 @patch ("requests.get" )
114115 @patch ("requests.patch" )
115- def test_run_undo (self , mock_patch , mock_get ):
116+ def test_run_undo (self , mock_patch , mock_get , monkeypatch ):
117+ monkeypatch .setenv ("GITHUB_TOKEN" , "test-token" )
118+
116119 def create_mock_response (json_data , status_code = 200 ):
117120 class MockResponse :
118121 def __init__ (self , data , code ):
@@ -143,8 +146,7 @@ def get_side_effect(url, **_):
143146
144147 mock_patch .return_value .raise_for_status .return_value = None
145148
146- token = Secret .from_token ("test_token" )
147- editor = GithubFileEditor (github_token = token )
149+ editor = GithubFileEditor ()
148150
149151 result = editor .run (
150152 command = Command .UNDO , payload = {"message" : "Undo last change" }, repo = "owner/repo" , branch = "main"
@@ -158,18 +160,19 @@ def get_side_effect(url, **_):
158160 headers = {
159161 "Accept" : "application/vnd.github.v3+json" ,
160162 "User-Agent" : "Haystack/GithubFileEditor" ,
161- "Authorization" : "Bearer test_token " ,
163+ "Authorization" : "Bearer test-token " ,
162164 },
163165 json = {"sha" : "def456" , "force" : True },
164166 timeout = 10 ,
165167 )
166168
167169 @patch ("requests.put" )
168- def test_run_create (self , mock_put ):
170+ def test_run_create (self , mock_put , monkeypatch ):
171+ monkeypatch .setenv ("GITHUB_TOKEN" , "test-token" )
172+
169173 mock_put .return_value .raise_for_status .return_value = None
170174
171- token = Secret .from_token ("test_token" )
172- editor = GithubFileEditor (github_token = token )
175+ editor = GithubFileEditor ()
173176
174177 result = editor .run (
175178 command = Command .CREATE ,
@@ -185,7 +188,7 @@ def test_run_create(self, mock_put):
185188 headers = {
186189 "Accept" : "application/vnd.github.v3+json" ,
187190 "User-Agent" : "Haystack/GithubFileEditor" ,
188- "Authorization" : "Bearer test_token " ,
191+ "Authorization" : "Bearer test-token " ,
189192 },
190193 json = {
191194 "message" : "Create new file" ,
@@ -197,7 +200,9 @@ def test_run_create(self, mock_put):
197200
198201 @patch ("requests.get" )
199202 @patch ("requests.delete" )
200- def test_run_delete (self , mock_delete , mock_get ):
203+ def test_run_delete (self , mock_delete , mock_get , monkeypatch ):
204+ monkeypatch .setenv ("GITHUB_TOKEN" , "test-token" )
205+
201206 mock_get .return_value .json .return_value = {
202207 "content" : "SGVsbG8gV29ybGQ=" , # Base64 encoded "Hello World"
203208 "sha" : "abc123" ,
@@ -206,8 +211,7 @@ def test_run_delete(self, mock_delete, mock_get):
206211
207212 mock_delete .return_value .raise_for_status .return_value = None
208213
209- token = Secret .from_token ("test_token" )
210- editor = GithubFileEditor (github_token = token )
214+ editor = GithubFileEditor ()
211215
212216 result = editor .run (
213217 command = Command .DELETE ,
@@ -223,7 +227,7 @@ def test_run_delete(self, mock_delete, mock_get):
223227 headers = {
224228 "Accept" : "application/vnd.github.v3+json" ,
225229 "User-Agent" : "Haystack/GithubFileEditor" ,
226- "Authorization" : "Bearer test_token " ,
230+ "Authorization" : "Bearer test-token " ,
227231 },
228232 params = {"ref" : "main" },
229233 timeout = 10 ,
@@ -234,18 +238,19 @@ def test_run_delete(self, mock_delete, mock_get):
234238 headers = {
235239 "Accept" : "application/vnd.github.v3+json" ,
236240 "User-Agent" : "Haystack/GithubFileEditor" ,
237- "Authorization" : "Bearer test_token " ,
241+ "Authorization" : "Bearer test-token " ,
238242 },
239243 json = {"message" : "Delete file" , "sha" : "abc123" , "branch" : "main" },
240244 timeout = 10 ,
241245 )
242246
243247 @patch ("requests.get" )
244- def test_run_error_handling (self , mock_get ):
248+ def test_run_error_handling (self , mock_get , monkeypatch ):
249+ monkeypatch .setenv ("GITHUB_TOKEN" , "test-token" )
250+
245251 mock_get .side_effect = requests .RequestException ("API Error" )
246252
247- token = Secret .from_token ("test_token" )
248- editor = GithubFileEditor (github_token = token , raise_on_failure = False )
253+ editor = GithubFileEditor (raise_on_failure = False )
249254
250255 result = editor .run (
251256 command = Command .EDIT ,
@@ -256,7 +261,7 @@ def test_run_error_handling(self, mock_get):
256261
257262 assert "Error: API Error" in result ["result" ]
258263
259- editor = GithubFileEditor (github_token = token , raise_on_failure = True )
264+ editor = GithubFileEditor (raise_on_failure = True )
260265 with pytest .raises (requests .RequestException ):
261266 editor .run (
262267 command = Command .EDIT ,
0 commit comments