@@ -21,6 +21,17 @@ def remote_generator(names):
2121 return ret_data
2222
2323
24+ def remote_generator_url (remotes ):
25+ """Generates objects to be used with git.Repo.remotes call"""
26+ ret_data = []
27+ for name , url in remotes .items ():
28+ obj = type ('' , (), {})()
29+ obj .name = name
30+ obj .url = url
31+ ret_data .append (obj )
32+ return ret_data
33+
34+
2435def test_get_remotes_returns_list (mock_repo ):
2536 """
2637 GIVEN GitRepo is initialized with a path and repo
@@ -36,6 +47,21 @@ def test_get_remotes_returns_list(mock_repo):
3647 assert expected == git_util .remote .names ()
3748
3849
50+ def test_get_remotes_returns_dict (mock_repo ):
51+ """
52+ GIVEN GitRepo is initialized with a path and repo
53+ WHEN remote.names_url_dict is called
54+ THEN a dict of remote names with its url is returned
55+ """
56+ expected = {'a' : 1 , 'b' : 2 , 'c' : 3 }
57+ attrs = {'remotes' : remote_generator_url (expected )}
58+ mock_repo .configure_mock (** attrs )
59+
60+ git_util = GitRepo ('./' , mock_repo )
61+
62+ assert expected == git_util .remote .names_url_dict ()
63+
64+
3965def test_add_remote_adds (mock_repo ):
4066 """
4167 GIVEN GitRepo initialized with a path and repo
@@ -89,6 +115,47 @@ def test_add_remote_update_fails(mock_repo):
89115 delete_mock .assert_called_once_with (remote_mock )
90116
91117
118+ def test_remove_remote_removes (mock_repo ):
119+ """
120+ GIVEN GitRepo initialized with a path and repo
121+ WHEN remote.add is called with a name and url
122+ THEN a TRUE status is returned
123+ WITH update called
124+ """
125+ git_util = GitRepo ('./' , mock_repo )
126+
127+ assert git_util .remote .remove ('origin' ) is True
128+
129+
130+ def test_remove_remote_remote_fails (mock_repo ):
131+ """
132+ GIVEN GitRepo initialized with a path and repo
133+ WHEN remote.add is called with a name and url
134+ AND the remote create fails with an exception
135+ THEN a False status is returned
136+ """
137+ mock_repo .remote .side_effect = ValueError
138+
139+ repo = GitRepo (repo = mock_repo )
140+ with pytest .raises (exceptions .ReferenceNotFoundException ):
141+ repo .remote .remove ("doesntExist" )
142+
143+ mock_repo .remote .assert_called_with ("doesntExist" )
144+
145+
146+ def test_remove_remote_remove_fails (mock_repo ):
147+ """
148+ GIVEN GitRepo initialized with a path and repo
149+ WHEN remote.add is called with a name and url
150+ AND the remote create fails with an exception
151+ THEN a False status is returned
152+ """
153+ mock_repo .delete_remote .side_effect = git .CommandError ('remove' )
154+ git_util = GitRepo ('./' , mock_repo )
155+
156+ assert git_util .remote .remove ('rdo' ) is False
157+
158+
92159def test_fetch (mock_repo ):
93160 """
94161 GIVEN GitRepo is initialized with a path and repo
0 commit comments