Skip to content

Commit 8503fb4

Browse files
committed
use send_file to send schema
1 parent 2812061 commit 8503fb4

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

oaipmh/requests/routes.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Dict
2-
from flask import Blueprint, request, render_template
2+
from flask import Blueprint, request, send_file
33

44
from oaipmh.requests.info_queries import identify, list_metadata_formats, list_sets
55
from oaipmh.requests.data_queries import get_record, list_data
@@ -42,24 +42,19 @@ def oai() -> Response:
4242

4343
@blueprint.route("/OAI/arXivRaw.xsd", methods=['GET', 'POST'])
4444
def schema_arXivRaw() -> Response:
45-
response=render_template("schema/arXivRaw.xsd")
46-
headers={}
47-
headers["Content-Type"]="application/xml"
48-
return response, 200, headers
45+
file_path = "templates/schema/arXivRaw.xsd"
46+
return send_file(file_path, mimetype="application/xml")
47+
4948

5049
@blueprint.route("/OAI/arXiv.xsd", methods=['GET', 'POST'])
5150
def schema_arXiv() -> Response:
52-
response=render_template("schema/arXiv.xsd")
53-
headers={}
54-
headers["Content-Type"]="application/xml"
55-
return response, 200, headers
51+
file_path = "templates/schema/arXiv.xsd"
52+
return send_file(file_path, mimetype="application/xml")
5653

5754
@blueprint.route("/OAI/arXivOld.xsd", methods=['GET', 'POST'])
5855
def schema_arXivOld() -> Response:
59-
response=render_template("schema/arXivOld.xsd")
60-
headers={}
61-
headers["Content-Type"]="application/xml"
62-
return response, 200, headers
56+
file_path = "templates/schema/arXivOld.xsd"
57+
return send_file(file_path, mimetype="application/xml")
6358

6459
@blueprint.route('/favicon.ico')
6560
def favicon():

tests/test_serve_schema.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
def test_schema_arXivRaw(test_client):
44
response = test_client.get("/OAI/arXivRaw.xsd")
55
assert response.status_code == 200
6-
assert response.content_type == "application/xml"
76
assert b"<schema" in response.data
87
assert b"</schema>" in response.data
98
assert b'xmlns:arXivRaw="http://arxiv.org/OAI/arXivRaw/"' in response.data
@@ -13,7 +12,6 @@ def test_schema_arXivRaw(test_client):
1312
def test_schema_arXivOld(test_client):
1413
response = test_client.get("/OAI/arXivOld.xsd")
1514
assert response.status_code == 200
16-
assert response.content_type == "application/xml"
1715
assert b"<schema" in response.data
1816
assert b"</schema>" in response.data
1917
assert b'xmlns:arXivOld="http://arxiv.org/OAI/arXivOld/"' in response.data
@@ -23,7 +21,6 @@ def test_schema_arXivOld(test_client):
2321
def test_schema_arXiv(test_client):
2422
response = test_client.get("/OAI/arXiv.xsd")
2523
assert response.status_code == 200
26-
assert response.content_type == "application/xml"
2724
assert b"<schema" in response.data
2825
assert b"</schema>" in response.data
2926
assert b'xmlns:arXiv="http://arxiv.org/OAI/arXiv/"' in response.data

0 commit comments

Comments
 (0)