Skip to content
Snippets Groups Projects
Commit 61308d1e3099 authored by Arnaud Vergnet's avatar Arnaud Vergnet :sun_with_face:
Browse files

test: add missing custom header tests

parent b3424501df0a
No related branches found
No related tags found
1 merge request!62tests: improve coverage
......@@ -16,7 +16,7 @@
import json
import webtest
from test.util import ApiBaseTC
from test.util import ApiBaseTC, check_missing_custom_header_response
class ApiBinaryTC(ApiBaseTC):
......@@ -115,3 +115,16 @@
status=204,
)
assert response.body == b""
def test_missing_custom_headers_returns_400(self):
response = self.webapp.get(
self.get_api_path("binary"),
status=400,
).json
check_missing_custom_header_response(response, 2)
response = self.webapp.get(
self.get_api_path("binary"),
params={"eid": 50, "attribute": "binary"},
status=400,
).json
check_missing_custom_header_response(response)
......@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from test.util import ApiBaseTC
from test.util import ApiBaseTC, check_missing_custom_header_response
class ApiCurrentUserTC(ApiBaseTC):
......@@ -35,3 +35,7 @@
assert response["login"] == "anon"
assert response["dcTitle"] == "anon"
assert isinstance(response["eid"], int)
def test_missing_custom_headers_returns_400(self):
response = self.webapp.get(self.get_api_path("current-user"), status=400).json
check_missing_custom_header_response(response)
......@@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import json
from test.util import ApiBaseTC
from test.util import ApiBaseTC, check_missing_custom_header_response
class ApiLoginTC(ApiBaseTC):
......@@ -117,7 +117,12 @@
def test_missing_custom_headers_returns_400(self):
response = self.webapp.post(
self.get_api_path("login"),
status=400,
).json
check_missing_custom_header_response(response)
response = self.webapp.post(
self.get_api_path("login"),
params=json.dumps({"login": self.admlogin, "password": self.admpassword}),
content_type="application/json",
status=400,
).json
......@@ -120,19 +125,8 @@
params=json.dumps({"login": self.admlogin, "password": self.admpassword}),
content_type="application/json",
status=400,
).json
assert response == {
"data": [
{
"exception": "MissingRequiredParameter",
"field": "X-Client-Name",
"message": "Missing required parameter: X-Client-Name",
},
],
"message": "Your request could not be validated against the openapi "
"specification.",
"title": "OpenApiValidationError",
}
check_missing_custom_header_response(response)
class ApiLoginDisabledDefaultTC(ApiBaseTC):
......
......@@ -16,7 +16,7 @@
import json
import webtest
from test.util import ApiBaseTC
from test.util import ApiBaseTC, check_missing_custom_header_response
from cubicweb import Binary
......@@ -197,7 +197,18 @@
def test_missing_custom_headers_returns_400(self):
response = self.webapp.post(
self.get_api_path("rql"),
status=400,
).json
check_missing_custom_header_response(response)
response = self.webapp.post(
self.get_api_path("rql"),
content_type=self.content_type,
status=400,
).json
check_missing_custom_header_response(response)
response = self.webapp.post(
self.get_api_path("rql"),
params=self.get_body([{"query": "test", "params": {}}]),
content_type=self.content_type,
status=400,
).json
......@@ -200,19 +211,8 @@
params=self.get_body([{"query": "test", "params": {}}]),
content_type=self.content_type,
status=400,
).json
assert response == {
"data": [
{
"exception": "MissingRequiredParameter",
"field": "X-Client-Name",
"message": "Missing required parameter: X-Client-Name",
},
],
"message": "Your request could not be validated against the openapi "
"specification.",
"title": "OpenApiValidationError",
}
check_missing_custom_header_response(response)
class ApiRqlMultipartTC(ApiRqlTC):
......
......@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from test.util import ApiBaseTC
from test.util import ApiBaseTC, check_missing_custom_header_response
from cubicweb.schema_exporters import JSONSchemaExporter
......@@ -28,3 +28,7 @@
exported_schema = exporter.export_as_dict(self.repo.schema)
assert exported_schema == schema
def test_missing_custom_headers_returns_400(self):
response = self.webapp.get(self.get_api_path("schema"), status=400).json
check_missing_custom_header_response(response)
import json
from typing import Optional
from cubicweb.pyramid.test import PyramidCWTest
......@@ -9,6 +10,11 @@
BASE_URL = "https://testing.cubicweb/"
def check_missing_custom_header_response(response, index_in_data: Optional[int] = 0):
assert response["data"][index_in_data]["exception"] == "MissingRequiredParameter"
assert response["data"][index_in_data]["field"] == "X-Client-Name"
class ApiBaseTC(PyramidCWTest):
settings = {
"cubicweb.includes": ["cubicweb.pyramid.auth"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment