示例#1
0
    def patch(self, run_id):
        """Modifies the value of a field of an existing system run.

        The run_id and import_attempts of an existing system run are
        forbidden to be patched.

        Args:
            run_id: ID of the system run as a string

        Returns:
            The system run with the run_id if successful as a
            datastore Entity object. Otherwise, (error message, error code),
            where the error message is a string and the error code is an int.
        """
        args = SystemRunByID.parser.parse_args()
        if _MODEL.run_id in args or _MODEL.import_attempts in args:
            return validation.get_patch_forbidden_error(
                (_MODEL.run_id, _MODEL.import_attempts))
        valid, err, code = validation.is_system_run_valid(args, run_id=run_id)
        if not valid:
            return err, code

        with self.client.transaction():
            run = self.database.get(run_id)
            if not run:
                return validation.get_not_found_error(_MODEL.run_id, run_id)
            run.update(args)
            return self.database.save(run)
示例#2
0
    def patch(self, attempt_id):
        """Modifies the value of a field of an existing import attempt.

        The attempt_id and run_id of an existing import attempt resource are
        forbidden to be patched.

        Args:
            attempt_id: ID of the import attempt as a string

        Returns:
            The import attempt with the attempt_id if successful as a
            datastore Entity object. Otherwise, (error message, error code),
            where the error message is a string and the error code is an int.
        """
        args = ImportAttempt.parser.parse_args()
        if (_MODEL.attempt_id in args or _MODEL.run_id in args or
                _MODEL.logs in args):
            return validation.get_patch_forbidden_error(
                (_MODEL.attempt_id, _MODEL.run_id, _MODEL.logs))
        valid, err, code = validation.is_import_attempt_valid(
            args, attempt_id=attempt_id)
        if not valid:
            return err, code

        with self.client.transaction():
            import_attempt = self.database.get(attempt_id)
            if not import_attempt:
                return validation.get_not_found_error(_MODEL.attempt_id,
                                                      attempt_id)
            import_attempt.update(args)
            return self.database.save(import_attempt)
示例#3
0
 def test_get_patch_forbidden_error(self):
     """Tests _get_patch_forbidden_error."""
     err, code = validation.get_patch_forbidden_error(('field1', 'field2'))
     self.assertEqual(err, f'It is not allowed to patch field1, field2')
     self.assertEqual(403, code)