@@ -962,7 +962,7 @@ def test_kw_only(self):
962
962
XML = (MEDIA_XML , MEDIA_XML , XML_CONTENT )
963
963
CUSTOM_XML = ('custom/any+xml' , MEDIA_XML , XML_CONTENT )
964
964
965
- YAML = (MEDIA_YAML , MEDIA_YAML , ( b'title: 410 Gone!' ) )
965
+ YAML = (MEDIA_YAML , MEDIA_YAML , b'title: 410 Gone!' )
966
966
ASYNC_ONLY = ('application/only_async' , 'application/only_async' , b'this is async' )
967
967
ASYNC_WITH_SYNC = (
968
968
'application/async_with_sync' ,
@@ -1040,3 +1040,34 @@ def test_json_async_only_error(self, util):
1040
1040
client = testing .TestClient (app )
1041
1041
with pytest .raises (NotImplementedError , match = 'requires the sync interface' ):
1042
1042
client .simulate_get ()
1043
+
1044
+ def test_add_xml_handler (self , client ):
1045
+ client .app .resp_options .media_handlers [MEDIA_XML ] = FakeYamlMediaHandler ()
1046
+ res = client .simulate_get (headers = {'Accept' : 'application/xhtml+xml' })
1047
+ assert res .content_type == MEDIA_XML
1048
+ assert res .content == YAML [- 1 ]
1049
+
1050
+ @pytest .mark .parametrize (
1051
+ 'accept, content_type' ,
1052
+ [
1053
+ (
1054
+ # firefox
1055
+ 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,'
1056
+ 'image/webp,image/png,image/svg+xml,*/*;q=0.8' ,
1057
+ MEDIA_XML ,
1058
+ ),
1059
+ (
1060
+ # safari / chrome
1061
+ 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,'
1062
+ 'image/apng,*/*;q=0.8' ,
1063
+ MEDIA_XML ,
1064
+ ),
1065
+ ('text/html, application/xhtml+xml, image/jxr, */*' , MEDIA_JSON ), # edge
1066
+ (f'text/html,{ MEDIA_YAML } ;q=0.8,*/*;q=0.7' , MEDIA_YAML ),
1067
+ (f'text/html,{ MEDIA_YAML } ;q=0.8,{ MEDIA_JSON } ;q=0.8' , MEDIA_JSON ),
1068
+ ],
1069
+ )
1070
+ def test_hard_content_types (self , client , accept , content_type ):
1071
+ client .app .resp_options .media_handlers [MEDIA_YAML ] = FakeYamlMediaHandler ()
1072
+ res = client .simulate_get (headers = {'Accept' : accept })
1073
+ assert res .content_type == content_type
0 commit comments