def test_not_exist(self):
        manageactions.report_actions(self.fake_workflows, self.output)

        self.assertFalse(self.output['success'])
        self.assertFalse(self.output['already_reported'])
        self.assertEqual(sorted(self.fake_workflows),
                         sorted(self.output['does_not_exist']))
    def test_everything(self):
        manageactions.report_actions(self.new_workflows + 
                                     self.old_workflows +
                                     self.fake_workflows, self.output)

        self.assertEqual(sorted(self.new_workflows), sorted(self.output['success']))
        self.assertEqual(sorted(self.new_workflows), sorted(self.output['success']))
        self.assertEqual(sorted(self.fake_workflows), sorted(self.output['does_not_exist']))
Example #3
0
    def reportaction(self):
        """
        A POST request to ``https://localhost:8080/reportaction``
        tells the WorkflowWebTools that a set of workflows has been acted on by Unified.
        The body of the POST request must include a JSON with the passphrase
        under ``"key"`` and a list of workflows under ``"workflows"``.

        An example of making this POST request is provided in the file
        ``WorkflowWebTools/test/report_action.py``,
        which relies on ``WorkflowWebTools/test/key.json``.

        :returns: A JSON summarizing results of the request. Keys and values include:

                  - `'valid_key'` - If this is false, the passphrase passed was wrong,
                                    and no action is changed
                  - `'valid_format'` - If false, the input format is unexpected
                  - `'success'` - List of actions that have been marked as acted on
                  - `'already_reported'` - List of workflows that were already removed
                  - `'does_not_exist'` - List of workflows that the database does not know

        :rtype: JSON
        """

        input_json = cherrypy.request.json

        # Is the input good?
        goodkey = (
            input_json['key'] == serverconfig.config_dict()['actions']['key'])
        goodformat = isinstance(input_json['workflows'], list)

        output = {'valid_key': goodkey, 'valid_format': goodformat}

        if goodkey and goodformat:
            # This output is added to by passing reference to manageactions.report_actions
            manageactions.report_actions(input_json['workflows'], output)

        return output