Skip to content

Commit 4c108c3

Browse files
committed
fix(controller): allow unicode in config:set and app logging
1 parent 362c6ff commit 4c108c3

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

api/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ def log(self, message):
172172
existing logging configurations.
173173
"""
174174
with open(os.path.join(settings.DEIS_LOG_DIR, self.id + '.log'), 'a') as f:
175-
f.write('{} deis[api]: {}\n'.format(
176-
time.strftime('%Y-%m-%d %H:%M:%S'),
177-
message))
175+
msg = "{} deis[api]: {}\n".format(time.strftime('%Y-%m-%d %H:%M:%S'), message)
176+
f.write(msg.encode('utf-8'))
178177

179178
def create(self, *args, **kwargs):
180179
config = Config.objects.create(owner=self.owner, app=self)

api/tests/test_config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
Unit tests for the Deis api app.
34
@@ -127,6 +128,29 @@ def test_config_set_same_key(self):
127128
self.assertIn('PORT', json.loads(response.data['values']))
128129
self.assertEqual(json.loads(response.data['values'])['PORT'], '5001')
129130

131+
@mock.patch('requests.post', mock_import_repository_task)
132+
def test_config_set_unicode(self):
133+
"""
134+
Test that config sets with unicode values are accepted.
135+
"""
136+
url = '/api/apps'
137+
body = {'cluster': 'autotest'}
138+
response = self.client.post(url, json.dumps(body), content_type='application/json')
139+
self.assertEqual(response.status_code, 201)
140+
app_id = response.data['id']
141+
url = "/api/apps/{app_id}/config".format(**locals())
142+
# set an initial config value
143+
body = {'values': json.dumps({'POWERED_BY': 'Деис'})}
144+
response = self.client.post(url, json.dumps(body), content_type='application/json')
145+
self.assertEqual(response.status_code, 201)
146+
self.assertIn('POWERED_BY', json.loads(response.data['values']))
147+
# reset same config value
148+
body = {'values': json.dumps({'POWERED_BY': 'Кроликов'})}
149+
response = self.client.post(url, json.dumps(body), content_type='application/json')
150+
self.assertEqual(response.status_code, 201)
151+
self.assertIn('POWERED_BY', json.loads(response.data['values']))
152+
self.assertEqual(json.loads(response.data['values'])['POWERED_BY'], 'Кроликов')
153+
130154
@mock.patch('requests.post', mock_import_repository_task)
131155
def test_config_str(self):
132156
"""Test the text representation of a node."""

registry/private.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ def _construct_env(env, config):
166166
if k in config:
167167
# update values defined by config
168168
v = config.pop(k)
169-
new_env.append("{}={}".format(k, v))
169+
new_env.append("{}={}".format(k.encode('utf-8'), v.encode('utf-8')))
170170
# add other config ENV items
171171
for k, v in config.items():
172-
new_env.append("{}={}".format(k, v))
172+
new_env.append("{}={}".format(k.encode('utf-8'), v.encode('utf-8')))
173173
return new_env
174174

175175

0 commit comments

Comments
 (0)