Skip to content

Commit

Permalink
fix attachment_url for repeats
Browse files Browse the repository at this point in the history
  • Loading branch information
snopoke committed Aug 2, 2017
1 parent cd27e63 commit fc9413d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commcare_export/env.py
Expand Up @@ -338,7 +338,7 @@ def attachment_url(val):
Reference('template'),
Literal('{}/a/{}/api/form/attachment/{}/{}'),
Reference('commcarehq_base_url'),
Reference('domain'),
Reference('$.domain'),
Reference('$.id'),
Literal(val)
)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_minilinq.py
Expand Up @@ -89,6 +89,22 @@ def test_attachment_url(self):
expected = 'https://www.commcarehq.org/a/d1/api/form/attachment/123/a.jpg'
assert Apply(Reference('attachment_url'), Reference('photo')).eval(env) == expected

def test_attachment_url_repeat(self):
env = BuiltInEnv({'commcarehq_base_url': 'https://www.commcarehq.org'}) | JsonPathEnv({
'id': '123', 'domain': 'd1', 'repeat': [
{'photo': 'a.jpg'}, {'photo': 'b.jpg'}
]
})
expected = [
'https://www.commcarehq.org/a/d1/api/form/attachment/123/a.jpg',
'https://www.commcarehq.org/a/d1/api/form/attachment/123/b.jpg',
]
result = unwrap_val(Map(
source=Reference('repeat.[*]'),
body=Apply(Reference('attachment_url'), Reference('photo'))
).eval(env))
assert result == expected

def test_template(self):
env = BuiltInEnv() | JsonPathEnv({'a': '1', 'b': '2'})
assert Apply(Reference('template'), Literal('{}.{}'), Reference('a'), Reference('b')).eval(env) == '1.2'
Expand Down

0 comments on commit fc9413d

Please sign in to comment.