mirror of https://github.com/zulip/zulip.git
devtools: Tweak the integrations tool to use http headers fixtures.
Now that we store HTTP headers in a way that is easy to retreive by specifying the integration name and fixture name, we should use it to pre-load the "Custom HTTP Headers" field in the integrations dev panel.
This commit is contained in:
parent
37d90d9add
commit
720c866e06
|
@ -105,7 +105,9 @@ function load_fixture_body(fixture_name) {
|
|||
/* Given a fixture name, use the loaded_fixtures dictionary to set
|
||||
* the fixture body field. */
|
||||
var integration_name = get_selected_integration_name();
|
||||
var fixture_body = loaded_fixtures[integration_name][fixture_name];
|
||||
var fixture = loaded_fixtures[integration_name][fixture_name];
|
||||
var fixture_body = fixture.body;
|
||||
var headers = fixture.headers;
|
||||
if (fixture_body === undefined) {
|
||||
set_results_notice("Fixture does not have a body.", "warning");
|
||||
return;
|
||||
|
@ -115,6 +117,7 @@ function load_fixture_body(fixture_name) {
|
|||
fixture_body = JSON.stringify(fixture_body, null, 4);
|
||||
}
|
||||
$("#fixture_body")[0].value = fixture_body;
|
||||
$("#custom_http_headers")[0].value = JSON.stringify(headers, null, 4);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ from zerver.lib.request import has_request_variables, REQ
|
|||
from zerver.lib.response import json_success, json_error
|
||||
from zerver.models import UserProfile, get_realm
|
||||
from zerver.management.commands.send_webhook_fixture_message import parse_headers
|
||||
from zerver.lib.webhooks.common import get_fixture_http_headers
|
||||
|
||||
|
||||
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../')
|
||||
|
@ -63,12 +64,22 @@ def get_fixtures(request: HttpResponse,
|
|||
|
||||
for fixture in os.listdir(fixtures_dir):
|
||||
fixture_path = os.path.join(fixtures_dir, fixture)
|
||||
content = open(fixture_path).read()
|
||||
body = open(fixture_path).read()
|
||||
try:
|
||||
content = ujson.loads(content)
|
||||
body = ujson.loads(body)
|
||||
except ValueError:
|
||||
pass # The file extension will be used to determine the type.
|
||||
fixtures[fixture] = content
|
||||
|
||||
headers_raw = get_fixture_http_headers(integration_name,
|
||||
"".join(fixture.split(".")[:-1]))
|
||||
headers = {}
|
||||
for header in headers_raw:
|
||||
if header.startswith("HTTP_"): # HTTP_ is a prefix intended for Django.
|
||||
headers[header.lstrip("HTTP_")] = headers_raw[header]
|
||||
else:
|
||||
headers[header] = headers_raw[header]
|
||||
|
||||
fixtures[fixture] = {"body": body, "headers": headers}
|
||||
|
||||
return json_success({"fixtures": fixtures})
|
||||
|
||||
|
|
Loading…
Reference in New Issue