0001-add-to_dict-and-export_to_json-to-Workflow-9849.patch
tests/test_workflows.py | ||
---|---|---|
824 | 824 |
assert emails.get('Foobar') |
825 | 825 |
assert set(emails.get('Foobar')['email_rcpt']) == set( |
826 | 826 |
['foo@localhost', 'bar@localhost', 'baz@localhost']) |
827 | ||
828 |
def test_workflow_to_dict(pub): |
|
829 |
workflow = Workflow(name='wf roles') |
|
830 |
st1 = workflow.add_status('Status1', 'st1') |
|
831 |
st2 = workflow.add_status('Status2', 'st2') |
|
832 |
st2.forced_endpoint = True |
|
833 |
workflow.roles['_other'] = 'Other Function' |
|
834 |
root = workflow.to_dict() |
|
835 |
assert set(root.keys()) == set(['statuses', 'name', 'roles']) |
|
836 | ||
837 |
assert root['name'] == 'wf roles' |
|
838 |
assert set(root['statuses'].keys()) == set(['st1', 'st2']) |
|
839 |
assert all(set(status.keys()) == set(['name', 'forced_endpoint']) for status in |
|
840 |
root['statuses'].values()) |
|
841 |
assert root['statuses']['st1']['name'] == 'Status1' |
|
842 |
assert root['statuses']['st1']['forced_endpoint'] is False |
|
843 |
assert root['statuses']['st2']['name'] == 'Status2' |
|
844 |
assert root['statuses']['st2']['forced_endpoint'] is True |
|
845 |
assert json.loads(workflow.export_to_json(indent=4)) == root |
wcs/workflows.py | ||
---|---|---|
672 | 672 |
return workflow |
673 | 673 |
get_default_workflow = classmethod(get_default_workflow) |
674 | 674 | |
675 |
def export_to_json(self, include_id=False, indent=None): |
|
676 |
root = self.to_dict(include_id=include_id) |
|
677 |
return json.dumps(root, indent=indent) |
|
678 | ||
679 |
def to_dict(self, include_id=False): |
|
680 |
charset = get_publisher().site_charset |
|
681 |
root = {} |
|
682 |
root['name'] = unicode(self.name, charset) |
|
683 |
if include_id and self.id: |
|
684 |
root['id'] = str(self.id) |
|
685 |
if self.last_modification_time: |
|
686 |
root['last_modification_time'] = time.strftime('%Y-%m-%dT%H:%M:%S', |
|
687 |
self.last_modification_time) |
|
688 |
roles = root['roles'] = {} |
|
689 |
for role, label in self.roles.iteritems(): |
|
690 |
roles[role] = unicode(label, charset) |
|
691 |
statuses = root['statuses'] = {} |
|
692 |
for status in self.possible_status: |
|
693 |
statuses[status.id] = { |
|
694 |
'name': unicode(status.name, charset), |
|
695 |
'forced_endpoint': status.forced_endpoint, |
|
696 |
} |
|
697 |
return root |
|
698 | ||
675 | 699 | |
676 | 700 |
class XmlSerialisable(object): |
677 | 701 |
node_name = None |
678 |
- |