88from infrahub_sdk .client import InfrahubClient
99from infrahub_sdk .ctl .cli_commands import app
1010
11+ from tests .helpers .fixtures import read_fixture
12+ from tests .helpers .utils import strip_color
13+
14+
1115runner = CliRunner ()
1216
1317
@@ -21,10 +25,10 @@ def mock_client() -> mock.Mock:
2125# ---------------------------------------------------------
2226# infrahubctl repository command tests
2327# ---------------------------------------------------------
24- @mock .patch ("infrahub_sdk.ctl.repository.initialize_client" )
2528class TestInfrahubctlRepository :
2629 """Groups the 'infrahubctl repository' test cases."""
2730
31+ @mock .patch ("infrahub_sdk.ctl.repository.initialize_client" )
2832 def test_repo_no_username (self , mock_init_client , mock_client ) -> None :
2933 """Case allow no username to be passed in and set it as None rather than blank string that fails."""
3034 mock_cred = mock .AsyncMock ()
@@ -84,6 +88,7 @@ def test_repo_no_username(self, mock_init_client, mock_client) -> None:
8488 tracker = "mutation-repository-create" ,
8589 )
8690
91+ @mock .patch ("infrahub_sdk.ctl.repository.initialize_client" )
8792 def test_repo_username (self , mock_init_client , mock_client ) -> None :
8893 """Case allow no username to be passed in and set it as None rather than blank string that fails."""
8994 mock_cred = mock .AsyncMock ()
@@ -116,6 +121,7 @@ def test_repo_username(self, mock_init_client, mock_client) -> None:
116121 mock_cred .save .assert_called_with (allow_upsert = True )
117122 mock_client .execute_graphql .assert_called_once ()
118123 mock_client .execute_graphql .assert_called_with (
124+
119125 query = """
120126mutation {
121127 CoreRepositoryCreate(
@@ -145,6 +151,7 @@ def test_repo_username(self, mock_init_client, mock_client) -> None:
145151 tracker = "mutation-repository-create" ,
146152 )
147153
154+ @mock .patch ("infrahub_sdk.ctl.repository.initialize_client" )
148155 def test_repo_readonly_true (self , mock_init_client , mock_client ) -> None :
149156 """Case allow no username to be passed in and set it as None rather than blank string that fails."""
150157 mock_cred = mock .AsyncMock ()
@@ -205,6 +212,7 @@ def test_repo_readonly_true(self, mock_init_client, mock_client) -> None:
205212 tracker = "mutation-repository-create" ,
206213 )
207214
215+ @mock .patch ("infrahub_sdk.ctl.repository.initialize_client" )
208216 def test_repo_description_commit_branch (self , mock_init_client , mock_client ) -> None :
209217 """Case allow no username to be passed in and set it as None rather than blank string that fails."""
210218 mock_cred = mock .AsyncMock ()
@@ -236,6 +244,7 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) ->
236244 mock_client .create .assert_called_with (
237245 name = "Gitlab" ,
238246 kind = "CorePasswordCredential" ,
247+
239248 password = "mySup3rSecureP@ssw0rd" ,
240249 username = "opsmill" ,
241250 )
@@ -271,3 +280,9 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) ->
271280 branch_name = "develop" ,
272281 tracker = "mutation-repository-create" ,
273282 )
283+
284+
285+ def test_repo_list (self , mock_repositories_list ) -> None :
286+ result = runner .invoke (app , ["repository" , "list" ])
287+ assert result .exit_code == 0
288+ assert strip_color (result .stdout ) == read_fixture ("output.txt" , "integration/test_infrahubctl/repository_list" )
0 commit comments