0001-evalutils-add-attachment-content-filename-content_ty.patch
tests/test_workflows.py | ||
---|---|---|
1 |
import json |
|
1 | 2 |
import datetime |
2 | 3 |
import os |
3 | 4 |
import pytest |
... | ... | |
1211 | 1212 |
assert emails.emails['foobar']['msg'].get_payload()[2].get_payload() == 'blah' |
1212 | 1213 |
assert len(emails.emails['foobar']['msg'].get_payload()) == 3 |
1213 | 1214 | |
1215 |
emails.empty() |
|
1216 |
sendmail.attachments = [ |
|
1217 |
'utils.attachment(form.formdata.export_to_json(include_files=False))', |
|
1218 |
'utils.attachment(form.formdata.export_to_json(), content_type=\'application/json\')', |
|
1219 |
] |
|
1220 |
sendmail.perform(formdata) |
|
1221 |
get_response().process_after_jobs() |
|
1222 |
assert emails.count() == 1 |
|
1223 |
assert emails.emails['foobar']['msg'].is_multipart() |
|
1224 |
assert emails.emails['foobar']['msg'].get_content_subtype() == 'mixed' |
|
1225 |
assert emails.emails['foobar']['msg'].get_payload(0).get_content_type() == 'text/html' |
|
1226 |
assert emails.emails['foobar']['msg'].get_payload(1).get_content_type() == 'application/octet-stream' |
|
1227 |
assert emails.emails['foobar']['msg'].get_payload(2).get_content_type() == 'application/json' |
|
1228 |
payload1 = emails.emails['foobar']['msg'].get_payload(1) |
|
1229 |
payload2 = emails.emails['foobar']['msg'].get_payload(2) |
|
1230 |
assert json.loads(formdata.export_to_json(include_files=False)) == json.loads(payload1.get_payload(decode=True)) |
|
1231 |
assert json.loads(formdata.export_to_json()) == json.loads(payload2.get_payload(decode=True)) |
|
1214 | 1232 | |
1215 | 1233 | |
1216 | 1234 |
def test_webservice_call(http_requests, pub): |
wcs/qommon/evalutils.py | ||
---|---|---|
118 | 118 |
today = make_datetime(today) |
119 | 119 |
return datetime_delta(today, born).total_seconds() |
120 | 120 | |
121 | ||
121 | 122 |
def add_days(date, count): |
122 | 123 |
'''Add the given number of days to date''' |
123 | 124 |
return make_date(date) + datetime.timedelta(days=count) |
125 | ||
126 | ||
127 |
def attachment(content, filename='', content_type='application/octet-stream'): |
|
128 |
'''Serialize content as an attachment''' |
|
129 |
import base64 |
|
130 | ||
131 |
return { |
|
132 |
'filename': filename, |
|
133 |
'content_type': content_type, |
|
134 |
'b64_content': base64.b64encode(content), |
|
135 |
} |
|
124 |
- |