15
15
# limitations under the License.
16
16
"""Renku service config view tests."""
17
17
18
+ import configparser
18
19
import json
20
+ import uuid
19
21
20
22
import pytest
21
23
@@ -43,6 +45,78 @@ def test_config_view_show(svc_client_with_repo):
43
45
assert 200 == response .status_code
44
46
45
47
48
+ @pytest .mark .service
49
+ @pytest .mark .integration
50
+ @retry_failed
51
+ @pytest .mark .remote_repo ("public" )
52
+ @pytest .mark .parametrize ("anonymous" , [False , True ])
53
+ def test_config_view_show_with_branch (svc_client_setup , anonymous ):
54
+ """Check config show view in a different branch."""
55
+ svc_client , headers , project_id , url_components , repository = svc_client_setup
56
+
57
+ if anonymous :
58
+ headers = {}
59
+
60
+ config_filepath = repository .path / ".renku" / "renku.ini"
61
+ current_branch = repository .active_branch .name
62
+ new_branch = uuid .uuid4 ().hex
63
+
64
+ # Write a default config value
65
+ config = configparser .ConfigParser ()
66
+ config .add_section ("interactive" )
67
+ config ["interactive" ]["default_url" ] = "/lab"
68
+ config .add_section ("renku" )
69
+ config ["renku" ]["test-config" ] = "current-branch"
70
+ with open (config_filepath , "w" ) as f :
71
+ config .write (f )
72
+
73
+ repository .add (all = True )
74
+ repository .commit ("master config" )
75
+ repository .push (remote = "origin" , refspec = current_branch )
76
+ current_commit_sha = repository .active_branch .commit .hexsha
77
+
78
+ # Create a new branch and a modified config
79
+ repository .branches .add (new_branch )
80
+ repository .checkout (new_branch )
81
+ config ["renku" ]["test-config" ] = "new-branch"
82
+ with open (config_filepath , "w" ) as f :
83
+ config .write (f )
84
+
85
+ repository .add (all = True )
86
+ repository .commit ("new config" )
87
+ repository .push (remote = "origin" , refspec = new_branch )
88
+
89
+ params = {
90
+ "git_url" : url_components .href ,
91
+ "branch" : current_branch ,
92
+ }
93
+
94
+ response = svc_client .get ("/config.show" , query_string = params , headers = headers )
95
+
96
+ assert 200 == response .status_code
97
+ assert "current-branch" == response .json ["result" ]["config" ].get ("renku.test-config" )
98
+
99
+ params = {
100
+ "git_url" : url_components .href ,
101
+ "branch" : new_branch ,
102
+ }
103
+
104
+ response = svc_client .get ("/config.show" , query_string = params , headers = headers )
105
+
106
+ assert 200 == response .status_code
107
+ assert "new-branch" == response .json ["result" ]["config" ].get ("renku.test-config" )
108
+
109
+ params = {
110
+ "git_url" : url_components .href ,
111
+ "branch" : current_commit_sha ,
112
+ }
113
+
114
+ response = svc_client .get ("/config.show" , query_string = params , headers = headers )
115
+
116
+ assert 200 == response .status_code
117
+ assert "current-branch" == response .json ["result" ]["config" ].get ("renku.test-config" )
118
+
119
+
46
120
@pytest .mark .service
47
121
@pytest .mark .integration
48
122
@retry_failed
@@ -133,7 +207,7 @@ def test_config_view_set(svc_client_with_repo):
133
207
@pytest .mark .service
134
208
@pytest .mark .integration
135
209
@retry_failed
136
- def test_config_view_set_nonexising_key_removal (svc_client_with_repo ):
210
+ def test_config_view_set_non_existing_key_removal (svc_client_with_repo ):
137
211
"""Check that removing a non-existing key (i.e. setting to None) is allowed."""
138
212
svc_client , headers , project_id , url_components = svc_client_with_repo
139
213
@@ -160,7 +234,7 @@ def test_config_view_set_and_show_failures(svc_client_with_repo):
160
234
"""Check errors triggered while invoking config set."""
161
235
svc_client , headers , project_id , url_components = svc_client_with_repo
162
236
163
- # NOTE: use sections with wrong chars introduces a readin error. Should we handle it at write time?
237
+ # NOTE: use sections with wrong chars introduces a reading error. Should we handle it at write time?
164
238
payload = {
165
239
"git_url" : url_components .href ,
166
240
"config" : {".NON_EXISTING" : "test" },
0 commit comments