From b4a8d7a2461c73bfa1ec823074bfce58e3b62378 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 27 Sep 2021 12:08:07 -0400 Subject: [PATCH] Fix selenium populators to respect the json parameter. Mirror behavior of the original request calls in the non-Selenium interactor - e.g. https://github.com/galaxyproject/galaxy/blob/dev/lib/galaxy/tool_util/verify/interactor.py#L747 --- lib/galaxy_test/selenium/framework.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/galaxy_test/selenium/framework.py b/lib/galaxy_test/selenium/framework.py index c24c734a695..f69ed4bbfd3 100644 --- a/lib/galaxy_test/selenium/framework.py +++ b/lib/galaxy_test/selenium/framework.py @@ -6,6 +6,7 @@ import os import traceback import unittest from functools import partial, wraps +from typing import Any, Dict import requests from gxformat2 import ( @@ -580,7 +581,8 @@ class SeleniumSessionGetPostMixin: full_url = f"{full_url}?key={self._mixin_admin_api_key}" else: cookies = self.selenium_context.selenium_to_requests_cookies() - response = requests.post(full_url, data=data, cookies=cookies, files=files, headers=headers, timeout=DEFAULT_SOCKET_TIMEOUT) + request_kwd = self._prepare_request_data(dict(cookies=cookies, headers=headers, timeout=DEFAULT_SOCKET_TIMEOUT, files=files), data, as_json=json) + response = requests.post(full_url, **request_kwd) return response def _delete(self, route, data=None, headers=None, admin=False, json: bool = False) -> Response: @@ -591,7 +593,8 @@ class SeleniumSessionGetPostMixin: full_url = f"{full_url}?key={self._mixin_admin_api_key}" else: cookies = self.selenium_context.selenium_to_requests_cookies() - response = requests.delete(full_url, data=data, cookies=cookies, headers=headers, timeout=DEFAULT_SOCKET_TIMEOUT) + request_kwd = self._prepare_request_data(dict(cookies=cookies, headers=headers, timeout=DEFAULT_SOCKET_TIMEOUT), data, as_json=json) + response = requests.delete(full_url, **request_kwd) return response def _put(self, route, data=None, headers=None, admin=False, json: bool = False) -> Response: @@ -602,9 +605,17 @@ class SeleniumSessionGetPostMixin: full_url = f"{full_url}?key={self._mixin_admin_api_key}" else: cookies = self.selenium_context.selenium_to_requests_cookies() - response = requests.put(full_url, data=data, cookies=cookies, headers=headers, timeout=DEFAULT_SOCKET_TIMEOUT) + request_kwd = self._prepare_request_data(dict(cookies=cookies, headers=headers, timeout=DEFAULT_SOCKET_TIMEOUT), data, as_json=json) + response = requests.put(full_url, **request_kwd) return response + def _prepare_request_data(self, request_kwd: Dict[str, Any], data: Dict[str, Any], as_json: bool = False): + if as_json: + request_kwd['json'] = data + else: + request_kwd['data'] = data + return request_kwd + class SeleniumSessionDatasetPopulator(SeleniumSessionGetPostMixin, populators.BaseDatasetPopulator):