How to use _request method in Molotov

Best Python code snippet using molotov_python

tmdb_api.py

Source:tmdb_api.py Github

copy

Full Screen

...10 def __init__(self, api_key, version=3):11 TMDB.api_key = str(api_key)12 TMDB.url = 'https://api.themoviedb.org' + '/' + str(version)13 @staticmethod14 def _request(method, path, params={}, json_body={}):15 url = TMDB.url + '/' + path + '?api_key=' + TMDB.api_key16 if method == 'GET':17 headers = {'Accept': 'application/json'}18 content = requests.get(url, params=params, headers=headers).content19 elif method == 'POST':20 for key in params.keys():21 url += '&' + key + '=' + params[key]22 headers = {'Content-Type': 'application/json', \23 'Accept': 'application/json'}24 content = requests.post(url, data=json.dumps(json_body), \25 headers=headers).content26 elif method == 'DELETE':27 for key in params.keys():28 url += '&' + key + '=' + params[key]29 headers = {'Content-Type': 'application/json', \30 'Accept': 'application/json'}31 content = requests.delete(url, data=json.dumps(json_body), \32 headers=headers).content33 else:34 raise Exception('method: ' + method + ' not supported.')35 response = json.loads(content.decode('utf-8'))36 return response37 38 #39 # Set attributes to dictionary values.40 # - e.g.41 # >>> tmdb = TMDB()42 # >>> movie = tmdb.Movie(103332)43 # >>> response = movie.info()44 # >>> movie.title # instead of response['title']45 #46 @staticmethod47 def _set_attrs_to_values(object, response={}):48 for key in response.keys():49 setattr(object, key, response[key])50 #51 # Configuration52 # http://docs.themoviedb.apiary.io/#configuration53 #54 class Configuration:55 def __init__(self):56 pass57 def info(self):58 path = 'configuration'59 response = TMDB._request('GET', path)60 TMDB._set_attrs_to_values(self, response)61 return response62 #63 # Account64 # http://docs.themoviedb.apiary.io/#account65 #66 class Account:67 def __init__(self, session_id):68 self.session_id = session_id69 # need to call this first to set account id70 def info(self):71 path = 'account'72 params = {'session_id': self.session_id}73 response = TMDB._request('GET', path, params)74 TMDB._set_attrs_to_values(self, response)75 return response76 77 # optional parameters: page, language78 def lists(self, params={}):79 path = 'account' + '/' + str(self.session_id) + '/lists'80 params['session_id'] = self.session_id81 response = TMDB._request('GET', path, params)82 TMDB._set_attrs_to_values(self, response)83 return response84 # optional parameters: page, sort_by, sort_order, language85 def favorite_movies(self, params={}):86 path = 'account' + '/' + str(self.session_id) + '/favorite_movies'87 params['session_id'] = self.session_id88 response = TMDB._request('GET', path, params)89 TMDB._set_attrs_to_values(self, response)90 return response91 # required JSON body: movie_id, favorite92 def favorite(self, json_body):93 path = 'account' + '/' + str(json_body['movie_id']) + '/favorite'94 params = {'session_id': self.session_id}95 response = TMDB._request('POST', path, params, json_body)96 TMDB._set_attrs_to_values(self, response)97 return response98 # optional parameters: page, sort_by, sort_order, language99 def rated_movies(self, params={}):100 path = 'account' + '/' + str(self.session_id) + '/rated_movies'101 params['session_id'] = self.session_id102 response = TMDB._request('GET', path, params)103 TMDB._set_attrs_to_values(self, response)104 return response105 # optional parameters: page, sort_by, sort_order, language106 def movie_watchlist(self, params={}):107 path = 'account' + '/' + str(self.session_id) + '/movie_watchlist'108 params['session_id'] = self.session_id109 response = TMDB._request('GET', path, params)110 TMDB._set_attrs_to_values(self, response)111 return response112 113 # required JSON body: movie_id, movie_watchlist114 def movie_watchlist_post(self, json_body):115 path = 'account' + '/' + str(json_body['movie_id']) + \116 '/movie_watchlist'117 params = {'session_id': self.session_id}118 response = TMDB._request('POST', path, params, json_body)119 TMDB._set_attrs_to_values(self, response)120 return response121 #122 # Authentication123 # http://docs.themoviedb.apiary.io/#authentication124 #125 # Note: to use authentication to access a user account, see:126 # https://www.themoviedb.org/documentation/api/sessions127 #128 class Authentication:129 def __init__(self):130 pass131 def token_new(self):132 path = 'authentication/token/new'133 response = TMDB._request('GET', path)134 TMDB._set_attrs_to_values(self, response)135 return response136 # required parameters: request_token137 def session_new(self, params):138 path = 'authentication/session/new'139 response = TMDB._request('GET', path, params)140 TMDB._set_attrs_to_values(self, response)141 return response142 def guest_session_new(self):143 path = 'authentication/guest_session/new'144 response = TMDB._request('GET', path)145 TMDB._set_attrs_to_values(self, response)146 return response147 #148 # Changes149 # http://docs.themoviedb.apiary.io/#changes150 #151 class Changes:152 def __init__(self):153 pass154 # optional parameters: page, start_date, end_date155 def movie(self, params={}):156 path = 'movie/changes'157 response = TMDB._request('GET', path, params)158 TMDB._set_attrs_to_values(self, response)159 return response160 161 # optional parameters: page, start_date, end_date162 def person(self, params={}):163 path = 'person/changes'164 response = TMDB._request('GET', path, params)165 TMDB._set_attrs_to_values(self, response)166 return response167 #168 # Collections169 # http://docs.themoviedb.apiary.io/#collections170 #171 class Collections:172 def __init__(self, id):173 self.id = id174 # optional parameter: language175 def info(self, params={}):176 path = 'collection' + '/' + str(self.id)177 response = TMDB._request('GET', path, params)178 TMDB._set_attrs_to_values(self, response)179 return response180 # optional parameters: language, include_image_language181 def images(self, params={}):182 path = 'collection' + '/' + str(self.id) + '/images'183 response = TMDB._request('GET', path, params)184 TMDB._set_attrs_to_values(self, response)185 return response186 #187 # Companies188 # http://docs.themoviedb.apiary.io/#companies189 #190 class Companies:191 def __init__(self, id=0):192 self.id = id193 def info(self):194 path = 'company' + '/' + str(self.id)195 response = TMDB._request('GET', path)196 TMDB._set_attrs_to_values(self, response)197 return response198 199 # optional parameters: page, language200 def movies(self, params={}):201 path = 'company' + '/' + str(self.id) + '/movies'202 response = TMDB._request('GET', path, params)203 TMDB._set_attrs_to_values(self, response)204 return response205 #206 # Credits207 # http://docs.themoviedb.apiary.io/#credits208 #209 class Credits:210 def __init__(self, credit_id):211 self.credit_id = credit_id212 # optional parameters: language213 def info(self, params={}):214 path = 'credit' + '/' + str(self.credit_id)215 response = TMDB._request('GET', path, params)216 TMDB._set_attrs_to_values(self, response)217 return response218 #219 # Discover220 # http://docs.themoviedb.apiary.io/#discover221 #222 class Discover:223 def __init__(self):224 pass225 # optional parameters: page, language, sort_by, include_adult, year, 226 # primary_release_year, vote_count.gte, vote_average.gte, with_genres, 227 # release_date.gte, release_date.lte, certification_country, 228 # certification.lte, with_companies229 def movie(self, params):230 path = 'discover/movie'231 response = TMDB._request('GET', path, params)232 TMDB._set_attrs_to_values(self, response)233 return response234 # optional parameters: page, language, sort_by, first_air_date_year,235 # vote_count.gte, vote_average.gte, with_genres, with_networks,236 # first_air_date.gte, first_air_date.lte237 def tv(self, params):238 path = 'discover/tv'239 response = TMDB._request('GET', path, params)240 TMDB._set_attrs_to_values(self, response)241 return response242 #243 # Find244 # http://docs.themoviedb.apiary.io/#find245 #246 class Find:247 def __init__(self, id=0):248 self.id = id249 # required parameters: external_source250 def info(self, params={}):251 path = 'find' + '/' + str(self.id)252 response = TMDB._request('GET', path, params)253 TMDB._set_attrs_to_values(self, response)254 return response255 #256 # Genres257 # http://docs.themoviedb.apiary.io/#genres258 #259 class Genres:260 def __init__(self, id=0):261 self.id = id262 # optional parameters: language263 def list(self, params={}):264 path = 'genre/list'265 response = TMDB._request('GET', path, params)266 TMDB._set_attrs_to_values(self, response)267 return response268 269 # optional parameters: page, language, include_all_movies, include_adult270 def movies(self, params={}):271 path = 'genre' + '/' + str(self.id) + '/movies'272 response = TMDB._request('GET', path, params)273 TMDB._set_attrs_to_values(self, response)274 return response275 #276 # Jobs277 # http://docs.themoviedb.apiary.io/#jobs278 #279 class Jobs:280 def __init__(self):281 pass282 def list(self):283 path = 'job/list'284 response = TMDB._request('GET', path)285 TMDB._set_attrs_to_values(self, response)286 return response287 288 #289 # Keywords290 # http://docs.themoviedb.apiary.io/#keywords291 #292 class Keywords:293 def __init__(self, id):294 self.id = id295 def info(self):296 path = 'keyword' + '/' + str(self.id)297 response = TMDB._request('GET', path)298 TMDB._set_attrs_to_values(self, response)299 return response300 # optional parameters: page, language301 def movies(self, params={}):302 path = 'keyword' + '/' + str(self.id) + '/movies'303 response = TMDB._request('GET', path, params)304 TMDB._set_attrs_to_values(self, response)305 return response306 #307 # Lists308 # http://docs.themoviedb.apiary.io/#lists309 #310 class Lists:311 def __init__(self, id=0, session_id=0):312 self.id = id313 self.session_id = session_id314 def info(self):315 path = 'list' + '/' + str(self.id)316 response = TMDB._request('GET', path)317 TMDB._set_attrs_to_values(self, response)318 return response319 # required parameters: movie_id320 def item_status(self, params):321 path = 'list' + '/' + str(self.id) + '/item_status'322 response = TMDB._request('GET', path, params)323 TMDB._set_attrs_to_values(self, response)324 return response325 # required JSON body: name, description326 # optional JSON body: language327 def create_list(self, json_body):328 path = 'list'329 params = {'session_id': self.session_id}330 response = TMDB._request('POST', path, params, json_body)331 TMDB._set_attrs_to_values(self, response)332 return response333 # required JSON body: media_id334 def add_item(self, json_body):335 path = 'list' + '/' + str(self.id) + '/add_item'336 params = {'session_id': self.session_id}337 response = TMDB._request('POST', path, params, json_body)338 TMDB._set_attrs_to_values(self, response)339 return response340 341 # required JSON body: media_id342 def remove_item(self, json_body):343 path = 'list' + '/' + str(self.id) + '/remove_item'344 params = {'session_id': self.session_id}345 response = TMDB._request('POST', path, params, json_body)346 TMDB._set_attrs_to_values(self, response)347 return response348 def delete_list(self):349 path = 'list' + '/' + str(self.id)350 params = {'session_id': self.session_id}351 response = TMDB._request('DELETE', path, params)352 TMDB._set_attrs_to_values(self, response)353 return response354 #355 # Movies356 # http://docs.themoviedb.apiary.io/#movies357 #358 class Movies:359 """ """360 def __init__(self, id=0):361 self.id = id362 # optional parameters: language363 def info(self, params={}):364 path = 'movie' + '/' + str(self.id)365 response = TMDB._request('GET', path, params)366 TMDB._set_attrs_to_values(self, response)367 return response368 # optional parameters: country369 def alternative_titles(self, params={}):370 path = 'movie' + '/' + str(self.id) + '/alternative_titles'371 response = TMDB._request('GET', path, params)372 TMDB._set_attrs_to_values(self, response)373 return response374 def credits(self):375 path = 'movie' + '/' + str(self.id) + '/credits'376 response = TMDB._request('GET', path)377 TMDB._set_attrs_to_values(self, response)378 return response379 # optional parameters: language, include_image_language380 def images(self, params={}):381 path = 'movie' + '/' + str(self.id) + '/images'382 response = TMDB._request('GET', path, params)383 TMDB._set_attrs_to_values(self, response)384 return response385 def keywords(self):386 path = 'movie' + '/' + str(self.id) + '/keywords'387 response = TMDB._request('GET', path)388 TMDB._set_attrs_to_values(self, response)389 return response390 def releases(self):391 path = 'movie' + '/' + str(self.id) + '/releases'392 response = TMDB._request('GET', path)393 TMDB._set_attrs_to_values(self, response)394 return response395 def trailers(self):396 path = 'movie' + '/' + str(self.id) + '/trailers'397 response = TMDB._request('GET', path)398 TMDB._set_attrs_to_values(self, response)399 return response400 def translations(self):401 path = 'movie' + '/' + str(self.id) + '/translations'402 response = TMDB._request('GET', path)403 TMDB._set_attrs_to_values(self, response)404 return response405 # optional parameters: page, language406 def similar_movies(self, params={}):407 path = 'movie' + '/' + str(self.id) + '/similar_movies'408 response = TMDB._request('GET', path, params)409 TMDB._set_attrs_to_values(self, response)410 return response411 412 # optional parameters: page, language413 def reviews(self, params={}):414 path = 'movie' + '/' + str(self.id) + '/reviews'415 response = TMDB._request('GET', path, params)416 TMDB._set_attrs_to_values(self, response)417 return response418 419 # optional parameters: page, language420 def lists(self, params={}):421 path = 'movie' + '/' + str(self.id) + '/lists'422 response = TMDB._request('GET', path, params)423 TMDB._set_attrs_to_values(self, response)424 return response425 426 # optional parameters: start_date, end_date427 def changes(self, params={}):428 path = 'movie' + '/' + str(self.id) + '/changes'429 response = TMDB._request('GET', path, params)430 TMDB._set_attrs_to_values(self, response)431 return response432 def latest(self):433 path = 'movie/latest'434 response = TMDB._request('GET', path)435 TMDB._set_attrs_to_values(self, response)436 return response437 # optional parameters: page, language438 def upcoming(self, params={}):439 path = 'movie/upcoming'440 response = TMDB._request('GET', path, params)441 TMDB._set_attrs_to_values(self, response)442 return response443 # optional parameters: page, language444 def now_playing(self, params={}):445 path = 'movie/now_playing'446 response = TMDB._request('GET', path, params)447 TMDB._set_attrs_to_values(self, response)448 return response449 450 # optional parameters: page, language451 def popular(self, params={}):452 path = 'movie/popular'453 response = TMDB._request('GET', path, params)454 TMDB._set_attrs_to_values(self, response)455 return response456 # optional parameters: page, language457 def top_rated(self, params={}):458 path = 'movie/top_rated'459 response = TMDB._request('GET', 'movie' + '/top_rated', params)460 TMDB._set_attrs_to_values(self, response)461 return response462 # required parameters: session_id463 def account_states(self, params):464 path = 'movie' + '/' + str(self.id) + '/account_states'465 response = TMDB._request('GET', path, params)466 TMDB._set_attrs_to_values(self, response)467 return response468 # required parameters: session_id or guest_session_id469 # required JSON body: value470 def rating(self, params, json_body):471 path = 'movie' + '/' + str(self.id) + '/rating'472 response = TMDB._request('POST', path, params, json_body)473 TMDB._set_attrs_to_values(self, response)474 return response475 #476 # Networks477 # http://docs.themoviedb.apiary.io/#networks478 #479 class Networks:480 def __init__(self, id):481 self.id = id482 def info(self):483 path = 'network' + '/' + str(self.id)484 response = TMDB._request('GET', path)485 TMDB._set_attrs_to_values(self, response)486 return response487 #488 # People489 # http://docs.themoviedb.apiary.io/#people490 #491 class People:492 def __init__(self, id=0):493 self.id = id494 def info(self):495 path = 'person' + '/' + str(self.id)496 response = TMDB._request('GET', path)497 TMDB._set_attrs_to_values(self, response)498 return response499 # optional parameters: language500 def movie_credits(self, params={}):501 path = 'person' + '/' + str(self.id) + '/movie_credits'502 response = TMDB._request('GET', path, params)503 TMDB._set_attrs_to_values(self, response)504 return response505 # optional parameters: language506 def tv_credits(self, params={}):507 path = 'person' + '/' + str(self.id) + '/tv_credits'508 response = TMDB._request('GET', path, params)509 TMDB._set_attrs_to_values(self, response)510 return response511 # optional parameters: language512 def combined_credits(self, params={}):513 path = 'person' + '/' + str(self.id) + '/combined_credits'514 response = TMDB._request('GET', path, params)515 TMDB._set_attrs_to_values(self, response)516 return response517 def images(self):518 path = 'person' + '/' + str(self.id) + '/images'519 response = TMDB._request('GET', path)520 TMDB._set_attrs_to_values(self, response)521 return response522 # optional parameters: start_date, end_date523 def changes(self, params={}):524 path = 'person' + '/' + str(self.id) + '/changes'525 response = TMDB._request('GET', path, params)526 TMDB._set_attrs_to_values(self, response)527 return response528 # optional parameters: page529 def popular(self, params={}):530 path = 'person/popular'531 response = TMDB._request('GET', path, params)532 TMDB._set_attrs_to_values(self, response)533 return response534 def latest(self):535 path = 'person/latest'536 response = TMDB._request('GET', path)537 TMDB._set_attrs_to_values(self, response)538 return response539 #540 # Reviews541 # http://docs.themoviedb.apiary.io/#reviews542 #543 class Reviews:544 def __init__(self, id):545 self.id = id546 def info(self):547 path = 'review' + '/' + str(self.id)548 response = TMDB._request('GET', path)549 TMDB._set_attrs_to_values(self, response)550 return response551 #552 # Search553 # http://docs.themoviedb.apiary.io/#search554 #555 class Search:556 def __init__(self):557 pass558 # required parameters: query559 # optional parameters: page, language, include_adult, year, 560 # primary_release_year, search_type561 def movie(self, params):562 path = 'search/movie'563 response = TMDB._request('GET', path, params)564 TMDB._set_attrs_to_values(self, response)565 return response566 # required parameters: query567 # optional parameters: page, language568 def collection(self, params):569 path = 'search/collection'570 response = TMDB._request('GET', path, params)571 TMDB._set_attrs_to_values(self, response)572 return response573 # required parameters: query574 # optional parameters: page, language, first_air_date_year, search_type575 def tv(self, params):576 path = 'search/tv'577 response = TMDB._request('GET', path, params)578 TMDB._set_attrs_to_values(self, response)579 return response580 # required parameters: query581 # optional parameters: page, include_adult, search_type582 def person(self, params):583 path = 'search/person'584 response = TMDB._request('GET', path, params)585 TMDB._set_attrs_to_values(self, response)586 return response587 # required parameters: query588 # optional parameters: page, include_adult589 def list(self, params):590 path = 'search/list'591 response = TMDB._request('GET', path, params)592 TMDB._set_attrs_to_values(self, response)593 return response594 # required parameters: query595 # optional parameters: page596 def company(self, params):597 path = 'search/company'598 response = TMDB._request('GET', path, params)599 TMDB._set_attrs_to_values(self, response)600 return response601 # required parameters: query602 # optional parameters: page603 def keyword(self, params):604 path = 'search/keyword'605 response = TMDB._request('GET', path, params)606 TMDB._set_attrs_to_values(self, response)607 return response608 #609 # TV610 # http://docs.themoviedb.apiary.io/#tv611 #612 class TV:613 def __init__(self, id=0):614 self.id = id615 # optional parameter: language616 def info(self, params={}):617 path = 'tv' + '/' + str(self.id)618 response = TMDB._request('GET', path, params)619 TMDB._set_attrs_to_values(self, response)620 return response621 622 # optional parameter: language623 def credits(self, params={}):624 path = 'tv' + '/' + str(self.id) + '/credits'625 response = TMDB._request('GET', path, params)626 TMDB._set_attrs_to_values(self, response)627 return response628 # optional parameter: language629 def external_ids(self, params={}):630 path = 'tv' + '/' + str(self.id) + '/external_ids'631 response = TMDB._request('GET', path, params)632 TMDB._set_attrs_to_values(self, response)633 return response634 # optional parameters: language, include_image_language635 def images(self, params={}):636 path = 'tv' + '/' + str(self.id) + '/images'637 response = TMDB._request('GET', path, params)638 TMDB._set_attrs_to_values(self, response)639 return response640 def translations(self):641 path = 'tv' + '/' + str(self.id) + '/translations'642 response = TMDB._request('GET', path)643 TMDB._set_attrs_to_values(self, response)644 return response645 # optional parameter: page, language646 def top_rated(self, params={}):647 path = 'tv/top_rated'648 response = TMDB._request('GET', path, params)649 TMDB._set_attrs_to_values(self, response)650 return response651 # optional parameter: page, language652 def popular(self, params={}):653 path = 'tv/popular'654 response = TMDB._request('GET', path, params)655 TMDB._set_attrs_to_values(self, response)656 return response657 #658 # TV Seasons659 # http://docs.themoviedb.apiary.io/#tvseasons660 #661 class TV_Seasons:662 def __init__(self, id, season_number):663 self.id = id664 self.season_number = season_number665 # optional parameter: language666 def info(self, params={}):667 path = 'tv' + '/' + str(self.id) + '/season' + \668 '/' + str(self.season_number)669 response = TMDB._request('GET', path, params)670 TMDB._set_attrs_to_values(self, response)671 return response672 def credits(self):673 path = 'tv' + '/' + str(self.id) + '/season' + \674 '/' + str(self.season_number) + '/credits'675 response = TMDB._request('GET', path)676 TMDB._set_attrs_to_values(self, response)677 return response678 # optional parameter: language679 def external_ids(self, params={}):680 path = 'tv' + '/' + str(self.id) + '/season' + \681 '/' + str(self.season_number) + '/external_ids'682 response = TMDB._request('GET', path, params)683 TMDB._set_attrs_to_values(self, response)684 return response685 # optional parameter: language686 def images(self, params={}):687 path = 'tv' + '/' + str(self.id) + '/season' + \688 '/' + str(self.season_number) + '/images'689 response = TMDB._request('GET', path, params)690 TMDB._set_attrs_to_values(self, response)691 return response692 #693 # TV Episodes694 # http://docs.themoviedb.apiary.io/#tvepisodes695 #696 class TV_Episodes:697 def __init__(self, id, season_number, episode_number):698 self.id = id699 self.season_number = season_number700 self.episode_number = episode_number701 # optional parameter: language702 def info(self, params={}):703 path = 'tv' + '/' + str(self.id) + '/season' + \704 '/' + str(self.season_number) + '/episode' + \705 '/' + str(self.episode_number)706 response = TMDB._request('GET', path, params)707 TMDB._set_attrs_to_values(self, response)708 return response709 def credits(self, params={}):710 path = 'tv' + '/' + str(self.id) + '/season' + \711 '/' + str(self.season_number) + '/episode' + \712 '/' + str(self.episode_number) + '/credits'713 response = TMDB._request('GET', path, params)714 TMDB._set_attrs_to_values(self, response)715 return response716 # optional parameter: language717 def external_ids(self, params={}):718 path = 'tv' + '/' + str(self.id) + '/season' + \719 '/' + str(self.season_number) + '/episode' + \720 '/' + str(self.episode_number) + '/external_ids'721 response = TMDB._request('GET', path, params)722 TMDB._set_attrs_to_values(self, response)723 return response724 # optional parameter: language725 def images(self, params={}):726 path = 'tv' + '/' + str(self.id) + '/season' + \727 '/' + str(self.season_number) + '/episode' + \728 '/' + str(self.episode_number) + '/images'729 response = TMDB._request('GET', path, params)730 TMDB._set_attrs_to_values(self, response)...

