How to use _get_config_file method in tempest

Best Python code snippet using tempest_python

test_cdsw_config_reader.py

Source:test_cdsw_config_reader.py Github

copy

Full Screen

...53 console_debug=True,54 format_str="%(message)s",55 )56 def test_config_reader_job_name(self):57 file = self._get_config_file(VALID_CONFIG_FILE)58 self._set_mandatory_env_vars()59 config = CdswJobConfigReader.read_from_file(file)60 self.assertIsNotNone(config)61 self.assertEqual("Reviewsync", config.job_name)62 def test_config_reader_valid_command_type(self):63 self._set_mandatory_env_vars()64 file = self._get_config_file(VALID_CONFIG_FILE)65 config = CdswJobConfigReader.read_from_file(file)66 self.assertIsNotNone(config)67 self.assertEqual(CommandType.REVIEWSYNC, config.command_type)68 def test_config_reader_email_body_file(self):69 self._set_mandatory_env_vars()70 file = self._get_config_file("cdsw_job_config_email_body_file.py")71 config = CdswJobConfigReader.read_from_file(file)72 self.assertIsNotNone(config.runs)73 run = config.runs[0]74 self.assertIsNotNone(run)75 self.assertIsNotNone(run.email_settings)76 self.assertEqual(run.email_settings.email_body_file_from_command_data, "report-short.html")77 def test_config_reader_invalid_command_type(self):78 file = self._get_config_file("cdsw_job_config_bad_command_type.py")79 with self.assertRaises(WrongTypeError) as ve:80 CdswJobConfigReader.read_from_file(file)81 LOG.info(ve.exception)82 self.assert_wrong_value_type(str(ve.exception), "command_type", "CommandType", "rrr", "str")83 def test_config_reader_valid_mandatory_env_vars(self):84 self._set_mandatory_env_vars()85 file = self._get_config_file(VALID_CONFIG_FILE)86 config = CdswJobConfigReader.read_from_file(file)87 self.assertIsNotNone(config)88 self.assertEqual(["GSHEET_CLIENT_SECRET", "GSHEET_SPREADSHEET", "MAIL_ACC_USER"], config.mandatory_env_vars)89 def test_config_reader_invalid_mandatory_env_var(self):90 file = self._get_config_file("cdsw_job_config_invalid_mandatory_env_var.py")91 with self.assertRaises(ValueError) as ve:92 CdswJobConfigReader.read_from_file(file)93 exc_msg = ve.exception.args[0]94 LOG.info(exc_msg)95 self.assertTrue(96 "Invalid mandatory env var specified as 'GSHEET_CLIENT_S'. Valid env vars for Command 'CommandType.REVIEWSYNC'"97 in str(exc_msg)98 )99 def test_config_reader_check_if_mandatory_env_vars_are_provided_at_runtime_positive_case(self):100 file = self._get_config_file(VALID_CONFIG_FILE)101 self._set_mandatory_env_vars()102 config = CdswJobConfigReader.read_from_file(file)103 self.assertIsNotNone(config)104 self.assertEqual(["GSHEET_CLIENT_SECRET", "GSHEET_SPREADSHEET", "MAIL_ACC_USER"], config.mandatory_env_vars)105 def test_config_reader_check_if_mandatory_env_vars_missing(self):106 file = self._get_config_file(VALID_CONFIG_FILE)107 os.environ["GSHEET_SPREADSHEET"] = "test_sheet"108 with self.assertRaises(ValueError) as ve:109 CdswJobConfigReader.read_from_file(file)110 exc_msg = ve.exception.args[0]111 LOG.info(exc_msg)112 self.assertIn("'GSHEET_CLIENT_SECRET'", exc_msg)113 self.assertNotIn("GSHEET_SPREADSHEET", exc_msg)114 def test_config_reader_mandatory_env_vars_are_of_correct_command_type(self):115 self._set_mandatory_env_vars()116 file = self._get_config_file(VALID_CONFIG_FILE)117 config = CdswJobConfigReader.read_from_file(file)118 self.assertIsNotNone(config)119 self.assertEqual(CommandType.REVIEWSYNC, config.command_type)120 def test_config_reader_valid_optional_env_vars(self):121 self._set_mandatory_env_vars()122 file = self._get_config_file(VALID_CONFIG_FILE)123 config = CdswJobConfigReader.read_from_file(file)124 self.assertIsNotNone(config)125 self.assertEqual(["BRANCHES", "GSHEET_JIRA_COLUMN"], config.optional_env_vars)126 def test_config_reader_valid_optional_env_vars_should_be_also_part_of_env_var_class(self):127 file = self._get_config_file("cdsw_job_config_invalid_optional_env_var.py")128 with self.assertRaises(ValueError) as ve:129 CdswJobConfigReader.read_from_file(file)130 exc_msg = ve.exception.args[0]131 LOG.info(exc_msg)132 self.assertTrue(133 "Invalid mandatory env var specified as 'GSHEET_CLIENT_S'. Valid env vars for Command 'CommandType.REVIEWSYNC'"134 in str(exc_msg)135 )136 def test_config_reader_if_optional_arg_is_mapped_to_yarndevtools_args_it_becomes_mandatory(self):137 self._set_mandatory_env_vars()138 del os.environ["GSHEET_JIRA_COLUMN"]139 # "GSHEET_JIRA_COLUMN" is intentionally deleted!140 file = self._get_config_file(VALID_CONFIG_FILE)141 with self.assertRaises(ValueError) as ve:142 CdswJobConfigReader.read_from_file(file)143 exc_msg = ve.exception.args[0]144 LOG.info(exc_msg)145 self.assertIn("GSHEET_JIRA_COLUMN", exc_msg)146 def test_config_reader_variables(self):147 file = self._get_config_file(VALID_CONFIG_FILE)148 self._set_mandatory_env_vars()149 config = CdswJobConfigReader.read_from_file(file)150 self.assertIsNotNone(config.global_variables)151 self.assertEqual("testAlgorithm", config.global_variables["algorithm"])152 # command_data_testAlgorithm_20220105_214629.zip153 self._match_env_var_for_regex(config, "commandDataFileName", r"command_data_testAlgorithm_(.*)\.zip")154 def test_config_reader_using_builtin_variable(self):155 self._set_mandatory_env_vars()156 file = self._get_config_file("cdsw_job_config_invalid_using_builtin_variable.py")157 with self.assertRaises(ValueError) as ve:158 CdswJobConfigReader.read_from_file(file)159 exc_msg = ve.exception.args[0]160 LOG.info(exc_msg)161 self.assertIn("Cannot use variables with the same name as built-in variables", exc_msg)162 def test_config_reader_using_builtin_variable_in_other_variable(self):163 self._set_mandatory_env_vars()164 file = self._get_config_file("cdsw_job_config_using_builtin_variable_in_other_variable.py")165 config = CdswJobConfigReader.read_from_file(file)166 job_start_date = config.job_start_date()167 expected_subject = f"YARN reviewsync report [start date: {job_start_date}]"168 expected_command_data_file_name = f"command_data_{job_start_date}.zip"169 self.assertIsNotNone(config.runs[0])170 self.assertEqual(171 {172 "sender": "YARN reviewsync",173 "subject": expected_subject,174 "commandDataFileName": expected_command_data_file_name,175 },176 config.global_variables,177 )178 self.assertEqual(expected_command_data_file_name, config.runs[0].email_settings.attachment_file_name)179 self.assertEqual("report-short.html", config.runs[0].email_settings.email_body_file_from_command_data)180 self.assertEqual("YARN reviewsync", config.runs[0].email_settings.sender)181 self.assertEqual(expected_subject, config.runs[0].email_settings.subject)182 def test_config_reader_transitive_variable_resolution_endless(self):183 self._set_mandatory_env_vars()184 file = self._get_config_file("cdsw_job_config_transitive_variable_resolution_endless.py")185 with self.assertRaises(ValueError) as ve:186 CdswJobConfigReader.read_from_file(file)187 exc_msg = ve.exception.args[0]188 LOG.info(exc_msg)189 self.assertIn("Cannot resolve variable 'varD'", exc_msg)190 def test_config_reader_transitive_variable_resolution_unresolved(self):191 self._set_mandatory_env_vars()192 file = self._get_config_file("cdsw_job_config_transitive_variable_resolution_unresolved.py")193 with self.assertRaises(ValueError) as ve:194 CdswJobConfigReader.read_from_file(file)195 exc_msg = ve.exception.args[0]196 LOG.info(exc_msg)197 self.assertIn("Cannot resolve variable 'varX'", exc_msg)198 def test_config_reader_transitive_variable_resolution_valid(self):199 self._set_mandatory_env_vars()200 file = self._get_config_file("cdsw_job_config_transitive_variable_resolution_valid.py")201 config = CdswJobConfigReader.read_from_file(file)202 self.assertIsNotNone(config.global_variables)203 self.assertEqual("testAlgorithm", config.global_variables["algorithm"])204 self.assertEqual("no_var_here", config.global_variables["varE"])205 self.assertEqual("no_var_here", config.global_variables["varA"])206 self.assertEqual("no_var_here", config.global_variables["varB"])207 self.assertEqual("no_var_here", config.global_variables["varC"])208 self.assertEqual("no_var_here", config.global_variables["varD"])209 def test_config_reader_transitive_variable_resolution_valid_more_complex(self):210 self._set_mandatory_env_vars()211 file = self._get_config_file("cdsw_job_config_transitive_variable_resolution_valid_more_complex.py")212 config = CdswJobConfigReader.read_from_file(file)213 self.assertIsNotNone(config.global_variables)214 self.assertEqual("testAlgorithm", config.global_variables["algorithm"])215 self.assertEqual("no_var_here", config.global_variables["varE"])216 self.assertEqual("no_var_here", config.global_variables["varA"])217 self.assertEqual("no_var_here", config.global_variables["varB"])218 self.assertEqual("no_var_here", config.global_variables["varC"])219 self.assertEqual("no_var_here", config.global_variables["varD"])220 self.assertEqual("s", config.global_variables["varS"])221 self.assertEqual("xy", config.global_variables["varZ"])222 self.assertEqual("xys", config.global_variables["varT"])223 self.assertEqual("xys", config.global_variables["varU"])224 def test_config_reader_transitive_variable_resolution_valid_more_complex2(self):225 self._set_mandatory_env_vars()226 file = self._get_config_file("cdsw_job_config_transitive_variable_resolution_valid_more_complex2.py")227 config = CdswJobConfigReader.read_from_file(file)228 self.assertIsNotNone(config.global_variables)229 self.assertEqual("testAlgorithm", config.global_variables["algorithm"])230 self.assertEqual("x", config.global_variables["varZ"])231 self.assertEqual("xs", config.global_variables["varT"])232 self.assertEqual("x", config.global_variables["varX"])233 self.assertEqual("s", config.global_variables["varS"])234 def test_config_reader_email_settings(self):235 self._set_mandatory_env_vars()236 file = self._get_config_file("cdsw_job_config_email_settings_with_vars.py")237 config = CdswJobConfigReader.read_from_file(file)238 email_settings_1 = config.runs[0].email_settings239 email_settings_2 = config.runs[1].email_settings240 self.assertIsNotNone(email_settings_1)241 self.assertIsNotNone(email_settings_2)242 self.assertEqual("testSubject+v2+v1_1", email_settings_1.subject)243 self.assertEqual("attachmentFileName+v3+v4", email_settings_1.attachment_file_name)244 self.assertFalse(email_settings_1.enabled)245 self.assertTrue(email_settings_1.send_attachment)246 self.assertEqual("testSubject+v2+v1_2", email_settings_2.subject)247 self.assertEqual("attachmentFileName+v1", email_settings_2.attachment_file_name)248 self.assertFalse(email_settings_2.enabled)249 self.assertTrue(email_settings_2.send_attachment)250 def test_config_reader_drive_api_upload_settings(self):251 self._set_mandatory_env_vars()252 file = self._get_config_file(VALID_CONFIG_FILE)253 config = CdswJobConfigReader.read_from_file(file)254 drive_api_upload_settings = config.runs[0].drive_api_upload_settings255 self.assertIsNotNone(drive_api_upload_settings)256 self.assertEqual("simple", drive_api_upload_settings.file_name)257 self.assertFalse(drive_api_upload_settings.enabled)258 def test_config_reader_drive_api_upload_settings_with_vars(self):259 self._set_mandatory_env_vars()260 file = self._get_config_file("cdsw_job_config_drive_api_upload_settings_with_vars.py")261 config = CdswJobConfigReader.read_from_file(file)262 drive_api_upload_settings = config.runs[0].drive_api_upload_settings263 self.assertIsNotNone(drive_api_upload_settings)264 self.assertEqual("constant1_v1_constant2_v3_constant3", drive_api_upload_settings.file_name)265 self.assertFalse(drive_api_upload_settings.enabled)266 def test_config_reader_runconfig_defined_yarn_dev_tools_arguments_env_vars(self):267 self._set_mandatory_env_vars()268 file = self._get_config_file("cdsw_job_config_runconfig_defined_yarn_dev_tools_arguments_env_vars.py")269 config = CdswJobConfigReader.read_from_file(file)270 self.assertIsNotNone(config.runs[0])271 self.assertIsNotNone(config.runs[0].yarn_dev_tools_arguments)272 self.assertEqual(273 [274 "--debug",275 "REVIEWSYNC",276 "--gsheet",277 '--gsheet-client-secret "gsheet client secret"',278 '--gsheet-spreadsheet "gsheet spreadsheet"',279 '--gsheet-jira-column "gsheet jira column"',280 ],281 config.yarn_dev_tools_arguments,282 )283 self.assertEqual(284 [285 "--debug",286 "REVIEWSYNC",287 "--gsheet",288 '--gsheet-client-secret "gsheet client secret"',289 '--gsheet-spreadsheet "gsheet spreadsheet"',290 '--gsheet-jira-column "gsheet jira column"',291 "--arg1",292 "--arg2 param1 param2",293 "--arg3 param1",294 "--arg4",295 ],296 config.runs[0].yarn_dev_tools_arguments,297 )298 def test_config_reader_runconfig_defined_yarn_dev_tools_arguments_regular_vars(self):299 self._set_mandatory_env_vars()300 file = self._get_config_file("cdsw_job_config_runconfig_defined_yarn_dev_tools_arguments_regular_vars.py")301 config = CdswJobConfigReader.read_from_file(file)302 job_start_date = config.job_start_date()303 self.assertIsNotNone(config.runs[0])304 self.assertEqual(305 [306 "--debug",307 "REVIEWSYNC",308 "--gsheet",309 "--algo testAlgorithm",310 f"--command-data-filename command_data_testAlgorithm_{job_start_date}.zip",311 ],312 config.yarn_dev_tools_arguments,313 )314 self.assertEqual(315 [316 "--debug",317 "REVIEWSYNC",318 "--gsheet",319 "--algo testAlgorithm",320 f"--command-data-filename command_data_testAlgorithm_{job_start_date}.zip",321 "--arg1",322 "--arg2 param1 param2",323 "--arg3 param1",324 "--arg4",325 ],326 config.runs[0].yarn_dev_tools_arguments,327 )328 def test_config_reader_runconfig_defined_yarn_dev_tools_arguments_overrides(self):329 self._set_mandatory_env_vars()330 file = self._get_config_file("cdsw_job_config_runconfig_defined_yarn_dev_tools_arguments_overrides.py")331 config = CdswJobConfigReader.read_from_file(file)332 self.assertIsNotNone(config.runs[0])333 self.assertEqual(334 [335 "--debug",336 "REVIEWSYNC",337 "--gsheet",338 '--gsheet-client-secret "gsheet client secret"',339 '--gsheet-spreadsheet "gsheet spreadsheet"',340 '--gsheet-jira-column "gsheet jira column"',341 ],342 config.yarn_dev_tools_arguments,343 )344 self.assertEqual(345 [346 "--debug",347 "REVIEWSYNC",348 "--gsheet",349 "--gsheet-client-secret bla",350 "--gsheet-spreadsheet bla2",351 '--gsheet-jira-column "gsheet jira column"',352 "--arg1",353 ],354 config.runs[0].yarn_dev_tools_arguments,355 )356 def test_config_reader_runconfig_defined_yarn_dev_tools_variable_overrides(self):357 self._set_mandatory_env_vars()358 file = self._get_config_file("cdsw_job_config_runconfig_defined_yarn_dev_tools_variable_overrides.py")359 config = CdswJobConfigReader.read_from_file(file)360 self.assertIsNotNone(config.runs[0])361 original_yarndevtools_args = [362 "--debug",363 "REVIEWSYNC",364 "--gsheet",365 '--gsheet-client-secret "gsheet client secret"',366 '--gsheet-spreadsheet "gsheet spreadsheet"',367 '--gsheet-jira-column "gsheet jira column"',368 ]369 self.assertEqual(370 original_yarndevtools_args,371 config.yarn_dev_tools_arguments,372 )373 self.assertEqual(374 original_yarndevtools_args375 + [376 "--testArg1 yetAnotherAlgorithm",377 "--testArg2 overriddenCommandData",378 "--testArg3 something+globalValue1",379 "--testArg4 something+globalValue2",380 "--testArg5 a new variable",381 ],382 config.runs[0].yarn_dev_tools_arguments,383 )384 def test_config_reader_two_run_configs_defined_complex(self):385 self._set_mandatory_env_vars()386 file = self._get_config_file("cdsw_job_config_two_run_configs_defined_complex.py")387 config = CdswJobConfigReader.read_from_file(file)388 self.assertIsNotNone(config.runs[0])389 self.assertIsNotNone(config.runs[1])390 original_yarndevtools_args = [391 "--debug",392 "REVIEWSYNC",393 "--gsheet",394 '--gsheet-client-secret "gsheet client secret"',395 '--gsheet-spreadsheet "gsheet spreadsheet"',396 '--gsheet-jira-column "gsheet jira column"',397 ]398 self.assertEqual(399 original_yarndevtools_args,400 config.yarn_dev_tools_arguments,401 )402 self.assertEqual(403 original_yarndevtools_args404 + [405 "--testArg1 yetAnotherAlgorithm",406 "--testArg2 overriddenCommandData",407 "--testArg3 something+globalValue1",408 "--testArg4 something+globalValue2",409 "--testArg5 a new variable",410 ],411 config.runs[0].yarn_dev_tools_arguments,412 )413 self.assertEqual(414 original_yarndevtools_args415 + [416 "--testArg1 yetAnotherAlgorithm2",417 "--testArg2 overriddenCommandData2",418 "--testArg3 var1+globalValue3",419 "--testArg4 var2+globalValue4",420 "--testArg5 var3",421 ],422 config.runs[1].yarn_dev_tools_arguments,423 )424 def test_config_reader_two_run_configs_with_same_name_not_allowed(self):425 self._set_mandatory_env_vars()426 file = self._get_config_file("cdsw_job_config_two_run_configs_same_name.py")427 with self.assertRaises(ValueError) as ve:428 CdswJobConfigReader.read_from_file(file)429 exc_msg = ve.exception.args[0]430 LOG.info(exc_msg)431 self.assertIn("Duplicate job name not allowed!", exc_msg)432 def test_config_reader_env_var_sanitize(self):433 self._set_env_vars_from_dict(434 {435 "GSHEET_WORKSHEET": "env1",436 "GSHEET_SPREADSHEET": "env2 env22",437 "GSHEET_JIRA_COLUMN": "env3 'env33' env333",438 "GSHEET_STATUS_INFO_COLUMN": '"env4 env44"',439 "GSHEET_UPDATE_DATE_COLUMN": '"env5 env5555"',440 "BRANCHES": "branch-3.2 branch-3.3",441 }442 )443 file = self._get_config_file("cdsw_job_config_env_var_sanitize_test.py")444 config = CdswJobConfigReader.read_from_file(file)445 self.assertEqual(446 [447 "--debug",448 "REVIEWSYNC",449 "--gsheet",450 "--arg1 env1",451 '--arg2 "env2 env22"',452 "--arg3 env3 'env33' env333",453 '--arg4 "env4 env44"',454 '--arg5 "env5 env5555"',455 "--arg6 branch-3.2 branch-3.3",456 ],457 config.runs[0].yarn_dev_tools_arguments,458 )459 def test_config_reader_yarn_dev_tools_arguments_with_includes(self):460 self._set_mandatory_env_vars()461 file = self._get_config_file("cdsw_job_config_yarn_dev_tools_arguments_with_includes.py")462 config = CdswJobConfigReader.read_from_file(file)463 self.assertEqual(464 [465 "--debug",466 "REVIEWSYNC",467 "--gsheet",468 '--gsheet-client-secret "gsheet client secret"',469 '--gsheet-spreadsheet "gsheet spreadsheet"',470 '--gsheet-jira-column "gsheet jira column"',471 "--force-sending-email",472 "--cache-type google_drive",473 ],474 config.runs[0].yarn_dev_tools_arguments,475 )476 def test_config_reader_yarn_dev_tools_arguments_with_conditional_env_var(self):477 self._set_mandatory_env_vars()478 os.environ["ENV1"] = "envVal1"479 os.environ["ENV3"] = "envVal3"480 file = self._get_config_file("cdsw_job_config_yarn_globals_with_conditional_env_var.py")481 config = CdswJobConfigReader.read_from_file(file)482 self.assertEqual(483 [484 "--debug",485 "REVIEWSYNC",486 "--gsheet",487 '--gsheet-client-secret "gsheet client secret"',488 '--gsheet-spreadsheet "gsheet spreadsheet"',489 '--gsheet-jira-column "gsheet jira column"',490 "--arg1 envVal1",491 "--arg2 False",492 "--arg3 envVal3",493 "--arg4 1999",494 ],495 config.runs[0].yarn_dev_tools_arguments,496 )497 def _match_env_var_for_regex(self, config, env_name, regex):498 LOG.debug(499 "Matching Env var with name '%s' with resolved value of %s",500 env_name,501 config.global_variables[env_name],502 )503 match = re.match(regex, config.global_variables[env_name])504 if not match:505 self.fail(506 "Env var with name '{}' with resolved value of {} does not match regex: {}. Original value: {}".format(507 env_name, config.global_variables[env_name], regex, config.global_variables[env_name]508 )509 )510 LOG.debug("Found date: %s", match.group(1))511 @classmethod512 def _get_config_file(cls, file_name):513 file = FileUtils.join_path(cls.configfiles_base_dir, file_name)514 return file515 @staticmethod516 def validate_date(date_text):517 try:518 datetime.datetime.strptime(date_text, "%Y%m%d_%H%M%S")519 except ValueError:520 raise ValueError("Incorrect data format, should be YYYY-MM-DD")521 def assert_wrong_value_type(self, exception_msg, field_name, expected_type, actual_value, actual_type):522 self.assertEqual(523 exception_msg,524 f'wrong value type for field "{field_name}" - should be "{expected_type}" instead of value "{actual_value}" of type "{actual_type}"',...

