1111
1212runner = CliRunner ()
1313
14- requires_python_310 = pytest .mark .skipif (sys .version_info < (3 , 10 ), reason = "Requires Python 3.10 or higher" )
14+ requires_python_310 = pytest .mark .skipif (
15+ sys .version_info < (3 , 10 ), reason = "Requires Python 3.10 or higher"
16+ )
1517
1618
1719@pytest .fixture
@@ -28,6 +30,54 @@ def mock_client() -> mock.Mock:
2830class TestInfrahubctlRepository :
2931 """Groups the 'infrahubctl repository' test cases."""
3032
33+ @requires_python_310
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+ ref: {
69+ value: ""
70+ }
71+ }
72+ ){
73+ ok
74+ }
75+ }
76+ """ ,
77+ branch_name = "main" ,
78+ tracker = "mutation-repository-create" ,
79+ )
80+
3181 @requires_python_310
3282 def test_repo_no_username (self , mock_init_client , mock_client ) -> None :
3383 """Case allow no username to be passed in and set it as None rather than blank string that fails."""
@@ -72,7 +122,7 @@ def test_repo_no_username(self, mock_init_client, mock_client) -> None:
72122 description: {
73123 value: ""
74124 }
75- commit : {
125+ ref : {
76126 value: ""
77127 }
78128 credential: {
@@ -134,7 +184,7 @@ def test_repo_username(self, mock_init_client, mock_client) -> None:
134184 description: {
135185 value: ""
136186 }
137- commit : {
187+ ref : {
138188 value: ""
139189 }
140190 credential: {
@@ -164,7 +214,7 @@ def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
164214 "repository" ,
165215 "add" ,
166216 "Gitlab" ,
167- "https://gitlab.com/FragmentedPacket/nautobot-plugin-ansible-filters .git" ,
217+ "https://gitlab.com/opsmill/example-repo .git" ,
168218 "--password" ,
169219 "mySup3rSecureP@ssw0rd" ,
170220 "--read-only" ,
@@ -190,12 +240,12 @@ def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
190240 value: "Gitlab"
191241 }
192242 location: {
193- value: "https://gitlab.com/FragmentedPacket/nautobot-plugin-ansible-filters .git"
243+ value: "https://gitlab.com/opsmill/example-repo .git"
194244 }
195245 description: {
196246 value: ""
197247 }
198- commit : {
248+ ref : {
199249 value: ""
200250 }
201251 credential: {
@@ -212,7 +262,9 @@ def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
212262 )
213263
214264 @requires_python_310
215- def test_repo_description_commit_branch (self , mock_init_client , mock_client ) -> None :
265+ def test_repo_description_commit_branch (
266+ self , mock_init_client , mock_client
267+ ) -> None :
216268 """Case allow no username to be passed in and set it as None rather than blank string that fails."""
217269 mock_cred = mock .AsyncMock ()
218270 mock_cred .id = "1234"
@@ -225,15 +277,15 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) ->
225277 "repository" ,
226278 "add" ,
227279 "Gitlab" ,
228- "https://gitlab.com/FragmentedPacket/nautobot-plugin-ansible-filters .git" ,
280+ "https://gitlab.com/opsmill/example-repo .git" ,
229281 "--password" ,
230282 "mySup3rSecureP@ssw0rd" ,
231283 "--username" ,
232284 "opsmill" ,
233285 "--description" ,
234286 "This is a test description" ,
235- "--commit " ,
236- "myHashCommit " ,
287+ "--ref " ,
288+ "my-custom-branch " ,
237289 "--branch" ,
238290 "develop" ,
239291 ],
@@ -258,13 +310,13 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) ->
258310 value: "Gitlab"
259311 }
260312 location: {
261- value: "https://gitlab.com/FragmentedPacket/nautobot-plugin-ansible-filters .git"
313+ value: "https://gitlab.com/opsmill/example-repo .git"
262314 }
263315 description: {
264316 value: "This is a test description"
265317 }
266- commit : {
267- value: "myHashCommit "
318+ ref : {
319+ value: "my-custom-branch "
268320 }
269321 credential: {
270322 id: "1234"
0 commit comments