@@ -50,6 +50,93 @@ def test_git_get_config_success(self, popen):
5050 },
5151 }
5252
53+ @patch ("subprocess.Popen" )
54+ def test_git_get_config_multiline (self , popen ):
55+ # Given
56+ process_mock = Mock ()
57+ attrs = {
58+ "communicate" : Mock (
59+ return_value = (
60+ b"user.name=John Snow\n "
61+ b"user.email=john.snow@iscoming.com\n "
62+ b'alias.topic-base-branch-name=!f(){ printf "master\n '
63+ b'"; };f\n '
64+ b'alias.topic-start=!f(){ topic_branch="$1"; git topic-create "$topic_branch"; git topic-push; };f' ,
65+ b"" ,
66+ )
67+ ),
68+ "returncode" : 0 ,
69+ }
70+ process_mock .configure_mock (** attrs )
71+ popen .return_value = process_mock
72+
73+ # When
74+ body = {"path" : "test_path" }
75+ response = self .tester .post (["config" ], body = body )
76+
77+ # Then
78+ popen .assert_called_once_with (
79+ ["git" , "config" , "--list" ],
80+ stdout = subprocess .PIPE ,
81+ stderr = subprocess .PIPE ,
82+ cwd = "test_path" ,
83+ )
84+ process_mock .communicate .assert_called_once_with ()
85+
86+ assert response .status_code == 201
87+ payload = response .json ()
88+ assert payload == {
89+ "code" : 0 ,
90+ "options" : {
91+ "user.name" : "John Snow" ,
92+ "user.email" : "john.snow@iscoming.com" ,
93+ },
94+ }
95+
96+ @patch ("subprocess.Popen" )
97+ @patch ("jupyterlab_git.git.ALLOWED_OPTIONS" , ["user.name" , "alias.topic-base-branch-name" ])
98+ def test_git_get_config_accepted_multiline (self , popen ):
99+ # Given
100+ process_mock = Mock ()
101+ attrs = {
102+ "communicate" : Mock (
103+ return_value = (
104+ b"user.name=John Snow\n "
105+ b"user.email=john.snow@iscoming.com\n "
106+ b'alias.topic-base-branch-name=!f(){ printf "master\n '
107+ b'"; };f\n '
108+ b'alias.topic-start=!f(){ topic_branch="$1"; git topic-create "$topic_branch"; git topic-push; };f' ,
109+ b"" ,
110+ )
111+ ),
112+ "returncode" : 0 ,
113+ }
114+ process_mock .configure_mock (** attrs )
115+ popen .return_value = process_mock
116+
117+ # When
118+ body = {"path" : "test_path" }
119+ response = self .tester .post (["config" ], body = body )
120+
121+ # Then
122+ popen .assert_called_once_with (
123+ ["git" , "config" , "--list" ],
124+ stdout = subprocess .PIPE ,
125+ stderr = subprocess .PIPE ,
126+ cwd = "test_path" ,
127+ )
128+ process_mock .communicate .assert_called_once_with ()
129+
130+ assert response .status_code == 201
131+ payload = response .json ()
132+ assert payload == {
133+ "code" : 0 ,
134+ "options" : {
135+ "user.name" : "John Snow" ,
136+ "alias.topic-base-branch-name" : '!f(){ printf "master"; };f' ,
137+ },
138+ }
139+
53140 @patch ("subprocess.Popen" )
54141 def test_git_set_config_success (self , popen ):
55142 # Given
0 commit comments