Full Screen

Full Screen

config.py

Source:config.py Github

copy

Full Screen

...22 _FIELD_ATTACHMENT_DESCRIPTION = "DESCRIPTION"23 _FIELD_ATTACHMENT_CONTENT_TYPE = "CONTENT_TYPE"24 @classmethod25 def get_attachment_content_type(cls) -> str:26 return cls._get_config_file()[cls._FIELD_ATTACHMENT_PUBLIC][cls._FIELD_ATTACHMENT_CONTENT_TYPE]27 @classmethod28 def get_attachment_description(cls) -> str:29 return cls._get_config_file()[cls._FIELD_ATTACHMENT_PUBLIC][cls._FIELD_ATTACHMENT_DESCRIPTION]30 @classmethod31 def get_attachment_path_in(cls) -> str:32 return cls._get_config_file()[cls._FIELD_ATTACHMENT_PUBLIC][cls._FIELD_ATTACHMENT_PATH_IN]33 @classmethod34 def get_api_key(cls) -> str:35 return cls._get_config_file()[cls._FIELD_API_KEY]36 @classmethod37 def get_user_id(cls) -> int:38 return int(cls._get_config_file()[cls._FIELD_USER_ID])39 @classmethod40 def get_monetary_account_id_2(cls) -> int:41 return int(cls._get_config_file()[cls._FIELD_MONETARY_ACCOUNT_ID_2])42 @classmethod43 def get_monetary_account_id_1(cls) -> int:44 return int(cls._get_config_file()[cls._FIELD_MONETARY_ACCOUNT_ID_1])45 @classmethod46 def get_cash_register_id(cls) -> str:47 return cls._get_config_file()[cls._FIELD_TAB_USAGE][cls._FIELD_CASH_REGISTER_ID]48 @classmethod49 def get_pointer_counter_party_self(cls) -> Pointer:50 type_ = cls._get_config_file()[cls._FIELD_COUNTER_PARTY_SELF][cls._FIELD_TYPE]51 alias = cls._get_config_file()[cls._FIELD_COUNTER_PARTY_SELF][cls._FIELD_ALIAS]52 return Pointer(type_, alias)53 @classmethod54 def get_pointer_counter_party_other(cls) -> Pointer:55 type_ = cls._get_config_file()[cls._FIELD_COUNTER_PARTY_OTHER][cls._FIELD_TYPE]56 alias = cls._get_config_file()[cls._FIELD_COUNTER_PARTY_OTHER][cls._FIELD_ALIAS]57 return Pointer(type_, alias)58 @classmethod59 def get_permitted_ips(cls) -> List[str]:60 permitted_ips_str = cls._get_config_file()[cls._FIELD_PERMITTED_IPS]61 if not permitted_ips_str:62 return []63 return permitted_ips_str.split(cls._DELIMITER_IPS)64 @classmethod65 def _get_config_file(cls) -> Any:66 file_path = os.path.dirname(os.path.realpath(__file__))67 with open(file_path + "/assets/config.json", "r") as f:...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...13 config_parser.read(config_file_path)14 username = config_parser.get(config._SECTION, "username")15 password = config_parser.get(config._SECTION, "password")16 else:17 print("Your JIRA creadentials will be saved in %s" % (_get_config_file()))18 username = input("Username: ")19 password = getpass.getpass("Password: ")20 21 config_parser.add_section(config._SECTION)22 config_parser.set(config._SECTION, "username", username)23 config_parser.set(config._SECTION, "password", password)24 25 with open(config_file_path, "wb") as config_file:26 config_parser.write(config_file)27 return username, password28def _get_home_directory():29 return os.path.expanduser("~")30def _get_config_file():31 return os.path.join(_get_home_directory(), config._CONFIG_FILE)32def print_progress(index, total):33 sys.stdout.write("\rTicket %d out of %d done" % (index, total))34 sys.stdout.flush()35def validate_credentials():36 username, password = _get_credentails(_get_config_file())37 params = {"username": username}38 results = requests.get(config._BASE_URL + config._USER, auth=HTTPBasicAuth(username, password), params=params)39 if results.status_code == 401:40 return False41 return True42def get_request_auth(api_call, params=None, json=True):43 username, password = _get_credentails(_get_config_file())44 if params:45 results = requests.get(config._BASE_URL + api_call, auth=HTTPBasicAuth(username, password), params=params)46 else:47 results = requests.get(config._BASE_URL + api_call, auth=HTTPBasicAuth(username, password))48 if results:49 if json:50 return results.json()51 return results52 else:53 None54def put_request_auth(api_call, payload):55 username, password = _get_credentails(_get_config_file())56 headers = {"Content-Type": "application/json; charset=utf8"}57 result = requests.put(config._BASE_URL + api_call, auth=HTTPBasicAuth(username, password), headers=headers, json=payload)58 if result.status_code == 204:59 return True60 return False61def add_label_payload(label):62 return {63 "update":64 {"labels":65 [66 {"add":"%s" % label}67 ]68 }69 }

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