@@ -50,6 +50,110 @@ def test_git_get_config_success(self, popen):
50
50
},
51
51
}
52
52
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
+
62
+ b'alias.summary=!f() { printf "Summary of this branch...\n '
63
+ b'"; printf "%s\n '
64
+ b'" $(git rev-parse --abbrev-ref HEAD); printf "\n '
65
+ b"Most-active files, with churn count\n "
66
+ b'"; git churn | head -7; }; f\n '
67
+ b'alias.topic-base-branch-name=!f(){ printf "master\n '
68
+ b'"; };f\n '
69
+ b'alias.topic-start=!f(){ topic_branch="$1"; git topic-create "$topic_branch"; git topic-push; };f' ,
70
+ b"" ,
71
+ )
72
+ ),
73
+ "returncode" : 0 ,
74
+ }
75
+ process_mock .configure_mock (** attrs )
76
+ popen .return_value = process_mock
77
+
78
+ # When
79
+ body = {"path" : "test_path" }
80
+ response = self .tester .post (["config" ], body = body )
81
+
82
+ # Then
83
+ popen .assert_called_once_with (
84
+ ["git" , "config" , "--list" ],
85
+ stdout = subprocess .PIPE ,
86
+ stderr = subprocess .PIPE ,
87
+ cwd = "test_path" ,
88
+ )
89
+ process_mock .communicate .assert_called_once_with ()
90
+
91
+ assert response .status_code == 201
92
+ payload = response .json ()
93
+ assert payload == {
94
+ "code" : 0 ,
95
+ "options" : {
96
+ "user.name" : "John Snow" ,
97
+ "user.email" :
"[email protected] " ,
98
+ },
99
+ }
100
+
101
+ @patch ("subprocess.Popen" )
102
+ @patch (
103
+ "jupyterlab_git.git.ALLOWED_OPTIONS" ,
104
+ ["alias.summary" , "alias.topic-base-branch-name" ],
105
+ )
106
+ def test_git_get_config_accepted_multiline (self , popen ):
107
+ # Given
108
+ process_mock = Mock ()
109
+ attrs = {
110
+ "communicate" : Mock (
111
+ return_value = (
112
+ b"user.name=John Snow\n "
113
+
114
+ b'alias.summary=!f() { printf "Summary of this branch...\n '
115
+ b'"; printf "%s\n '
116
+ b'" $(git rev-parse --abbrev-ref HEAD); printf "\n '
117
+ b"Most-active files, with churn count\n "
118
+ b'"; git churn | head -7; }; f\n '
119
+ b'alias.topic-base-branch-name=!f(){ printf "master\n '
120
+ b'"; };f\n '
121
+ b'alias.topic-start=!f(){ topic_branch="$1"; git topic-create "$topic_branch"; git topic-push; };f' ,
122
+ b"" ,
123
+ )
124
+ ),
125
+ "returncode" : 0 ,
126
+ }
127
+ process_mock .configure_mock (** attrs )
128
+ popen .return_value = process_mock
129
+
130
+ # When
131
+ body = {"path" : "test_path" }
132
+ response = self .tester .post (["config" ], body = body )
133
+
134
+ # Then
135
+ popen .assert_called_once_with (
136
+ ["git" , "config" , "--list" ],
137
+ stdout = subprocess .PIPE ,
138
+ stderr = subprocess .PIPE ,
139
+ cwd = "test_path" ,
140
+ )
141
+ process_mock .communicate .assert_called_once_with ()
142
+
143
+ assert response .status_code == 201
144
+ payload = response .json ()
145
+ assert payload == {
146
+ "code" : 0 ,
147
+ "options" : {
148
+ "alias.summary" : '!f() { printf "Summary of this branch...\n '
149
+ '"; printf "%s\n '
150
+ '" $(git rev-parse --abbrev-ref HEAD); printf "\n '
151
+ "Most-active files, with churn count\n "
152
+ '"; git churn | head -7; }; f' ,
153
+ "alias.topic-base-branch-name" : '!f(){ printf "master\n "; };f' ,
154
+ },
155
+ }
156
+
53
157
@patch ("subprocess.Popen" )
54
158
def test_git_set_config_success (self , popen ):
55
159
# Given
0 commit comments