0001-add-to_dict-method-to-Workflow-9849.patch
tests/test_workflows.py | ||
---|---|---|
943 | 943 |
assert emails.get('Foobar') |
944 | 944 |
assert set(emails.get('Foobar')['email_rcpt']) == set( |
945 | 945 |
['foo@localhost', 'bar@localhost', 'baz@localhost']) |
946 | ||
947 |
def test_workflow_to_dict(pub): |
|
948 |
workflow = Workflow(name='wf roles') |
|
949 |
st1 = workflow.add_status('Status1', 'st1') |
|
950 |
st2 = workflow.add_status('Status2', 'st2') |
|
951 |
st2.forced_endpoint = True |
|
952 |
workflow.roles['_other'] = 'Other Function' |
|
953 |
root = workflow.to_dict() |
|
954 |
assert set(root.keys()) >= set(['statuses', 'name', 'functions']) |
|
955 | ||
956 |
assert root['name'] == 'wf roles' |
|
957 |
assert set(root['statuses'].keys()) == set(['st1', 'st2']) |
|
958 |
assert all(set(status.keys()) >= set(['name', 'forced_endpoint']) for status in |
|
959 |
root['statuses'].values()) |
|
960 |
assert root['statuses']['st1']['name'] == 'Status1' |
|
961 |
assert root['statuses']['st1']['forced_endpoint'] is False |
|
962 |
assert root['statuses']['st2']['name'] == 'Status2' |
|
963 |
assert root['statuses']['st2']['forced_endpoint'] is True |
wcs/workflows.py | ||
---|---|---|
672 | 672 |
return workflow |
673 | 673 |
get_default_workflow = classmethod(get_default_workflow) |
674 | 674 | |
675 |
def to_dict(self, include_id=False): |
|
676 |
charset = get_publisher().site_charset |
|
677 |
root = {} |
|
678 |
root['name'] = unicode(self.name, charset) |
|
679 |
if include_id and self.id: |
|
680 |
root['id'] = str(self.id) |
|
681 |
if self.last_modification_time: |
|
682 |
root['last_modification_time'] = time.strftime('%Y-%m-%dT%H:%M:%S', |
|
683 |
self.last_modification_time) |
|
684 |
roles = root['functions'] = {} |
|
685 |
for role, label in self.roles.iteritems(): |
|
686 |
roles[role] = unicode(label, charset) |
|
687 |
statuses = root['statuses'] = {} |
|
688 |
for status in self.possible_status: |
|
689 |
statuses[status.id] = { |
|
690 |
'name': unicode(status.name, charset), |
|
691 |
'forced_endpoint': status.forced_endpoint, |
|
692 |
} |
|
693 |
return root |
|
694 | ||
675 | 695 | |
676 | 696 |
class XmlSerialisable(object): |
677 | 697 |
node_name = None |
678 |
- |