diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 037f764b2..5e1f13e5b 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -1,3 +1,4 @@ +import base64 import json import datetime import os @@ -3665,6 +3666,8 @@ def test_set_backoffice_field_file(http_requests, two_pubs): assert formdata.data['bo1'].base_filename == 'test.jpeg' assert formdata.data['bo1'].content_type == 'image/jpeg' assert formdata.data['bo1'].get_content() == open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read() + assert formdata.data['bo1'].get_base64_content() == base64.encodestring( + open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg'), 'rb').read()) # same test with PicklableUpload wcs.qommon.form from wcs.qommon.form import PicklableUpload as PicklableUpload2 diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py index 15edd7beb..b0b0d4f10 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -866,6 +866,12 @@ class PicklableUpload(Upload): return open(filename, 'rb').read() return None + def get_base64_content(self): + content = self.get_content() + if content: + return base64.encodestring(content) + return None + class EmailWidget(StringWidget): HTML_TYPE = 'email'