Best Python code snippet using autotest_python
api.py
Source:api.py
...5 self.__server = server6 self.__client = HttpClient(server, {'Content-type': 'application/json'})7 self.__client.authorize_bearer('token', login, password)8 def get_mine(self, date):9 return self.__get_items('api/references/mine/{0}'10 .format(date))11 def get_shaft(self, date, mine_id):12 return self.__get_items('api/references/shaft/{0}/{1}'13 .format(date, mine_id))14 def get_section(self, date, mine_id, shaft_id):15 return self.__get_items('api/references/section/{0}/{1}/{2}'16 .format(date, mine_id, shaft_id))17 def get_orepass(self, date, mine_id):18 return self.__get_items('api/references/orepass/{0}/{1}'19 .format(date, mine_id))20 def get_skip(self, date, mine_id):21 return self.__get_items('api/references/skip/{0}/{1}'22 .format(date, mine_id))23 def get_location(self, date, mine_id):24 return self.__get_items('api/references/location/{0}/{1}'25 .format(date, mine_id))26 def get_location_kind(self, date):27 return self.__get_items('api/references/locationkind/{0}'28 .format(date))29 def get_development_type(self, date):30 return self.__get_items('api/references/developmenttype/{0}'31 .format(date))32 def get_equipment_category(self, date):33 return self.__get_items('api/references/equipmentcategory/{0}'34 .format(date))35 def get_equipment_type(self, date, equipment_category_id='Null'):36 return self.__get_items('api/references/equipmenttype/{0}/{1}'37 .format(date, equipment_category_id))38 def get_equipment(self, date, mine_id, equipment_type_id='Null'):39 return self.__get_items('api/references/equipment/{0}/{1}/{2}'40 .format(date, mine_id, equipment_type_id))41 def get_operator(self, date, mine_id):42 return self.__get_items('api/references/operator/{0}/{1}'43 .format(date, mine_id))44 def get_material(self, date, material_kind='Null'):45 return self.__get_items('api/references/material/{0}/{1}'46 .format(date, material_kind))47 def get_material_kind(self, date):48 return self.__get_items('api/references/materialkind'49 .format(date))50 def get_job_kind(self, date, mine_id, job_category_id='Null'):51 return self.__get_items('api/references/jobkind/{0}/{1}/{2}'52 .format(date, mine_id, job_category_id))53 def get_priority(self, date, mine_id, shift):54 return self.__get_items('api/references/priority/{0}/{1}/{2}'.format(date, mine_id, shift),55 root='priorityCollection')56 def get_unit(self, date):57 return self.__get_items('api/references/unit/{0}'.format(date))58 def get_work_order(self, date, mine_id, shaft_id, section_id, shift):59 orders = self.__get_items('api/workorder/{0}/{1}/{2}/{3}/{4}'.format(date, mine_id, shaft_id, section_id, shift))60 orders_list = list()61 if len(orders) > 0:62 for order in orders:63 orders_list = orders_list + order.body64 return orders_list65 def get_locomotive_order(self, date, shift, mine_id):66 return self.__get_items('api/locomotiveorder/{0}/{1}/{2}'.format(date, shift, mine_id))67 def get_skip_order(self, date, shift, mine_id):68 return self.__get_items('api/skiporder/{0}/{1}/{2}'.format(date, shift, mine_id))69 def __get_items(self, uri, root='data'):70 response = self.__client.get(uri)71 items = getattr(Dynamic(response), root)72 if items is None:73 items = list()74 return items75class KsipApi:76 def __init__(self, server, login, password):77 self.__server = server78 self.__client = HttpClient(server, headers={'Content-type': 'application/json'})79 self.__client.authorize_basic(login, password)80 def get_sdo_fact(self, uri, date, shift, mine, shaft, section):81 return self.__get_items('{0}/{1}/{2}/{3}/{4}/{5}'.format(uri, date, shift, mine, shaft, section))82 def get_skip_fact(self, uri, date, shift, mine):83 response = self.__get_items('{0}/{1}/{2}/{3}'.format(uri, date, shift, mine), root='facts')84 return response85 def get_ore_pass_fact(self, uri, date, shift, mine):86 response = self.__get_items('{0}/{1}/{2}/{3}'.format(uri, date, shift, mine), root='facts')87 return response88 def __get_items(self, uri, root='data'):89 response = self.__client.get(uri)90 items = getattr(Dynamic(response), root, list())91 if items is None:92 items = list()...
collections.py
Source:collections.py
1import typing as _typing2from returns import (3 returns as _returns,4)5from .each import (6 BaseOneToOneFunction as _BaseOneToOneFunction,7)8def yield_from(iterable: _typing.Iterable[_typing.Iterable]) -> _typing.Iterator:9 """10 Unpack a series of iterables into one iterable.11 """12 for item in iterable:13 yield from item14Collection = _typing.Union[_typing.Sequence, _typing.Mapping]15class GetItem(_BaseOneToOneFunction[Collection, _typing.Any]):16 def __init__(17 self,18 index,19 *,20 none: bool = False,21 ):22 """23 :param none:24 If False (default), collections without index result in IndexError or KeyError;25 If True, fill with None instead.26 """27 self.__index = index28 self.__none = none29 @property30 def index(self):31 return self.__index32 @property33 def none(self) -> bool:34 return self.__none35 def each(self, item: Collection) -> _typing.Any:36 try:37 return item[self.index]38 except (IndexError, KeyError):39 if not self.none:40 raise41 return None42class GetItems(_BaseOneToOneFunction[Collection, _typing.Tuple]):43 def __init__(44 self,45 *indexes,46 **kwargs,47 ):48 """49 :param kwargs: See GetItem50 """51 self.__get_items = [52 GetItem(index, **kwargs)53 for index in indexes54 ]55 @_returns(tuple)56 def each(self, item: Collection) -> _typing.Tuple:57 for get_item in self.__get_items: # type: GetItem58 yield get_item.each(item)59class ToDict(_BaseOneToOneFunction[_typing.Sequence, _typing.Dict]):60 def __init__(61 self,62 *keys,63 **kwargs,64 ):65 """66 :param kwargs: See GetItem67 """68 self.__get_items = [69 (key, GetItem(i, **kwargs))70 for i, key in enumerate(keys)71 ]72 @_returns(dict)73 def each(self, item: _typing.Sequence) -> _typing.Dict:74 for key, get_item in self.__get_items: # type: _typing.Any, GetItem75 yield key, get_item.each(item)76class SelectKeys(_BaseOneToOneFunction[_typing.Mapping, _typing.Dict]):77 def __init__(78 self,79 *keys,80 **kwargs,81 ):82 """83 :param kwargs: See GetItem84 """85 self.__get_items = [86 GetItem(key, **kwargs)87 for key in keys88 ]89 @_returns(dict)90 def each(self, item: _typing.Sequence) -> _typing.Dict:91 for get_item in self.__get_items: # type: GetItem92 yield get_item.index, get_item.each(item)93class ApplyOnKeys(_BaseOneToOneFunction[_typing.Dict, _typing.Dict]):94 def __init__(95 self,96 func,97 *keys,98 copy: bool = False,99 none: bool = False,100 ):101 self.__func = func102 self.__keys = keys103 self.__copy = copy104 self.__none = none105 def each(self, item: _typing.Dict) -> _typing.Dict:106 if self.__copy:107 item = item.copy()108 keys = self.__keys or tuple(item)109 for k in keys:110 try:111 item[k] = self.__func(item[k])112 except Exception:113 if self.__none:114 item[k] = None115 else:116 raise117 return item118class ReplaceKeys(_BaseOneToOneFunction[_typing.Dict, _typing.Dict]):119 def __init__(120 self,121 replace: _typing.Dict,122 *,123 copy: bool = False,124 none: bool = False,125 ):126 self.__replace = replace127 self.__copy = copy128 self.__none = none129 def each(self, item: _typing.Dict) -> _typing.Dict:130 if self.__copy:131 item = item.copy()132 for k, v in self.__replace.items():133 try:134 item[v] = item.pop(k)135 except KeyError:136 if self.__none:137 item[v] = None138 else:139 raise...
spotify_service.py
Source:spotify_service.py
...5 def __init__(self, app_env):6 self.__initialize_spotify(app_env)7 def get_playlist_tracks(self, playlist_id):8 playlist_tracks = []9 items = self.__get_items(self.spotify.playlist_tracks(playlist_id), True)10 for item in items:11 track = item['track']12 album_name = track['album']['name']13 album_release_date = track['album']['release_date']14 artist = track['artists'][0]['name']15 song_name = track['name']16 playlist_tracks.append(f'{artist} - {song_name}; {album_name} ({album_release_date})')17 return playlist_tracks18 def get_playlists(self, playlist_name):19 playlists = []20 items = self.__get_items(self.spotify.current_user_playlists(), True)21 for item in items:22 playlists.append(item)23 if playlist_name is None:24 return list(map(lambda p: f"{p['name']} (Total tracks: {p['tracks']['total']})", playlists))25 matching_playlists = list(filter(lambda x: playlist_name.lower() in x['name'].lower(), playlists))26 if len(matching_playlists) == 0:27 return [f"Could not find any playlists matching {playlist_name}"]28 playlist_info = ""29 for matching_playlist in matching_playlists:30 playlist_info += f" Name: {matching_playlist['name']}\n"31 playlist_info += f" Id: {matching_playlist['id']}\n"32 playlist_info += f" Uri: {matching_playlist['uri']}\n"33 playlist_info += f"Total tracks: {matching_playlist['tracks']['total']}\n\n"34 return [playlist_info]35 def get_recently_played_tracks(self):36 recent_tracks = []37 items = self.__get_items(self.spotify.current_user_recently_played())38 for item in items:39 track = item['track']40 artist = track['artists'][0]['name']41 song_name = track['name']42 recent_tracks.append(f'{artist} - {song_name}')43 return recent_tracks44 def get_top_artists(self, range='medium_term'):45 top_artists = []46 items = self.__get_items(47 self.spotify.current_user_top_artists(time_range=range))48 for item in items:49 top_artists.append(item['name'])50 return top_artists51 def get_top_tracks(self, range='medium_term'):52 top_tracks = []53 items = self.__get_items(54 self.spotify.current_user_top_tracks(time_range=range))55 for item in items:56 artist = item['artists'][0]['name']57 song_name = item['name']58 top_tracks.append(f'{artist} - {song_name}')59 return top_tracks60 def __get_items(self, results, should_get_all_items=False):61 items = results['items']62 if not should_get_all_items:63 return items64 while results['next']:65 results = self.spotify.next(results)66 items.extend(results['items'])67 return items68 def __initialize_spotify(self, app_env):69 scope = ScopeBuilder().build()70 self.spotify = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=app_env.client_id,71 client_secret=app_env.client_secret,72 redirect_uri=app_env.redirect_uri,...
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!!