@@ -29,6 +29,55 @@ def mock_client() -> mock.Mock:
2929class TestInfrahubctlRepository :
3030 """Groups the 'infrahubctl repository' test cases."""
3131
32+ @requires_python_310
33+ @mock .patch ("infrahub_sdk.ctl.repository.initialize_client" )
34+ def test_repo_no_username_or_password (self , mock_init_client , mock_client ) -> None :
35+ """Case allow no username to be passed in and set it as None rather than blank string that fails."""
36+ mock_cred = mock .AsyncMock ()
37+ mock_cred .id = "1234"
38+ mock_client .create .return_value = mock_cred
39+
40+ mock_init_client .return_value = mock_client
41+ output = runner .invoke (
42+ app ,
43+ [
44+ "repository" ,
45+ "add" ,
46+ "Gitlab" ,
47+ "https://gitlab.com/opsmill/example-repo.git" ,
48+ ],
49+ )
50+ assert output .exit_code == 0
51+ mock_client .create .assert_not_called ()
52+ mock_cred .save .assert_not_called ()
53+ mock_client .execute_graphql .assert_called_once ()
54+ mock_client .execute_graphql .assert_called_with (
55+ query = """
56+ mutation {
57+ CoreRepositoryCreate(
58+ data: {
59+ name: {
60+ value: "Gitlab"
61+ }
62+ location: {
63+ value: "https://gitlab.com/opsmill/example-repo.git"
64+ }
65+ description: {
66+ value: ""
67+ }
68+ default_branch: {
69+ value: ""
70+ }
71+ }
72+ ){
73+ ok
74+ }
75+ }
76+ """ ,
77+ branch_name = "main" ,
78+ tracker = "mutation-repository-create" ,
79+ )
80+
3281 @requires_python_310
3382 @mock .patch ("infrahub_sdk.ctl.repository.initialize_client" )
3483 def test_repo_no_username (self , mock_init_client , mock_client ) -> None :
@@ -74,7 +123,7 @@ def test_repo_no_username(self, mock_init_client, mock_client) -> None:
74123 description: {
75124 value: ""
76125 }
77- commit : {
126+ default_branch : {
78127 value: ""
79128 }
80129 credential: {
@@ -137,7 +186,7 @@ def test_repo_username(self, mock_init_client, mock_client) -> None:
137186 description: {
138187 value: ""
139188 }
140- commit : {
189+ default_branch : {
141190 value: ""
142191 }
143192 credential: {
@@ -168,7 +217,7 @@ def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
168217 "repository" ,
169218 "add" ,
170219 "Gitlab" ,
171- "https://gitlab.com/FragmentedPacket/nautobot-plugin-ansible-filters .git" ,
220+ "https://gitlab.com/opsmill/example-repo .git" ,
172221 "--password" ,
173222 "mySup3rSecureP@ssw0rd" ,
174223 "--read-only" ,
@@ -194,12 +243,12 @@ def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
194243 value: "Gitlab"
195244 }
196245 location: {
197- value: "https://gitlab.com/FragmentedPacket/nautobot-plugin-ansible-filters .git"
246+ value: "https://gitlab.com/opsmill/example-repo .git"
198247 }
199248 description: {
200249 value: ""
201250 }
202- commit : {
251+ ref : {
203252 value: ""
204253 }
205254 credential: {
@@ -230,15 +279,15 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) ->
230279 "repository" ,
231280 "add" ,
232281 "Gitlab" ,
233- "https://gitlab.com/FragmentedPacket/nautobot-plugin-ansible-filters .git" ,
282+ "https://gitlab.com/opsmill/example-repo .git" ,
234283 "--password" ,
235284 "mySup3rSecureP@ssw0rd" ,
236285 "--username" ,
237286 "opsmill" ,
238287 "--description" ,
239288 "This is a test description" ,
240- "--commit " ,
241- "myHashCommit " ,
289+ "--ref " ,
290+ "my-custom-branch " ,
242291 "--branch" ,
243292 "develop" ,
244293 ],
@@ -263,13 +312,13 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) ->
263312 value: "Gitlab"
264313 }
265314 location: {
266- value: "https://gitlab.com/FragmentedPacket/nautobot-plugin-ansible-filters .git"
315+ value: "https://gitlab.com/opsmill/example-repo .git"
267316 }
268317 description: {
269318 value: "This is a test description"
270319 }
271- commit : {
272- value: "myHashCommit "
320+ default_branch : {
321+ value: "my-custom-branch "
273322 }
274323 credential: {
275324 id: "1234"
0 commit comments