How to use __save_conf method in yandex-tank

Best Python code snippet using yandex-tank

fdapi.py

Source:fdapi.py Github

copy

Full Screen

...121 requests.post(url, headers=headers)122 finally:123 self.conf['token']['expires_in'] = 0124 self.conf['token']['refresh_token_expires_in'] = 0125 self.__save_conf()126 print("===")127 def login(self):128 if self.conf['client']['client_id'] == "" or \129 self.conf['client']['client_secret'] == "":130 self.__login_prerequisite()131 timestamp = int(time.time())132 if self.conf['token']['token_type'] == '' or \133 self.conf['token']['access_token'] == '' or \134 self.conf['token']['access_token'] == '' or \135 timestamp > self.conf['token']['refresh_token_expires_in']:136 self.__get_access_token()137 elif timestamp > self.conf['token']['expires_in']:138 self.__get_refresh_token()139 def __read_configuration(self):140 conf = {}141 try:142 conf = toml.load(self.path)143 except Exception as exception:144 print(exception)145 return conf146 def __login_prerequisite(self):147 base_url = self.conf['credentials']['base_url']148 url = f"{base_url}/oauth-clients/local"149 response = requests.get(url)150 if response.status_code == 200:151 self.conf['client'] = response.json()152 self.__save_conf()153 else:154 raise Exception155 def __get_access_token(self):156 client_id = self.conf['client']['client_id']157 client_secret = self.conf['client']['client_secret']158 base_url = self.conf['credentials']['base_url']159 username = self.conf['credentials']['username']160 password = self.conf['credentials']['password']161 url = f"{base_url}/users/token"162 data = {163 "client_id": client_id,164 "client_secret": client_secret,165 "grant_type": "password",166 "response_type": "code",167 "username": username,168 "password": password169 }170 response = requests.post(url, data=data)171 if response.status_code == 200:172 data = response.json()173 timestamp = int(time.time())174 data['expires_in'] += timestamp175 data['refresh_token_expires_in'] += timestamp176 self.conf['token'] = data177 self.__save_conf()178 else:179 raise Exception180 def __get_refresh_token(self):181 base_url = self.conf['credentials']['base_url']182 client_id = self.conf['client']['client_id']183 client_secret = self.conf['client']['client_secret']184 refresh_token = self.conf['token']['refresh_token']185 url = f"{base_url}/users/token"186 data = {187 "client_id": client_id,188 "client_secret": client_secret,189 "grant_type": "refresh_token",190 "refresh_token": refresh_token191 }192 response = requests.post(url, data=data)193 if response.status_code == 200:194 data = response.json()195 timestamp = int(time.time())196 data['expires_in'] += timestamp197 data['refresh_token_expires_in'] += timestamp198 self.conf['token'] = data199 self.__save_conf()200 else:201 print(response.status_code)202 self.conf['token']['refresh_token_expires_in'] = 0203 self.__save_conf()204 def __save_conf(self):205 with open(self.path, 'w') as file_writer:206 toml.dump(self.conf, file_writer)207if __name__ == '__main__':208 import os209 from dotenv import load_dotenv210 load_dotenv()211 pt_path = os.getenv("PT_PATH")212 peerTube = PeerTube(pt_path)213 print(peerTube.get_user_info())214 channel_id = os.getenv('PT_CHANNEL_ID')215 name = "test"216 filepath = "cap5.mp4"...

Full Screen

Full Screen

api.py

Source:api.py Github

copy

Full Screen

...115 requests.post(url, headers=headers)116 finally:117 self.conf['token']['expires_in'] = 0118 self.conf['token']['refresh_token_expires_in'] = 0119 self.__save_conf()120 print("===")121 def login(self):122 if self.conf['client']['client_id'] == "" or \123 self.conf['client']['client_secret'] == "":124 self.__login_prerequisite()125 timestamp = int(time.time())126 if self.conf['token']['token_type'] == '' or \127 self.conf['token']['access_token'] == '' or \128 self.conf['token']['access_token'] == '' or \129 timestamp > self.conf['token']['refresh_token_expires_in']:130 self.__get_access_token()131 elif timestamp > self.conf['token']['expires_in']:132 self.__get_refresh_token()133 def __read_configuration(self):134 conf = {}135 try:136 conf = toml.load(self.path)137 except Exception as exception:138 print(exception)139 return conf140 def __login_prerequisite(self):141 base_url = self.conf['credentials']['base_url']142 url = f"{base_url}/oauth-clients/local"143 response = requests.get(url)144 if response.status_code == 200:145 self.conf['client'] = response.json()146 self.__save_conf()147 else:148 raise Exception149 def __get_access_token(self):150 client_id = self.conf['client']['client_id']151 client_secret = self.conf['client']['client_secret']152 base_url = self.conf['credentials']['base_url']153 username = self.conf['credentials']['username']154 password = self.conf['credentials']['password']155 url = f"{base_url}/users/token"156 data = {157 "client_id": client_id,158 "client_secret": client_secret,159 "grant_type": "password",160 "response_type": "code",161 "username": username,162 "password": password163 }164 response = requests.post(url, data=data)165 if response.status_code == 200:166 data = response.json()167 timestamp = int(time.time())168 data['expires_in'] += timestamp169 data['refresh_token_expires_in'] += timestamp170 self.conf['token'] = data171 self.__save_conf()172 else:173 raise Exception174 def __get_refresh_token(self):175 base_url = self.conf['credentials']['base_url']176 client_id = self.conf['client']['client_id']177 client_secret = self.conf['client']['client_secret']178 refresh_token = self.conf['token']['refresh_token']179 url = f"{base_url}/users/token"180 data = {181 "client_id": client_id,182 "client_secret": client_secret,183 "grant_type": "refresh_token",184 "refresh_token": refresh_token185 }186 response = requests.post(url, data=data)187 if response.status_code == 200:188 data = response.json()189 timestamp = int(time.time())190 data['expires_in'] += timestamp191 data['refresh_token_expires_in'] += timestamp192 self.conf['token'] = data193 self.__save_conf()194 else:195 print(response.status_code)196 self.conf['token']['refresh_token_expires_in'] = 0197 self.__save_conf()198 def __save_conf(self):199 with open(self.path, 'w') as file_writer:200 toml.dump(self.conf, file_writer)201if __name__ == '__main__':202 import os203 from dotenv import load_dotenv204 load_dotenv()205 pt_path = os.getenv("PT_PATH")206 peerTube = PeerTube(pt_path)207 print(peerTube.get_user_info())208 channel_id = os.getenv('PT_CHANNEL_ID')209 name = "test"210 filepath = "cap5.mp4"...

Full Screen

Full Screen

conf.py

Source:conf.py Github

copy

Full Screen

...9def get_conf(key):10 return __conf.get(key)11def put_conf(key, value):12 __conf[key] = value13def __save_conf():14 with open(__CONF_FILE, 'w') as fp:15 json.dump(__conf, fp)16try:17 if not os.path.exists(__CONF_FILE):18 __conf = {}19 __save_conf()20 else:21 with open(__CONF_FILE, 'r') as fp:22 __conf = json.load(fp)23except Exception as e:24 print(e)...

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 yandex-tank 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