0001-workflows-make-sure-attachments-are-saved-only-once-.patch
tests/test_workflows.py | ||
---|---|---|
1 | 1 |
import datetime |
2 | 2 |
import pytest |
3 | 3 |
import shutil |
4 |
import StringIO |
|
4 | 5 |
import time |
5 | 6 |
import urllib2 |
6 | 7 |
import urlparse |
... | ... | |
518 | 519 |
item.perform(formdata) |
519 | 520 |
assert formdata.evolution[-1].display_parts()[-1] == '<div>1 < 3</div>' |
520 | 521 | |
522 |
def test_register_comment_attachment(pub): |
|
523 |
pub.substitutions.feed(MockSubstitutionVariables()) |
|
524 | ||
525 |
formdef = FormDef() |
|
526 |
formdef.name = 'baz' |
|
527 |
formdef.fields = [] |
|
528 |
formdef.store() |
|
529 | ||
530 |
formdata = formdef.data_class()() |
|
531 |
formdata.just_created() |
|
532 |
formdata.store() |
|
533 | ||
534 |
item = RegisterCommenterWorkflowStatusItem() |
|
535 |
item.perform(formdata) |
|
536 |
assert formdata.evolution[-1].display_parts()[-1] == '' |
|
537 | ||
538 |
if os.path.exists(os.path.join(get_publisher().app_dir, 'attachments')): |
|
539 |
shutil.rmtree(os.path.join(get_publisher().app_dir, 'attachments')) |
|
540 | ||
541 |
formdata.evolution[-1].parts = [AttachmentEvolutionPart('hello.txt', |
|
542 |
fp=StringIO.StringIO('hello world'), varname='testfile')] |
|
543 |
formdata.store() |
|
544 |
assert len(os.listdir(os.path.join(get_publisher().app_dir, 'attachments'))) == 1 |
|
545 | ||
546 |
item.comment = '[attachments.testfile.url]' |
|
547 | ||
548 |
pub.substitutions.feed(formdata) |
|
549 |
item.perform(formdata) |
|
550 |
url1 = formdata.evolution[-1].parts[-1].content |
|
551 | ||
552 |
pub.substitutions.feed(formdata) |
|
553 |
item.perform(formdata) |
|
554 |
url2 = formdata.evolution[-1].parts[-1].content |
|
555 | ||
556 |
assert len(os.listdir(os.path.join(get_publisher().app_dir, 'attachments'))) == 1 |
|
557 |
assert url1 == url2 |
|
558 | ||
521 | 559 |
def test_email(pub): |
522 | 560 |
pub.substitutions.feed(MockSubstitutionVariables()) |
523 | 561 |
wcs/workflows.py | ||
---|---|---|
199 | 199 |
if not os.path.exists(filename): |
200 | 200 |
return filename |
201 | 201 | |
202 |
odict['filename'] = get_new_filename() |
|
203 |
self.fp.seek(0) |
|
204 |
fd = file(odict['filename'], 'w') |
|
205 |
fd.write(self.fp.read()) |
|
206 |
fd.close() |
|
202 |
if not 'filename' in odict: |
|
203 |
odict['filename'] = get_new_filename() |
|
204 |
self.filename = odict['filename'] |
|
205 |
self.fp.seek(0) |
|
206 |
fd = file(odict['filename'], 'w') |
|
207 |
fd.write(self.fp.read()) |
|
208 |
fd.close() |
|
209 | ||
207 | 210 |
return odict |
208 | 211 | |
209 | 212 |
def view(self): |
210 |
- |