Full Screen

Full Screen

request.py

Source:request.py Github

copy

Full Screen

1#!/usr/bin/env python2#==============================================================================3# Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.4#5# Licensed under the Amazon Software License (the "License"). You may not use6# this file except in compliance with the License. A copy of the License is7# located at8#9# http://aws.amazon.com/asl/10#11# or in the "license" file accompanying this file. This file is distributed on12# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or13# implied. See the License for the specific language governing permissions14# and limitations under the License.15#==============================================================================16from lib.utility import misc17class TemplateSnippet(object):18 19 def __init__(self, snippet_name = None, source_url = None, order = None):20 self._snippet_name = snippet_name21 self._source_url = source_url22 self._order = order23 @property24 def snippet_name(self):25 return self._snippet_name26 @property27 def source_url(self):28 return self._source_url29 @property30 def order(self):31 return self._order32 33 @snippet_name.setter 34 def snippet_name(self, snippet_name):35 self._snippet_name = snippet_name36 37 @source_url.setter 38 def source_url(self, source_url):39 self._source_url = source_url40 41 @order.setter 42 def order(self, order):43 self._order = order44 45class Version(object):46 def __init__(self, application_name = None, version_label = None):47 self._application_name = application_name48 self._version_label = version_label49 50 @property51 def application_name(self):52 return self._application_name53 @property54 def version_label(self):55 return self._version_label56 57 @application_name.setter 58 def application_name(self, application_name):59 self._application_name = application_name60 61 @version_label.setter 62 def version_label(self, version_label):63 self._version_label = version_label64class TemplateSpecification(object):65 def __init__(self, template_source = None, template_snippets = None):66 if template_source is None:67 self._template_source = TemplateSource()68 else:69 self._template_source = template_source70 if template_snippets is None:71 self._template_snippets = list()72 else:73 self._template_snippets = template_snippets74 75 @property76 def template_source(self):77 return self._template_source78 @property79 def template_snippets(self):80 return self._template_snippets81 82 @template_source.setter 83 def template_source(self, template_source):84 self._template_source = template_source85 @template_snippets.setter 86 def template_snippets(self, snippets):87 self._template_snippets = snippets88 89class TemplateSource(object):90 def __init__(self, solution_stack_name = None):91 self._solution_stack_name = solution_stack_name92 93 @property94 def solution_stack_name(self):95 return self._solution_stack_name96 97 @solution_stack_name.setter 98 def solution_stack_name(self, solution_stack_name):99 self._solution_stack_name = solution_stack_name100 101class Request(object):102 '''103 Convert and store EB request parameters104 '''105 106 def __init__(self):107 self._request = dict()108 def _set_to_list(self, name_set):109 name_list = []110 if isinstance(name_set, set):111 for name in name_set:112 name_list.append(unicode(name))113 else:114 name_list.append(unicode(name_set))115 return name_list 116 def _check_boolean(self, switch):117 if isinstance(switch, bool):118 if switch:119 return u'true'120 else:121 return u'false'122 else:123 return switch124 125 def __repr__(self):126 try:127 text = u'Request API: {0}. \nParameters: [\n'.format(self._request[u'Operation'])128 except:129 text = u'Parameters:[\n'130 131 for key,value in self._request.iteritems():132 text = text + u' {0} : {1}\n'.format(key, value)133 text = text + u']'134 135 return text136 137 def get_dict(self):138 return self._request139 140 def set_operation(self, name):141 self._request[u'Operation'] = misc.to_unicode(name)142 def set_app_name(self, name):143 self._request[u'ApplicationName'] = misc.to_unicode(name)144 def set_app_names(self, name_set):145 name_list = self._set_to_list(name_set)146 for i in range(len(name_list)):147 self._request[u'ApplicationNames.member.' + misc.to_unicode(i + 1)] \148 = misc.to_unicode(name_list[i])149 150 def set_version_label(self, name):151 self._request[u'VersionLabel'] = misc.to_unicode(name)152 153 def set_description(self, description):154 self._request[u'Description'] = misc.to_unicode(description)155 def set_s3bucket(self, bucket):156 self._request[u'SourceBundle.S3Bucket'] = misc.to_unicode(bucket)157 def set_s3key(self, key):158 self._request[u'SourceBundle.S3Key'] = misc.to_unicode(key)159 def set_auto_create_app(self, switch):160 switch = self._check_boolean(switch)161 self._request[u'AutoCreateApplication'] = misc.to_unicode(switch)162 def set_env_name(self, name):163 self._request[u'EnvironmentName'] = misc.to_unicode(name)164 def set_env_id(self, env_id):165 self._request[u'EnvironmentId'] = misc.to_unicode(env_id)166 167 def set_env_names(self, name_set):168 name_list = self._set_to_list(name_set)169 for i in range(len(name_list)):170 self._request[u'EnvironmentNames.member.' + misc.to_unicode(i + 1)] \171 = misc.to_unicode(name_list[i])172 def set_env_ids(self, id_set):173 id_list = self._set_to_list(id_set)174 for i in range(len(id_list)):175 self._request[u'EnvironmentIds.member.' + misc.to_unicode(i + 1)] \176 = misc.to_unicode(id_list[i]) 177 def set_cname(self, name):178 self._request[u'CNAMEPrefix'] = misc.to_unicode(name)179 180 def set_source_configuration(self, name):181 self._request[u'SourceConfiguration'] = misc.to_unicode(name)182 183 def set_template(self, name):184 self._request[u'TemplateName'] = misc.to_unicode(name)185 186 def set_solution_stack(self, name):187 self._request[u'SolutionStackName'] = misc.to_unicode(name)188 def set_options(self, options_to_describe):189 index = 1190 for namespace, options in options_to_describe.iteritems():191 for option_name in options:192 self._request[u'Options.member.' + misc.to_unicode(index) + u'.Namespace'] \193 = misc.to_unicode(namespace)194 self._request[u'Options.member.' + misc.to_unicode(index) + u'.OptionName'] \195 = misc.to_unicode(option_name)196 index = index + 1197 def set_option_settings(self, option_settings):198 index = 1199 for namespace, options in option_settings.iteritems():200 for option_name, value in options.iteritems():201 self._request[u'OptionSettings.member.' + misc.to_unicode(index) + u'.Namespace'] \202 = misc.to_unicode(namespace)203 self._request[u'OptionSettings.member.' + misc.to_unicode(index) + u'.OptionName'] \204 = misc.to_unicode(option_name)205 self._request[u'OptionSettings.member.' + misc.to_unicode(index) + u'.Value'] \206 = misc.to_unicode(value)207 index = index + 1208 def set_options_to_remove(self, options_to_remove):209 index = 1210 for namespace, options in options_to_remove.iteritems():211 for option_name in options:212 self._request[u'OptionsToRemove.member.' + misc.to_unicode(index) + u'.Namespace'] \213 = misc.to_unicode(namespace)214 self._request[u'OptionsToRemove.member.' + misc.to_unicode(index) + u'.OptionName'] \215 = misc.to_unicode(option_name)216 index = index + 1217 def set_include_deleted(self, switch):218 switch = self._check_boolean(switch)219 self._request[u'IncludeDeleted'] = misc.to_unicode(switch)220 def set_included_deleted_backto(self, datetime):221 self._request[u'IncludedDeletedBackTo'] = misc.to_unicode(datetime)222 def set_start_time(self, datetime):223 self._request[u'StartTime'] = misc.to_unicode(datetime)224 def set_end_time(self, datetime):225 self._request[u'EndTime'] = misc.to_unicode(datetime)226 227 def set_max_records(self, num):228 self._request[u'MaxRecords'] = misc.to_unicode(num)229 230 def set_next_token(self, token):231 self._request[u'NextToken'] = misc.to_unicode(token)232 def set_requst_id(self, request_id):233 self._request[u'RequestId'] = misc.to_unicode(request_id)234 def set_severity(self, severity):235 self._request[u'Severity'] = misc.to_unicode(severity)236 237 def set_terminate_env(self, switch):238 self._request[u'TerminateEnvByForce'] = misc.to_unicode(switch)239 def set_delete_source_bundle(self, switch):240 self._request[u'DeleteSourceBundle'] = misc.to_unicode(switch)241 242 def set_terminate_resources(self, switch):243 self._request[u'TerminateResources'] = misc.to_unicode(switch)244 def set_template_specification(self, template_spec):245 #TemplateSource246 if template_spec.template_source is not None:247 ts = template_spec.template_source 248 if ts.solution_stack_name is not None:249 self._request[u'TemplateSpecification.TemplateSource.SolutionStackName'] \250 = misc.to_unicode(ts.solution_stack_name)251 252 #Snippets253 if template_spec.template_snippets is not None:254 for i, snippet in enumerate(template_spec.template_snippets):255 if snippet.snippet_name is not None:256 self._request[u'TemplateSpecification.TemplateSnippets.member.' \257 + misc.to_unicode(i + 1)+u'.SnippetName'] \258 = misc.to_unicode(snippet.snippet_name)259 if snippet.source_url is not None:260 self._request[u'TemplateSpecification.TemplateSnippets.member.' \261 + misc.to_unicode(i + 1)+u'.SourceUrl'] \262 = misc.to_unicode(snippet.source_url)263 if snippet.order is not None:264 self._request[u'TemplateSpecification.TemplateSnippets.member.' \265 + misc.to_unicode(i + 1)+u'.Order'] \266 = misc.to_unicode(snippet.order)267 268 def set_tier(self, environment_tier):269 self._request[u'Tier.Name'] = misc.to_unicode(environment_tier.name)270 self._request[u'Tier.Type'] = misc.to_unicode(environment_tier.type)271 self._request[u'Tier.Version'] = misc.to_unicode(environment_tier.version)272 273 def set_info_type(self, info_type):274 self._request[u'InfoType'] = misc.to_unicode(info_type)275 276class Response(object):277 278 def __init__(self, request_id, result = None, next_token = None):279 self._request_id = request_id280 self._result = result281 self._next_token = next_token282 283 def __repr__(self):284 return u'API Response.\n Request ID: {0}\n Results: {1}'.\285 format(self.request_id, misc.collection_to_string(self._result))286 287 @property288 def request_id(self):289 return self._request_id290 291 @property292 def result(self):293 return self._result294 295 @property296 def next_token(self):297 return self._next_token...

