<s> """<STR_LIT>""" <EOL> import unittest <EOL> import requests <EOL> import os <EOL> from tempfile import NamedTemporaryFile <EOL> import ads . base <EOL> import ads . config <EOL> from ads . base import BaseQuery , APIResponse <EOL> from . mocks import MockApiResponse <EOL> class TestApiResponse ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> with MockApiResponse ( '<STR_LIT>' ) : <EOL> self . APIResponse = APIResponse ( ) <EOL> self . APIResponse . response = requests . get ( '<STR_LIT>' ) <EOL> def test_get_ratelimits ( self ) : <EOL> """<STR_LIT>""" <EOL> limits = self . APIResponse . get_ratelimits ( ) <EOL> self . assertEqual ( limits [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( limits [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( limits [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> class TestBaseQuery ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_token ( self ) : <EOL> """<STR_LIT>""" <EOL> def reset_token ( ) : <EOL> bq . token = None <EOL> ads . base . TOKEN_ENVIRON_VARS = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> os . environ [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> os . environ [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> tf1 , tf2 = NamedTemporaryFile ( ) , NamedTemporaryFile ( ) <EOL> tf1 . write ( '<STR_LIT>' . encode ( "<STR_LIT:utf-8>" ) ) <EOL> tf2 . write ( '<STR_LIT>' . encode ( "<STR_LIT:utf-8>" ) ) <EOL> [ f . flush ( ) for f in [ tf1 , tf2 ] ] <EOL> [ f . seek ( <NUM_LIT:0> ) for f in [ tf1 , tf2 ] ] <EOL> ads . base . TOKEN_FILES = [ tf1 . name , tf2 . name ] <EOL> bq = BaseQuery ( ) <EOL> self . assertEqual ( bq . token , '<STR_LIT>' ) <EOL> reset_token ( ) <EOL> del os . environ [ '<STR_LIT>' ] <EOL> self . assertEqual ( bq . token , '<STR_LIT>' ) <EOL> reset_token ( ) <EOL> del os . environ [ '<STR_LIT>' ] <EOL> self . assertEqual ( bq . token , '<STR_LIT>' ) <EOL> reset_token ( ) <EOL> tf1 . close ( ) <EOL> self . assertEqual ( bq . token , '<STR_LIT>' ) <EOL> reset_token ( ) <EOL> tf2 . close ( ) <EOL> self . assertEqual ( bq . token , None ) <EOL> ads . config . token = "<STR_LIT>" <EOL> self . assertEqual ( BaseQuery ( ) . token , "<STR_LIT>" ) <EOL> def test_headers ( self ) : <EOL> """<STR_LIT>""" <EOL> hdrs = BaseQuery ( ) . session . headers <EOL> self . assertEqual ( hdrs [ '<STR_LIT:Content-Type>' ] , '<STR_LIT:application/json>' ) <EOL> self . assertIn ( '<STR_LIT>' , hdrs [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , hdrs [ '<STR_LIT>' ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( verbosity = <NUM_LIT:2> ) </s>
