How to use get_poeditor_file_path method in toolium

Best Python code snippet using toolium_python

poeditor.py

Source:poeditor.py Github

copy

Full Screen

...145 """146 Saves POEditor terms to a file in output dir147 :param poeditor_terms: POEditor terms148 """149 file_path = get_poeditor_file_path()150 with open(file_path, 'w') as f:151 json.dump(poeditor_terms, f, indent=4)152 logger.info('POEditor terms have been saved in "%s" file' % file_path)153def assert_poeditor_response_code(response_data, status_code):154 """155 Check status code returned in POEditor response156 :param response_data: data received in poeditor API response as a dictionary157 :param status_code: expected status code158 """159 assert response_data['response']['code'] == status_code, f"{response_data['response']['code']} status code \160 has been received instead of {status_code} in POEditor response body. Response body: {response_data}"161def get_country_from_config_file():162 """163 Gets the country to use later from config checking if it's a valid one in POEditor164 :return: country165 """166 try:167 country = dataset.toolium_config.get('TestExecution', 'language').lower()168 except NoOptionError:169 assert False, "There is no language configured in test, add it to config or use step with parameter lang_id"170 return country171def get_valid_lang(language_codes, lang=None):172 """173 Check if language provided is a valid one configured and returns the POEditor matched lang174 :param language_codes: valid POEditor language codes175 :param lang: a language from config or from lang parameter176 :return: lang matched from POEditor177 """178 lang = lang if lang else get_country_from_config_file()179 if lang in language_codes:180 matching_lang = lang181 elif lang.split('-')[0] in language_codes:182 matching_lang = lang.split('-')[0]183 else:184 assert False, f"Language {lang} is not included in valid codes: {', '.join(language_codes)}"185 return matching_lang186def get_poeditor_projects():187 """188 Get the list of the projects configured in POEditor189 :return: POEditor projects list190 """191 params = {"api_token": get_poeditor_api_token()}192 r = send_poeditor_request(ENDPOINT_POEDITOR_LIST_PROJECTS, "POST", params, 200)193 response_data = r.json()194 assert_poeditor_response_code(response_data, "200")195 projects = response_data['result']['projects']196 projects_names = [project['name'] for project in projects]197 logger.info('POEditor projects: %s %s' % (len(projects_names), projects_names))198 return projects199def send_poeditor_request(endpoint, method, params, status_code):200 """201 Send a request to the POEditor API202 :param endpoint: endpoint path203 :param method: HTTP method to be used in the request204 :param params: parameters to be sent in the request205 :param code: expected status code206 :return: response207 """208 try:209 base_url = dataset.project_config['poeditor']['base_url']210 except KeyError:211 base_url = 'https://api.poeditor.com'212 url = f'{base_url}/{endpoint}'213 r = requests.request(method, url, data=params)214 assert r.status_code == status_code, f"{r.status_code} status code has been received instead of {status_code} \215 in POEditor response calling to {url}. Response body: {r.json()}"216 return r217def get_all_terms(project_info, lang):218 """219 Get all terms for a given language configured in POEditor220 :param project_info: project_info221 :param lang: a valid language configured in POEditor project222 :return: the list of terms223 """224 params = {"api_token": get_poeditor_api_token(),225 "id": project_info['id'],226 "language": lang}227 r = send_poeditor_request(ENDPOINT_POEDITOR_LIST_TERMS, "POST", params, 200)228 response_data = r.json()229 assert_poeditor_response_code(response_data, "200")230 terms = response_data['result']['terms']231 logger.info('POEditor terms in "%s" project with "%s" language: %s' % (project_info['name'], lang, len(terms)))232 return terms233def load_poeditor_texts(context=None):234 """235 Download POEditor texts and save in output folder if the config exists or use previously downloaded texts236 :param context: behave context (deprecated parameter)237 """238 if context:239 logger.warning('Deprecated context parameter has been sent to load_poeditor_texts method. Please, '240 'configure POEditor global variables instead of passing context to load_poeditor_texts.')241 if get_poeditor_api_token():242 # Try to get poeditor mode param from toolium config first243 poeditor_mode = dataset.toolium_config.get_optional('TestExecution', 'poeditor_mode')244 if poeditor_mode:245 dataset.project_config['poeditor']['mode'] = poeditor_mode246 if 'mode' in dataset.project_config['poeditor'] and map_param('[CONF:poeditor.mode]') == 'offline':247 file_path = get_poeditor_file_path()248 # With offline POEditor mode, file must exist249 if not os.path.exists(file_path):250 error_message = 'You are using offline POEditor mode but poeditor file has not been found in %s' % \251 file_path252 logger.error(error_message)253 assert False, error_message254 with open(file_path, 'r') as f:255 dataset.poeditor_terms = json.load(f)256 if context:257 # Workaround for backwards compatibility258 context.poeditor_export = dataset.poeditor_terms259 last_mod_time = time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(os.path.getmtime(file_path)))260 logger.info('Using local POEditor file "%s" with date: %s' % (file_path, last_mod_time))261 else: # without mode configured or mode = 'online'262 download_poeditor_texts(context)263 else:264 logger.info("POEditor is not configured")265def get_poeditor_file_path():266 """267 Get configured POEditor file path or default file path268 :return: POEditor file path269 """270 try:271 file_path = dataset.project_config['poeditor']['file_path']272 except KeyError:273 file_path = os.path.join(DriverWrappersPool.output_directory, 'poeditor_terms.json')274 return file_path275def get_poeditor_api_token():276 """277 Get POEditor API token from environment property or configuration property278 :return: POEditor API token279 """...

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 toolium 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