コード例 #1
0
    def do_patch(self, payload):
        payload_shifted = create_data(self.property_full_path, payload)
        status, status_code, response_body, headers = self._api_caller.patch_resource(
            self.api_resource.url,
            self.discovery_container,
            payload=payload_shifted,
            acceptable_return_codes=self.patching_strategy.
            allowable_return_codes)

        patch_applied = self.patching_strategy.was_patch_applied(status_code)

        if status != RequestStatus.SUCCESS:
            cts_error(
                "{odata_id:id} Patching {property} failed (unexpected status code: {code})",
                odata_id=self.api_resource.odata_id,
                property=self.property_description.name,
                code=status_code)
            validation_status = ValidationStatus.FAILED
        elif not patch_applied:
            cts_error(
                "{odata_id:id} Patching {property} failed (patch not applied); status code: {code}",
                odata_id=self.api_resource.odata_id,
                property=self.property_description.name,
                code=status_code)
            validation_status = ValidationStatus.FAILED
        else:
            validation_status = ValidationStatus.PASSED

        return validation_status
コード例 #2
0
    def do_patch(self, payload):
        payload_shifted = create_data(self.property_full_path, payload)
        status, status_code, response_body, headers = self._api_caller.patch_resource(
            self.api_resource.url,
            self.discovery_container,
            payload=payload_shifted,
            acceptable_return_codes=self.patching_strategy.allowable_return_codes)

        patch_applied = self.patching_strategy.was_patch_applied(status_code)

        if status != RequestStatus.SUCCESS:
            cts_error("{odata_id:id} Patching {property} failed (unexpected status code: {code})",
                      odata_id=self.api_resource.odata_id,
                      property=self.property_description.name,
                      code=status_code)
            validation_status = ValidationStatus.FAILED
        elif not patch_applied:
            cts_error("{odata_id:id} Patching {property} failed (patch not applied); status code: {code}",
                      odata_id=self.api_resource.odata_id,
                      property=self.property_description.name,
                      code=status_code)
            validation_status = ValidationStatus.FAILED
        else:
            validation_status = ValidationStatus.PASSED

        return validation_status
コード例 #3
0
    def _restore_property(self, context, value_pre, variable_path, collection=None):
        """
        Final patching that restores original value of the property.

        :type context: Context
        :type value_pre: *
        :type variable_path: list [int or str]
        :return: str
        """
        api_resource = context.api_resource

        validation_status = ValidationStatus.PASSED

        property = "%s" % ("->".join([str(path) for path in variable_path]))
        print "TEST_CASE::Restore %s := %s" % (property, dumps(value_pre))

        data = create_data(variable_path, value_pre, collection)
        status, status_code, response_body, headers = self._api_caller.patch_resource(
            api_resource.url,
            self.discovery_container,
            payload=data,
            acceptable_return_codes=self._strategy.allowable_return_codes)
        if status != RequestStatus.SUCCESS:
            cts_error("{odata_id:id} Restoring {property} failed. status code {code}",
                      odata_id=api_resource.odata_id,
                      property=property,
                      code=status_code)
            validation_status = ValidationStatus.FAILED
        print "STATUS::%s" % validation_status
        return validation_status
コード例 #4
0
    def _patch_property(self, context, property_name, value_pre, value_requested, variable_path, collection=None):
        """
        Issues Patch request to update property to new requested value. Tries to determine
        if patch has been applied and sets validation status accordingly.

        :type context: Context
        :type property_name: str
        :type value_pre: *
        :type value_requested: *
        :type variable_path: list [str or int]
        :rtype: (bool, bool, str)
        """

        api_resource = context.api_resource

        print "TEST_CASE:: Patch %s := %s" % (property_name, str(value_requested))
        context.register_patch_attempt(property_name, str(value_requested))

        data = create_data(variable_path, value_requested, collection)

        status, status_code, response_body, headers = self._api_caller.patch_resource(
            api_resource.url,
            self.discovery_container,
            payload=data,
            acceptable_return_codes=self._strategy.allowable_return_codes)

        patch_applied = self._strategy.was_patch_applied(status_code)

        if status != RequestStatus.SUCCESS or not patch_applied:
            validation_status = ValidationStatus.FAILED
        else:
            validation_status = ValidationStatus.PASSED
        print "STATUS::%s" % validation_status

        return patch_applied, status, validation_status
コード例 #5
0
 def build_payload_for_restore(self, value):
     payload = self.payload().next()
     value = create_data(self.property_full_path, value)
     update_existing_keys(payload, value)
     return payload
コード例 #6
0
 def build_payload_for_restore(self, value):
     payload = self.payload().next()
     value = create_data(self.property_full_path, value)
     update_existing_keys(payload, value)
     return payload