33from  werkzeug .wrappers  import  Response  as  ResponseBase 
44from  flask  import  make_response 
55
6+ import  json 
7+ import  cbor2 
8+ 
69import  pytest 
710
811
@@ -53,14 +56,29 @@ def post(self):
5356def  test_accept_default_application_json (app , client ):
5457    class  Index (view .View ):
5558        def  get (self ):
56-             return  "GET" 
59+             return  { "key" :  "value" } 
5760
5861    app .add_url_rule ("/" , view_func = Index .as_view ("index" ))
5962
6063    with  client :
61-         res  =  client .get ("/" ,  headers = [( "Accept" ,  "application/json" )] )
64+         res  =  client .get ("/" )
6265        assert  res .status_code  ==  200 
6366        assert  res .content_type  ==  "application/json" 
67+         assert  json .loads (res .data ) ==  {"key" : "value" }
68+ 
69+ 
70+ def  test_accept_default_application_cbor (app , cbor_client ):
71+     class  Index (view .View ):
72+         def  get (self ):
73+             return  {"key" : "value" }
74+ 
75+     app .add_url_rule ("/" , view_func = Index .as_view ("index" ))
76+ 
77+     with  cbor_client :
78+         res  =  cbor_client .get ("/" )
79+         assert  res .status_code  ==  200 
80+         assert  res .content_type  ==  "application/cbor" 
81+         assert  cbor2 .loads (res .data ) ==  {"key" : "value" }
6482
6583
6684def  test_return_response (app , client ):
@@ -71,7 +89,7 @@ def get(self):
7189    app .add_url_rule ("/" , view_func = Index .as_view ("index" ))
7290
7391    with  client :
74-         res  =  client .get ("/" ,  headers = [( "Accept" ,  "application/json" )] )
92+         res  =  client .get ("/" )
7593        assert  res .status_code  ==  200 
7694        assert  res .data  ==  b"GET" 
7795
@@ -84,7 +102,7 @@ def get(self):
84102    app .add_url_rule ("/" , view_func = Index .as_view ("index" ))
85103
86104    with  client :
87-         res  =  client .post ("/" ,  headers = [( "Accept" ,  "application/json" )] )
105+         res  =  client .post ("/" )
88106        assert  res .status_code  ==  405 
89107
90108
@@ -105,6 +123,7 @@ class Index(view.View):
105123        def  get (self ):
106124            return  "GET" 
107125
126+     # Main test 
108127    assert  Index ().get_value () ==  "GET" 
109128
110129
@@ -113,6 +132,7 @@ class Index(view.View):
113132        def  post (self ):
114133            return  "POST" 
115134
135+     # Main test 
116136    assert  Index ().get_value () is  None 
117137
118138
@@ -124,6 +144,7 @@ def post(self):
124144    Index .get  =  "GET" 
125145
126146    with  pytest .raises (TypeError ):
147+         # Main test 
127148        Index ().get_value ()
128149
129150
@@ -134,7 +155,8 @@ def get(self):
134155
135156    with  app_ctx .test_request_context ():
136157        assert  isinstance (Index ().get (), ResponseBase )
137-         assert  Index ().get ().json  is  None 
158+         assert  Index ().get ().headers .get ("Content-Type" ) ==  "text/html; charset=utf-8" 
159+         # Main test 
138160        assert  Index ().get_value () ==  "GET" 
139161
140162
@@ -145,5 +167,6 @@ def get(self):
145167
146168    with  app_ctx .test_request_context ():
147169        assert  isinstance (Index ().get (), ResponseBase )
148-         assert  Index ().get ().json  is  not None 
170+         assert  Index ().get ().headers .get ("Content-Type" ) ==  "application/json" 
171+         # Main test 
149172        assert  Index ().get_value () ==  {"json" : "body" }
0 commit comments