Best Python code snippet using tempest_python
client.py
Source:client.py
1#!/usr/bin/env python2#3# Copyright (C) 2009 Google Inc.4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16"""Contains a client to communicate with the Blogger servers.17For documentation on the Blogger API, see:18http://code.google.com/apis/blogger/19"""20__author__ = 'j.s@google.com (Jeff Scudder)'21import gdata.client22import gdata.gauth23import gdata.blogger.data24import atom.data25import atom.http_core26# List user's blogs, takes a user ID, or 'default'.27BLOGS_URL = 'http://www.blogger.com/feeds/%s/blogs'28# Takes a blog ID.29BLOG_POST_URL = 'http://www.blogger.com/feeds/%s/posts/default'30# Takes a blog ID.31BLOG_PAGE_URL = 'http://www.blogger.com/feeds/%s/pages/default'32# Takes a blog ID and post ID.33BLOG_POST_COMMENTS_URL = 'http://www.blogger.com/feeds/%s/%s/comments/default'34# Takes a blog ID.35BLOG_COMMENTS_URL = 'http://www.blogger.com/feeds/%s/comments/default'36# Takes a blog ID.37BLOG_ARCHIVE_URL = 'http://www.blogger.com/feeds/%s/archive/full'38class BloggerClient(gdata.client.GDClient):39 api_version = '2'40 auth_service = 'blogger'41 auth_scopes = gdata.gauth.AUTH_SCOPES['blogger']42 def get_blogs(self, user_id='default', auth_token=None,43 desired_class=gdata.blogger.data.BlogFeed, **kwargs):44 return self.get_feed(BLOGS_URL % user_id, auth_token=auth_token,45 desired_class=desired_class, **kwargs)46 GetBlogs = get_blogs47 def get_posts(self, blog_id, auth_token=None,48 desired_class=gdata.blogger.data.BlogPostFeed, query=None,49 **kwargs):50 return self.get_feed(BLOG_POST_URL % blog_id, auth_token=auth_token,51 desired_class=desired_class, query=query, **kwargs)52 GetPosts = get_posts53 def get_pages(self, blog_id, auth_token=None,54 desired_class=gdata.blogger.data.BlogPageFeed, query=None,55 **kwargs):56 return self.get_feed(BLOG_PAGE_URL % blog_id, auth_token=auth_token,57 desired_class=desired_class, query=query, **kwargs)58 GetPages = get_pages59 def get_post_comments(self, blog_id, post_id, auth_token=None,60 desired_class=gdata.blogger.data.CommentFeed,61 query=None, **kwargs):62 return self.get_feed(BLOG_POST_COMMENTS_URL % (blog_id, post_id),63 auth_token=auth_token, desired_class=desired_class,64 query=query, **kwargs)65 GetPostComments = get_post_comments66 def get_blog_comments(self, blog_id, auth_token=None,67 desired_class=gdata.blogger.data.CommentFeed,68 query=None, **kwargs):69 return self.get_feed(BLOG_COMMENTS_URL % blog_id, auth_token=auth_token,70 desired_class=desired_class, query=query, **kwargs)71 GetBlogComments = get_blog_comments72 def get_blog_archive(self, blog_id, auth_token=None, **kwargs):73 return self.get_feed(BLOG_ARCHIVE_URL % blog_id, auth_token=auth_token,74 **kwargs)75 GetBlogArchive = get_blog_archive76 def add_post(self, blog_id, title, body, labels=None, draft=False,77 auth_token=None, title_type='text', body_type='html', **kwargs):78 # Construct an atom Entry for the blog post to be sent to the server.79 new_entry = gdata.blogger.data.BlogPost(80 title=atom.data.Title(text=title, type=title_type),81 content=atom.data.Content(text=body, type=body_type))82 if labels:83 for label in labels:84 new_entry.add_label(label)85 if draft:86 new_entry.control = atom.data.Control(draft=atom.data.Draft(text='yes'))87 return self.post(new_entry, BLOG_POST_URL % blog_id, auth_token=auth_token, **kwargs)88 AddPost = add_post89 def add_page(self, blog_id, title, body, draft=False, auth_token=None,90 title_type='text', body_type='html', **kwargs):91 new_entry = gdata.blogger.data.BlogPage(92 title=atom.data.Title(text=title, type=title_type),93 content=atom.data.Content(text=body, type=body_type))94 if draft:95 new_entry.control = atom.data.Control(draft=atom.data.Draft(text='yes'))96 return self.post(new_entry, BLOG_PAGE_URL % blog_id, auth_token=auth_token, **kwargs)97 AddPage = add_page98 def add_comment(self, blog_id, post_id, body, auth_token=None,99 title_type='text', body_type='html', **kwargs):100 new_entry = gdata.blogger.data.Comment(101 content=atom.data.Content(text=body, type=body_type))102 return self.post(new_entry, BLOG_POST_COMMENTS_URL % (blog_id, post_id),103 auth_token=auth_token, **kwargs)104 AddComment = add_comment105 def update(self, entry, auth_token=None, **kwargs):106 # The Blogger API does not currently support ETags, so for now remove107 # the ETag before performing an update.108 old_etag = entry.etag109 entry.etag = None110 response = gdata.client.GDClient.update(self, entry,111 auth_token=auth_token, **kwargs)112 entry.etag = old_etag113 return response114 Update = update115 def delete(self, entry_or_uri, auth_token=None, **kwargs):116 if isinstance(entry_or_uri, (str, unicode, atom.http_core.Uri)):117 return gdata.client.GDClient.delete(self, entry_or_uri,118 auth_token=auth_token, **kwargs)119 # The Blogger API does not currently support ETags, so for now remove120 # the ETag before performing a delete.121 old_etag = entry_or_uri.etag122 entry_or_uri.etag = None123 response = gdata.client.GDClient.delete(self, entry_or_uri,124 auth_token=auth_token, **kwargs)125 # TODO: if GDClient.delete raises and exception, the entry's etag may be126 # left as None. Should revisit this logic.127 entry_or_uri.etag = old_etag128 return response129 Delete = delete130class Query(gdata.client.Query):131 def __init__(self, order_by=None, **kwargs):132 gdata.client.Query.__init__(self, **kwargs)133 self.order_by = order_by134 def modify_request(self, http_request):135 gdata.client._add_query_param('orderby', self.order_by, http_request)136 gdata.client.Query.modify_request(self, http_request)...
matchmakingHelper.py
Source:matchmakingHelper.py
1# -*- coding: utf-8 -*-2import endpoints3from protorpc import message_types4from firebaseService.firebaseService import Firebase5from helpers import firebaseHelper6def queue(request):7 if request.id is None or request.id == "":8 raise endpoints.BadRequestException('Por favor, inicia sesión para continuar.')9 auth_token = firebaseHelper.get_credentials()10 users = Firebase.get('/matchmaking/', auth_token)11 me = Firebase.get('/matchmaking/' + str(request.id), auth_token)12 if me is None:13 data = {'match': '0'}14 me = Firebase.patch('/matchmaking/' + request.id, data, auth_token)15 if users is not None:16 if me['match'] == '0':17 for user in users:18 if user != request.id and users[user]['match'] == '0': # 0 means is not in any game, but queueing19 data = {'player1': request.id, 'player2': user, 'player1_ready': False, 'player2_ready': False, 'status': 'SETTING'}20 game = Firebase.post('/games/', data, auth_token)21 patch_data = {'match': game['name']}22 Firebase.patch('/matchmaking/' + request.id, patch_data, auth_token)23 Firebase.patch('/matchmaking/' + str(user), patch_data, auth_token)24 break25 return message_types.VoidMessage()26def unqueue(request):27 auth_token = firebaseHelper.get_credentials()28 me = Firebase.get('/matchmaking/' + str(request.id), auth_token)29 if me is not None:30 if me['match'] != '0':31 raise endpoints.BadRequestException(u'Ya estás en partida.')32 Firebase.delete('/matchmaking/' + str(request.id), auth_token)33 return message_types.VoidMessage()34def requeue(request):35 auth_token = firebaseHelper.get_credentials()36 me = Firebase.get('/matchmaking/' + str(request.id), auth_token)37 if me is not None and me['match'] != '0':38 game = Firebase.get('/games/' + str(me['match']), auth_token)39 if game is not None:40 if game['player1'] == str(request.id):41 if game['player2'] == '0':42 Firebase.delete('/games/' + str(me['match']), auth_token)43 else:44 Firebase.patch('/games/' + str(me['match']), {'player1': '0'}, auth_token)45 if game['player2'] == str(request.id):46 if game['player1'] == '0':47 Firebase.delete('/games/' + str(me['match']), auth_token)48 else:49 Firebase.patch('/games/' + str(me['match']), {'player2': '0'}, auth_token)50 Firebase.patch('/matchmaking/' + str(request.id), {'match': '0'}, auth_token)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!