We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 6243d91 + 0920b9e commit 0cfa320Copy full SHA for 0cfa320
5 files changed
client/deis.py
@@ -303,6 +303,14 @@ def dictify(args):
303
return data
304
305
306
+def encode(obj):
307
+ """Return UTF-8 encoding for string objects."""
308
+ if isinstance(obj, basestring):
309
+ return obj.encode('utf-8')
310
+ else:
311
+ return obj
312
+
313
314
def readable_datetime(datetime_str):
315
"""
316
Return a human-readable datetime string from an ECMA-262 (JavaScript)
@@ -1122,14 +1130,12 @@ def config_list(self, args):
1122
1130
if not oneline:
1123
1131
width = max(map(len, keys)) + 5
1124
1132
for k in keys:
1125
- v = values[k]
1126
- k, v = k.encode('utf-8'), v.encode('utf-8')
1133
+ k, v = encode(k), encode(values[k])
1127
1134
self._logger.info(("{k:<" + str(width) + "} {v}").format(**locals()))
1128
1135
else:
1129
1136
output = []
1137
1138
1139
output.append("{k}={v}".format(**locals()))
1140
self._logger.info(' '.join(output))
1141
@@ -1175,8 +1181,7 @@ def config_set(self, args):
1175
1181
self._logger.info('No configuration')
1176
1182
return
1177
1183
for k, v in values.items():
1178
1179
- self._logger.info("{k}: {v}".format(**locals()))
1184
+ self._logger.info("{}: {}".format(encode(k), encode(v)))
1180
1185
1186
raise ResponseError(response)
1187
controller/api/tests/test_config.py
@@ -148,6 +148,12 @@ def test_config_set_unicode(self):
148
self.assertEqual(response.status_code, 201)
149
self.assertIn('POWERED_BY', json.loads(response.data['values']))
150
self.assertEqual(json.loads(response.data['values'])['POWERED_BY'], 'Кроликов')
151
+ # set an integer to test unicode regression
152
+ body = {'values': json.dumps({'INTEGER': 1})}
153
+ response = self.client.post(url, json.dumps(body), content_type='application/json')
154
+ self.assertEqual(response.status_code, 201)
155
+ self.assertIn('INTEGER', json.loads(response.data['values']))
156
+ self.assertEqual(json.loads(response.data['values'])['INTEGER'], 1)
157
158
@mock.patch('requests.post', mock_import_repository_task)
159
def test_config_str(self):
controller/api/utils.py
@@ -108,6 +108,14 @@ def fingerprint(key):
108
return ':'.join(a + b for a, b in zip(fp_plain[::2], fp_plain[1::2]))
109
110
111
112
113
114
115
116
117
118
119
if __name__ == "__main__":
120
import doctest
121
doctest.testmod()
controller/registry/private.py
@@ -6,9 +6,10 @@
6
import urlparse
7
import uuid
8
9
+from django.conf import settings
10
from docker.utils import utils
11
-from django.conf import settings
12
+from api.utils import encode
13
14
15
def publish_release(source, config, target):
@@ -158,7 +159,6 @@ def _put_tag(image_id, repository_path, tag):
160
# utility functions
161
-
162
def _construct_env(env, config):
163
"Update current environment with latest config"
164
new_env = []
@@ -168,10 +168,10 @@ def _construct_env(env, config):
168
if k in config:
169
# update values defined by config
170
v = config.pop(k)
171
- new_env.append("{}={}".format(k.encode('utf-8'), v.encode('utf-8')))
+ new_env.append("{}={}".format(encode(k), encode(v)))
172
# add other config ENV items
173
for k, v in config.items():
174
175
return new_env
176
177
tests/config_test.go
@@ -11,6 +11,7 @@ import (
var (
configListCmd = "config:list --app={{.AppName}}"
configSetCmd = "config:set FOO=讲台 --app={{.AppName}}"
+ configSet2Cmd = "config:set FOO=10 --app={{.AppName}}"
configUnsetCmd = "config:unset FOO --app={{.AppName}}"
16
)
17
@@ -52,11 +53,13 @@ func configListTest(
52
53
}
54
55
func configSetTest(t *testing.T, params *utils.DeisTestConfig) {
- utils.Execute(t, configSetCmd, params, false, "")
56
+ utils.Execute(t, configSetCmd, params, false, "讲台")
57
utils.CheckList(t, appsInfoCmd, params, "(v3)", false)
58
+ utils.Execute(t, configSet2Cmd, params, false, "10")
59
+ utils.CheckList(t, appsInfoCmd, params, "(v4)", false)
60
61
62
func configUnsetTest(t *testing.T, params *utils.DeisTestConfig) {
63
utils.Execute(t, configUnsetCmd, params, false, "")
- utils.CheckList(t, appsInfoCmd, params, "(v4)", false)
64
+ utils.CheckList(t, appsInfoCmd, params, "(v5)", false)
65
0 commit comments