environment: allow templated sites variable values (#74500)
gitea-wip/hobo/pipeline/pr-main This commit looks good
Details
gitea-wip/hobo/pipeline/pr-main This commit looks good
Details
This commit is contained in:
parent
fe64b31ba2
commit
3e6d5eaaf5
|
@ -73,8 +73,12 @@ class Variable(models.Model):
|
|||
return self.name
|
||||
|
||||
def _parse_value_as_json(self):
|
||||
if self.value and (
|
||||
self.value[0] in '{[' or self.value in ('true', 'false', 'null') or FLOAT_RE.match(self.value)
|
||||
if (
|
||||
self.value
|
||||
and not self.value.startswith(('{{', '{%'))
|
||||
and (
|
||||
self.value[0] in '{[' or self.value in ('true', 'false', 'null') or FLOAT_RE.match(self.value)
|
||||
)
|
||||
):
|
||||
try:
|
||||
return json.loads(self.value)
|
||||
|
|
|
@ -236,6 +236,26 @@ def test_new_variable_view(app, admin_user):
|
|||
assert Variable.objects.all()[0].value == 'foofoo'
|
||||
|
||||
|
||||
def test_new_variable_templated_value(app, admin_user):
|
||||
app = login(app)
|
||||
response = app.get('/sites/new-variable')
|
||||
response.form['name'] = 'foo'
|
||||
response.form['label'] = 'bar'
|
||||
response.form['value'] = '{{ foobar }}'
|
||||
response = response.form.submit()
|
||||
assert response.location == '/sites/variables'
|
||||
assert Variable.objects.all()[0].name == 'foo'
|
||||
assert Variable.objects.all()[0].label == 'bar'
|
||||
assert Variable.objects.all()[0].value == '{{ foobar }}'
|
||||
response = app.get('/sites/new-variable')
|
||||
response.form['name'] = 'foo'
|
||||
response.form['label'] = 'bar'
|
||||
response.form['value'] = '{% firstof foofoo "Plop" %}'
|
||||
response = response.form.submit()
|
||||
assert response.location == '/sites/variables'
|
||||
assert Variable.objects.all()[0].value == '{% firstof foofoo "Plop" %}'
|
||||
|
||||
|
||||
def test_new_variable_service_view(app, admin_user):
|
||||
app = login(app)
|
||||
Combo.objects.create(
|
||||
|
|
Loading…
Reference in New Issue