Full Screen

Full Screen

ystockquote.py

Source:ystockquote.py Github

copy

Full Screen

...19except ImportError:20 # py221 from urllib2 import Request, urlopen22 from urllib import urlencode23def _request(symbol, stat):24 url = 'http://finance.yahoo.com/d/quotes.csv?s=%s&f=%s' % (symbol, stat)25 req = Request(url)26 resp = urlopen(req)27 content = resp.read().decode().strip()28 return content29def get_all(symbol):30 """31 Get all available quote data for the given ticker symbol.32 Returns a dictionary.33 """34 ids = \35 'ydb2r1b3qpoc1d1cd2c6t1k2p2c8m5c3m6gm7hm8k1m3lm4l1t8w1g1w4g3p' \36 '1g4mg5m2g6kvjj1j5j3k4f6j6nk5n4ws1xj2va5b6k3t7a2t615l2el3e7v1' \37 'e8v7e9s6b4j4p5p6rr2r5r6r7s7'38 values = _request(symbol, ids).split(',')39 return dict(40 dividend_yield=values[0],41 dividend_per_share=values[1],42 ask_realtime=values[2],43 dividend_pay_date=values[3],44 bid_realtime=values[4],45 ex_dividend_date=values[5],46 previous_close=values[6],47 today_open=values[7],48 change=values[8],49 last_trade_date=values[9],50 change_percent_change=values[10],51 trade_date=values[11],52 change_realtime=values[12],53 last_trade_time=values[13],54 change_percent_realtime=values[14],55 change_percent=values[15],56 after_hours_change_realtime=values[16],57 change_200_sma=values[17],58 todays_low=values[18],59 change_50_sma=values[19],60 todays_high=values[20],61 percent_change_50_sma=values[21],62 last_trade_realtime_time=values[22],63 fifty_sma=values[23],64 last_trade_time_plus=values[24],65 twohundred_sma=values[25],66 last_trade_price=values[26],67 one_year_target=values[27],68 todays_value_change=values[28],69 holdings_gain_percent=values[29],70 todays_value_change_realtime=values[30],71 annualized_gain=values[31],72 price_paid=values[32],73 holdings_gain=values[33],74 todays_range=values[34],75 holdings_gain_percent_realtime=values[35],76 todays_range_realtime=values[36],77 holdings_gain_realtime=values[37],78 fiftytwo_week_high=values[38],79 more_info=values[39],80 fiftytwo_week_low=values[40],81 market_cap=values[41],82 change_from_52_week_low=values[42],83 market_cap_realtime=values[43],84 change_from_52_week_high=values[44],85 float_shares=values[45],86 percent_change_from_52_week_low=values[46],87 company_name=values[47],88 percent_change_from_52_week_high=values[48],89 notes=values[49],90 fiftytwo_week_range=values[50],91 shares_owned=values[51],92 stock_exchange=values[52],93 shares_outstanding=values[53],94 volume=values[54],95 ask_size=values[55],96 bid_size=values[56],97 last_trade_size=values[57],98 ticker_trend=values[58],99 average_daily_volume=values[59],100 trade_links=values[60],101 order_book_realtime=values[61],102 high_limit=values[62],103 eps=values[63],104 low_limit=values[64],105 eps_estimate_current_year=values[65],106 holdings_value=values[66],107 eps_estimate_next_year=values[67],108 holdings_value_realtime=values[68],109 eps_estimate_next_quarter=values[69],110 revenue=values[70],111 book_value=values[71],112 ebitda=values[72],113 price_sales=values[73],114 price_book=values[74],115 pe=values[75],116 pe_realtime=values[76],117 peg=values[77],118 price_eps_estimate_current_year=values[78],119 price_eps_estimate_next_year=values[79],120 short_ratio=values[80],121 )122def get_dividend_yield(symbol):123 return _request(symbol, 'y')124def get_dividend_per_share(symbol):125 return _request(symbol, 'd')126def get_ask_realtime(symbol):127 return _request(symbol, 'b2')128def get_dividend_pay_date(symbol):129 return _request(symbol, 'r1')130def get_bid_realtime(symbol):131 return _request(symbol, 'b3')132def get_ex_dividend_date(symbol):133 return _request(symbol, 'q')134def get_previous_close(symbol):135 return _request(symbol, 'p')136def get_today_open(symbol):137 return _request(symbol, 'o')138def get_change(symbol):139 return _request(symbol, 'c1')140def get_last_trade_date(symbol):141 return _request(symbol, 'd1')142def get_change_percent_change(symbol):143 return _request(symbol, 'c')144def get_trade_date(symbol):145 return _request(symbol, 'd2')146def get_change_realtime(symbol):147 return _request(symbol, 'c6')148def get_last_trade_time(symbol):149 return _request(symbol, 't1')150def get_change_percent_realtime(symbol):151 return _request(symbol, 'k2')152def get_change_percent(symbol):153 return _request(symbol, 'p2')154def get_after_hours_change(symbol):155 return _request(symbol, 'c8')156def get_change_200_sma(symbol):157 return _request(symbol, 'm5')158def get_commission(symbol):159 return _request(symbol, 'c3')160def get_percent_change_200_sma(symbol):161 return _request(symbol, 'm6')162def get_todays_low(symbol):163 return _request(symbol, 'g')164def get_change_50_sma(symbol):165 return _request(symbol, 'm7')166def get_todays_high(symbol):167 return _request(symbol, 'h')168def get_percent_change_50_sma(symbol):169 return _request(symbol, 'm8')170def get_last_trade_realtime_time(symbol):171 return _request(symbol, 'k1')172def get_50_sma(symbol):173 return _request(symbol, 'm3')174def get_last_trade_time_plus(symbol):175 return _request(symbol, 'l')176def get_200_sma(symbol):177 return _request(symbol, 'm4')178def get_last_trade_price(symbol):179 return _request(symbol, 'l1')180def get_1_year_target(symbol):181 return _request(symbol, 't8')182def get_todays_value_change(symbol):183 return _request(symbol, 'w1')184def get_holdings_gain_percent(symbol):185 return _request(symbol, 'g1')186def get_todays_value_change_realtime(symbol):187 return _request(symbol, 'w4')188def get_annualized_gain(symbol):189 return _request(symbol, 'g3')190def get_price_paid(symbol):191 return _request(symbol, 'p1')192def get_holdings_gain(symbol):193 return _request(symbol, 'g4')194def get_todays_range(symbol):195 return _request(symbol, 'm')196def get_holdings_gain_percent_realtime(symbol):197 return _request(symbol, 'g5')198def get_todays_range_realtime(symbol):199 return _request(symbol, 'm2')200def get_holdings_gain_realtime(symbol):201 return _request(symbol, 'g6')202def get_52_week_high(symbol):203 return _request(symbol, 'k')204def get_more_info(symbol):205 return _request(symbol, 'v')206def get_52_week_low(symbol):207 return _request(symbol, 'j')208def get_market_cap(symbol):209 return _request(symbol, 'j1')210def get_change_from_52_week_low(symbol):211 return _request(symbol, 'j5')212def get_market_cap_realtime(symbol):213 return _request(symbol, 'j3')214def get_change_from_52_week_high(symbol):215 return _request(symbol, 'k4')216def get_float_shares(symbol):217 return _request(symbol, 'f6')218def get_percent_change_from_52_week_low(symbol):219 return _request(symbol, 'j6')220def get_company_name(symbol):221 return _request(symbol, 'n')222def get_percent_change_from_52_week_high(symbol):223 return _request(symbol, 'k5')224def get_notes(symbol):225 return _request(symbol, 'n4')226def get_52_week_range(symbol):227 return _request(symbol, 'w')228def get_shares_owned(symbol):229 return _request(symbol, 's1')230def get_stock_exchange(symbol):231 return _request(symbol, 'x')232def get_shares_outstanding(symbol):233 return _request(symbol, 'j2')234def get_volume(symbol):235 return _request(symbol, 'v')236def get_ask_size(symbol):237 return _request(symbol, 'a5')238def get_bid_size(symbol):239 return _request(symbol, 'b6')240def get_last_trade_size(symbol):241 return _request(symbol, 'k3')242def get_ticker_trend(symbol):243 return _request(symbol, 't7')244def get_average_daily_volume(symbol):245 return _request(symbol, 'a2')246def get_trade_links(symbol):247 return _request(symbol, 't6')248def get_order_book_realtime(symbol):249 return _request(symbol, 'i5')250def get_high_limit(symbol):251 return _request(symbol, 'l2')252def get_eps(symbol):253 return _request(symbol, 'e')254def get_low_limit(symbol):255 return _request(symbol, 'l3')256def get_eps_estimate_current_year(symbol):257 return _request(symbol, 'e7')258def get_holdings_value(symbol):259 return _request(symbol, 'v1')260def get_eps_estimate_next_year(symbol):261 return _request(symbol, 'e8')262def get_holdings_value_realtime(symbol):263 return _request(symbol, 'v7')264def get_eps_estimate_next_quarter(symbol):265 return _request(symbol, 'e9')266def get_revenue(symbol):267 return _request(symbol, 's6')268def get_book_value(symbol):269 return _request(symbol, 'b4')270def get_ebitda(symbol):271 return _request(symbol, 'j4')272def get_price_sales(symbol):273 return _request(symbol, 'p5')274def get_price_book(symbol):275 return _request(symbol, 'p6')276def get_pe(symbol):277 return _request(symbol, 'r')278def get_pe_realtime(symbol):279 return _request(symbol, 'r2')280def get_peg(symbol):281 return _request(symbol, 'r5')282def get_price_eps_estimate_current_year(symbol):283 return _request(symbol, 'r6')284def get_price_eps_estimate_next_year(symbol):285 return _request(symbol, 'r7')286def get_short_ratio(symbol):287 return _request(symbol, 's7')288def get_historical_prices(symbol, start_date, end_date):289 """290 Get historical prices for the given ticker symbol.291 Date format is 'YYYY-MM-DD'292 Returns a nested dictionary (dict of dicts).293 outer dict keys are dates ('YYYY-MM-DD')294 """295 params = urlencode({296 's': symbol,297 'a': int(start_date[5:7]) - 1,298 'b': int(start_date[8:10]),299 'c': int(start_date[0:4]),300 'd': int(end_date[5:7]) - 1,301 'e': int(end_date[8:10]),...

