1212import xkcd_wrapper
1313from aioresponses import aioresponses
1414from nose2 .tools .params import params as nose2_params
15- from . import (base_url , latest_comic_url , comic_id_url , check_comic ,
15+ from . import (base_url , latest_comic_url , comic_id_url , check_comic , raw_comic_image ,
1616 xkcd_api_example_628_raw ,
1717 xkcd_api_example_138_raw ,
1818 xkcd_api_example_wrong_raw ,
@@ -31,6 +31,13 @@ def test_client_init(self):
3131 self .assertIsInstance (c ._base_url , str )
3232 self .assertIsInstance (c ._api , str )
3333 self .assertIsInstance (c ._explanation_wiki_url , str )
34+ self .assertIsInstance (c ._explanation_wiki_url , str )
35+
36+ self .assertIsInstance (c ._response_int_values , dict )
37+ self .assertEqual (c ._response_int_values ['num' ], 'id' )
38+ self .assertEqual (c ._response_int_values ['year' ], 'date' )
39+ self .assertEqual (c ._response_int_values ['month' ], 'date' )
40+ self .assertEqual (c ._response_int_values ['day' ], 'date' )
3441
3542 def test_base_url (self ):
3643 c = xkcd_wrapper .AsyncClient ()
@@ -50,41 +57,54 @@ def test_get(self):
5057 loop = asyncio .get_event_loop ()
5158 with aioresponses () as mock :
5259 mock .get (comic_id_url .format (628 ), status = 200 , body = xkcd_api_example_628_raw )
60+ mock .get (xkcd_api_example_628_dict ['img' ], status = 200 , body = raw_comic_image )
5361 response = loop .run_until_complete (c .get (628 ))
5462 check_comic (self , response , xkcd_api_example_628_dict )
5563 with self .assertRaises (TypeError ):
5664 loop .run_until_complete (c .get ('' ))
5765 with self .assertRaises (TypeError ):
5866 loop .run_until_complete (c .get ([1 , 2 , 3 ]))
5967
68+ def test_get_without_raw_image (self ):
69+ c = xkcd_wrapper .AsyncClient ()
70+ loop = asyncio .get_event_loop ()
71+ with aioresponses () as mock :
72+ mock .get (comic_id_url .format (628 ), status = 200 , body = xkcd_api_example_628_raw )
73+ response = loop .run_until_complete (c .get (628 , raw_comic_image = False ))
74+ check_comic (self , response , xkcd_api_example_628_dict , raw_image = False )
75+ with self .assertRaises (TypeError ):
76+ loop .run_until_complete (c .get ('' ))
77+ with self .assertRaises (TypeError ):
78+ loop .run_until_complete (c .get ([1 , 2 , 3 ]))
79+
6080 def test_get_http_error (self ):
6181 c = xkcd_wrapper .AsyncClient ()
6282 loop = asyncio .get_event_loop ()
6383 with aioresponses () as mock :
6484 mock .get (comic_id_url .format (628 ), status = 404 )
6585 with self .assertRaises (xkcd_wrapper .exceptions .HttpError ):
66- loop .run_until_complete (c .get (628 ))
86+ loop .run_until_complete (c .get (628 , raw_comic_image = False ))
6787
6888 def test_get_bad_response_fields (self ):
6989 c = xkcd_wrapper .AsyncClient ()
7090 loop = asyncio .get_event_loop ()
7191 with aioresponses () as mock :
7292 mock .get (comic_id_url .format (628 ), status = 200 , body = xkcd_api_example_wrong_raw )
7393 with self .assertRaises (xkcd_wrapper .exceptions .BadResponseField ):
74- loop .run_until_complete (c .get (628 ))
94+ loop .run_until_complete (c .get (628 , raw_comic_image = False ))
7595
7696 def test_get_latest (self ): # let's assume the example_628 json is the latest comic
7797 c = xkcd_wrapper .AsyncClient ()
7898 loop = asyncio .get_event_loop ()
7999 with aioresponses () as mock :
80100 mock .get (latest_comic_url , status = 200 , body = xkcd_api_example_628_raw )
81- response = loop .run_until_complete (c .get_latest ())
82- check_comic (self , response , xkcd_api_example_628_dict )
101+ response = loop .run_until_complete (c .get_latest (raw_comic_image = False ))
102+ check_comic (self , response , xkcd_api_example_628_dict , raw_image = False )
83103
84104 # alias
85105 mock .get (latest_comic_url , status = 200 , body = xkcd_api_example_628_raw )
86- response = loop .run_until_complete (c .latest ())
87- check_comic (self , response , xkcd_api_example_628_dict )
106+ response = loop .run_until_complete (c .latest (raw_comic_image = False ))
107+ check_comic (self , response , xkcd_api_example_628_dict , raw_image = False )
88108
89109 def test_get_random (self ): # let's assume the example_628 json is the latest comic
90110 c = xkcd_wrapper .AsyncClient ()
@@ -93,17 +113,17 @@ def test_get_random(self): # let's assume the example_628 json is the latest co
93113 mock .get (latest_comic_url , status = 200 , body = xkcd_api_example_628_raw )
94114 mock .get (comic_id_url .format (138 ), status = 200 , body = xkcd_api_example_138_raw )
95115 random .seed (1 ) # with latest comic being 628, random value will be 138
96- response = loop .run_until_complete (c .get_random ())
116+ response = loop .run_until_complete (c .get_random (raw_comic_image = False ))
97117 self .assertEqual (response .id , xkcd_api_example_138_dict ['num' ])
98- check_comic (self , response , xkcd_api_example_138_dict )
118+ check_comic (self , response , xkcd_api_example_138_dict , raw_image = False )
99119
100120 # alias
101121 mock .get (latest_comic_url , status = 200 , body = xkcd_api_example_628_raw )
102122 mock .get (comic_id_url .format (138 ), status = 200 , body = xkcd_api_example_138_raw )
103123 random .seed (1 )
104- response = loop .run_until_complete (c .get_random ())
124+ response = loop .run_until_complete (c .get_random (raw_comic_image = False ))
105125 self .assertEqual (response .id , xkcd_api_example_138_dict ['num' ])
106- check_comic (self , response , xkcd_api_example_138_dict )
126+ check_comic (self , response , xkcd_api_example_138_dict , raw_image = False )
107127
108128 def test__repr__ (self ):
109129 c = xkcd_wrapper .AsyncClient ()
0 commit comments