Example #1
0
    def refresh(self, api_test_case, last_exchange: HttpExchange):
        self.parent_view.tbl_assertions.clear()
        formatted_response_code = response_code_formatter(
            last_exchange.response.http_status_code)
        self.parent_view.btn_response_code_assertion.setText(
            f"HTTP {formatted_response_code}")
        elapsed_time = elapsed_time_formatter(
            last_exchange.response.elapsed_time)
        self.parent_view.btn_response_time_assertion.setText(elapsed_time)

        for assertion in api_test_case.assertions:
            item = QTreeWidgetItem()

            current_value_from_exchange = "Unable to retrieve value"

            try:
                current_value_from_exchange = app_settings.app_data_cache.get_latest_assertion_value_from_exchange(
                    assertion, last_exchange)
            except Exception as e:
                logging.error("Unable to retrieve value")
                logging.error(assertion)
                logging.error(last_exchange)

            # @todo: Create a function to convert row in assertions table <-> Assertion object
            item.setData(0, Qt.DisplayRole, assertion.data_from)
            item.setData(1, Qt.DisplayRole, assertion.var_name)
            item.setData(2, Qt.DisplayRole, assertion.selector)
            item.setData(3, Qt.DisplayRole, current_value_from_exchange)
            item.setData(3, ASSERTION_TYPE_ROLE, assertion.var_type)
            item.setData(5, Qt.DisplayRole, assertion.expected_value)
            self.add_item(
                item,
                selected_matcher=assertion.matcher,
                current_data=current_value_from_exchange,
            )
Example #2
0
def markdown_response(exchange: HttpExchange):
    elapsed_time = elapsed_time_formatter(exchange.response.elapsed_time)
    if exchange.response.is_mocked:
        elapsed_time = "Mocked Response"

    response_headers = dict_formatter(exchange.response.headers.items(),
                                      "{k}: {v}",
                                      splitter="\n")

    formatted_response_body = highlight_format_json(
        exchange.response.response_body, formatter=NullFormatter())
    return f"""
Example #3
0
 def add_response_time_assertion(self):
     api_call = self.parent_presenter.current
     last_exchange: HttpExchange = app_settings.app_data_cache.get_last_exchange(
         api_call.id)
     current_elapsed_time = elapsed_time_formatter(
         last_exchange.response.elapsed_time)
     item = QTreeWidgetItem([
         AssertionDataSource.RESPONSE_TIME.value,
         assertion_variable_name(api_call.title,
                                 AssertionDataSource.RESPONSE_TIME.value,
                                 ""),
         None,
         current_elapsed_time,
     ])
     item.setData(3, ASSERTION_TYPE_ROLE, "float")
     self.add_item(item, current_data=current_elapsed_time)