|
5 | 5 |
|
6 | 6 | from gateway_api.common.error import ( |
7 | 7 | MissingOrEmptyHeaderError, |
| 8 | + UnsupportedMediaTypeError, |
8 | 9 | ) |
9 | 10 | from gateway_api.conftest import create_mock_request |
10 | 11 | from gateway_api.get_structured_record.request import GetStructuredRecordRequest |
@@ -118,3 +119,33 @@ def test_raises_value_error_when_trace_id_header_is_whitespace( |
118 | 119 | match='Missing or empty required header "Ssp-TraceID"', |
119 | 120 | ): |
120 | 121 | GetStructuredRecordRequest(request=mock_request) |
| 122 | + |
| 123 | + def test_missing_content_type_header_is_accepted( |
| 124 | + self, valid_simple_request_payload: dict[str, Any] |
| 125 | + ) -> None: |
| 126 | + """Test that a missing Content-Type header does not raise an error.""" |
| 127 | + headers = { |
| 128 | + "Content-Type": "", |
| 129 | + "Ssp-TraceID": "test-trace-id", |
| 130 | + "ODS-from": "test-ods", |
| 131 | + } |
| 132 | + mock_request = create_mock_request(headers, valid_simple_request_payload) |
| 133 | + |
| 134 | + GetStructuredRecordRequest(request=mock_request) |
| 135 | + |
| 136 | + def test_raises_unsupported_media_type_when_content_type_is_invalid( |
| 137 | + self, valid_simple_request_payload: dict[str, Any] |
| 138 | + ) -> None: |
| 139 | + """ |
| 140 | + Test that UnsupportedMediaTypeError is raised when Content-Type |
| 141 | + is not "application/fhir+json". |
| 142 | + """ |
| 143 | + headers = { |
| 144 | + "Content-Type": "application/json", |
| 145 | + "Ssp-TraceID": "test-trace-id", |
| 146 | + "ODS-from": "test-ods", |
| 147 | + } |
| 148 | + mock_request = create_mock_request(headers, valid_simple_request_payload) |
| 149 | + |
| 150 | + with pytest.raises(UnsupportedMediaTypeError): |
| 151 | + GetStructuredRecordRequest(request=mock_request) |
0 commit comments