Full Screen

Full Screen

request_test.py

Source:request_test.py Github

copy

Full Screen

1# Copyright 2017 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import httplib5import socket6import unittest7import mock8from google.appengine.api import urlfetch_errors9from google.appengine.ext import testbed10from dashboard.common import utils11from dashboard.services import request12class _RequestTest(unittest.TestCase):13 def setUp(self):14 self.testbed = testbed.Testbed()15 self.testbed.activate()16 self.testbed.init_memcache_stub()17 http = mock.MagicMock()18 self._request = http.request19 patcher = mock.patch('dashboard.common.utils.ServiceAccountHttp')20 self._service_account_http = patcher.start()21 self._service_account_http.return_value = http22 self.addCleanup(patcher.stop)23class SuccessTest(_RequestTest):24 def testRequest(self):25 self._request.return_value = ({'status': '200'}, 'response')26 response = request.Request('https://example.com')27 self._service_account_http.assert_called_once_with(28 scope=utils.EMAIL_SCOPE, timeout=30)29 self._request.assert_called_once_with('https://example.com', method='GET')30 self.assertEqual(response, 'response')31 def testRequestJson(self):32 self._request.return_value = ({'status': '200'}, '"response"')33 response = request.RequestJson('https://example.com')34 self._request.assert_called_once_with('https://example.com', method='GET')35 self.assertEqual(response, 'response')36 def testRequestJsonWithPrefix(self):37 self._request.return_value = ({'status': '200'}, ')]}\'\n"response"')38 response = request.RequestJson('https://example.com')39 self._request.assert_called_once_with('https://example.com', method='GET')40 self.assertEqual(response, 'response')41 def testRequestWithBodyAndParameters(self):42 self._request.return_value = ({'status': '200'}, 'response')43 response = request.Request('https://example.com', 'POST', body='a string',44 url_param_1='value_1', url_param_2='value_2')45 self._request.assert_called_once_with(46 'https://example.com?url_param_1=value_1&url_param_2=value_2',47 method='POST', body='"a string"',48 headers={'Content-Type': 'application/json'})49 self.assertEqual(response, 'response')50class FailureAndRetryTest(_RequestTest):51 def _TestRetry(self):52 response = request.Request('https://example.com')53 self._request.assert_called_with('https://example.com', method='GET')54 self.assertEqual(self._request.call_count, 2)55 self.assertEqual(response, 'response')56 def testHttpErrorCode(self):57 self._request.return_value = ({'status': '500'}, '')58 with self.assertRaises(httplib.HTTPException):59 request.Request('https://example.com')60 self._request.assert_called_with('https://example.com', method='GET')61 self.assertEqual(self._request.call_count, 2)62 def testHttpException(self):63 self._request.side_effect = httplib.HTTPException64 with self.assertRaises(httplib.HTTPException):65 request.Request('https://example.com')66 self._request.assert_called_with('https://example.com', method='GET')67 self.assertEqual(self._request.call_count, 2)68 def testSocketError(self):69 self._request.side_effect = socket.error70 with self.assertRaises(socket.error):71 request.Request('https://example.com')72 self._request.assert_called_with('https://example.com', method='GET')73 self.assertEqual(self._request.call_count, 2)74 def testInternalTransientError(self):75 self._request.side_effect = urlfetch_errors.InternalTransientError76 with self.assertRaises(urlfetch_errors.InternalTransientError):77 request.Request('https://example.com')78 self._request.assert_called_with('https://example.com', method='GET')79 self.assertEqual(self._request.call_count, 2)80 def testNotFound(self):81 self._request.return_value = ({'status': '404'}, '')82 with self.assertRaises(request.NotFoundError):83 request.Request('https://example.com')84 self._request.assert_called_with('https://example.com', method='GET')85 self.assertEqual(self._request.call_count, 1)86 def testHttpErrorCodeSuccessOnRetry(self):87 failure_return_value = ({'status': '500'}, '')88 success_return_value = ({'status': '200'}, 'response')89 self._request.side_effect = failure_return_value, success_return_value90 self._TestRetry()91 def testHttpExceptionSuccessOnRetry(self):92 return_value = ({'status': '200'}, 'response')93 self._request.side_effect = httplib.HTTPException, return_value94 self._TestRetry()95 def testSocketErrorSuccessOnRetry(self):96 return_value = ({'status': '200'}, 'response')97 self._request.side_effect = socket.error, return_value98 self._TestRetry()99class CacheTest(_RequestTest):100 def testSetAndGet(self):101 self._request.return_value = ({'status': '200'}, 'response')102 response = request.Request('https://example.com', use_cache=True)103 self.assertEqual(response, 'response')104 self.assertEqual(self._request.call_count, 1)105 response = request.Request('https://example.com', use_cache=True)106 self.assertEqual(response, 'response')107 self.assertEqual(self._request.call_count, 1)108 def testRequestBody(self):109 self._request.return_value = ({'status': '200'}, 'response')110 with self.assertRaises(NotImplementedError):111 request.Request('https://example.com', body='body', use_cache=True)112 @mock.patch.object(request.memcache, 'add',113 mock.MagicMock(side_effect=ValueError))114 def testResponseTooLarge(self):115 self._request.return_value = ({'status': '200'}, 'response')116 response = request.Request('https://example.com', use_cache=True)117 self.assertEqual(response, 'response')118 self.assertEqual(self._request.call_count, 1)119 response = request.Request('https://example.com', use_cache=True)120 self.assertEqual(response, 'response')121 self.assertEqual(self._request.call_count, 2)122class AuthTest(_RequestTest):123 def testNoAuth(self):124 http = mock.MagicMock()125 patcher = mock.patch('httplib2.Http')126 httplib2_http = patcher.start()127 httplib2_http.return_value = http128 self.addCleanup(patcher.stop)129 http.request.return_value = ({'status': '200'}, 'response')130 response = request.Request('https://example.com', use_auth=False)131 httplib2_http.assert_called_once_with(timeout=30)132 http.request.assert_called_once_with('https://example.com', method='GET')133 self.assertEqual(self._request.call_count, 0)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Molotov automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful