Best Python code snippet using robotframework-pageobjects_python
trial_model_utils.py
Source:trial_model_utils.py
1from dateutil import parser2import datetime as dt3import logging4logger = logging.getLogger(__name__)5# fields not in this map just get passed through6RENAME_FIELDS_MAP = {7 "NCTId": "id",8}9ORGANIZATION_FIELDS = ["org_full_name", "org_class"]10US_TERRITORIES = set([11 "United States",12 "American Samoa",13 "Guam",14 "Northern Mariana Islands",15 "Puerto Rico",16 "U.S. Virgin Islands"17])18def extract_institution_from_trial(trial):19 institution = {}20 for field in ORGANIZATION_FIELDS:21 institution[field] = trial.pop(field)22 return institution23def split_organization_trial(full_trial):24 trial = full_trial.copy()25 institution = {}26 for field in ORGANIZATION_FIELDS:27 value = trial.pop(field)28 value = "" if value is None else value29 institution[field] = value30 return institution, trial31def trial_from_response_data(response_data):32 trial_model = {RENAME_FIELDS_MAP.get(k, k): v for k, v in response_data.items()}33 for k, v in trial_model.items():34 if not isinstance(v, str):35 continue36 # convert date columns37 if k.endswith("Date") and v is not None:38 trial_model[k] = parser.parse(v)39 continue40 # convert anything that looks boolean into a bool41 if v == "Yes":42 trial_model[k] = True43 continue44 elif v == "No":45 trial_model[k] = False46 continue47 # convert integers (I'm not aware of any floats in the schema)48 try:49 trial_model[k] = int(v)50 continue51 except ValueError:52 pass53 return dict_to_snake_case(trial_model)54def add_computed_fields(trial):55 """Adds Computed fields to a trial56 Fields related to https://clinicaltrials.gov/ct2/manage-recs/fdaaa57 should_have_results: the trial should have reported results by now58 is_late: the trial was late reporting results, but is not missing59 is_missing: the trial results should have been reported by now but are missing60 """61 add_applicable_trial_fields(trial)62 one_year = dt.timedelta(365)63 one_year_ago = trial["data_version"] - one_year64 # logger.info(trial)65 completion_date = trial["primary_completion_date"]66 is_applicable_trial = trial["is_applicable_trial"]67 trial["should_have_results"] = (68 is_applicable_trial and completion_date is not None and completion_date <= one_year_ago69 )70 results_date = trial["results_first_post_date"]71 if not trial['is_applicable_trial']:72 return trial73 trial["is_late"] = (74 trial["should_have_results"]75 and results_date is not None76 and results_date > (completion_date + one_year)77 )78 trial["is_missing"] = trial["should_have_results"] and not results_date79 trial["is_on_time"] = (80 trial["should_have_results"]81 and not trial["is_late"]82 and not trial["is_missing"]83 )84 return trial85def add_applicable_trial_fields(trial):86 """87 1) StudyType="Interventional"88 2) Any of:89 1) {"United States", "American Samoa", "Guam", "Northern Mariana Islands", "Puerto Rico", "U.S. Virgin Islands"} intersects with set(LocationCountry)90 2) [[Has IND or IDE Number]] - not publically available91 3) "Yes" in IsUSExport92 3) Either:93 1) IsFDARegulatedDrug and Phase != "Phase 1"94 2) IsUnapprovedDevice and DesignPrimaryPurpose != "Device Feasibility"95 :param trial: Trial dictionary96 :param rigorous: Whether to treat missing values as False (rigorous) or True (not rigorous)97 :return:98 """99 is_interventional = trial.get('study_type') == "Interventional"100 is_under_fda_oversight = (101 trial['location_country'] in US_TERRITORIES102 or trial['is_u_s_export']103 )104 is_major_drug_test = (105 trial['is_f_d_a_regulated_drug']106 and trial["phase"]107 and "Phase 1" not in trial["phase"]108 )109 is_major_device_test = (110 trial['is_unapproved_device']111 and trial["design_primary_purpose"] != "Device Feasibility"112 )113 trial['is_interventional'] = is_interventional114 trial['is_under_fda_oversight'] = is_under_fda_oversight115 trial['is_major_drug_test'] = is_major_drug_test116 trial['is_major_device_test'] = is_major_device_test117 trial['is_applicable_trial'] = (118 is_interventional119 and is_under_fda_oversight120 and (is_major_device_test or is_major_drug_test)121 )122def dict_to_snake_case(d):123 return {to_snake_case(k): v for k, v in d.items()}124def to_snake_case(str):...
test_fail.py
Source:test_fail.py
...5 widget_page = widget_rel_uri_attr.Page()6 widget_page.open()7 self.widget_search_result_page = widget_page.search("search term")8 # This assert should fail9 self.widget_search_result_page.should_have_results(2)10 def tearDown(self):11 self.widget_search_result_page.close()12if __name__ == "__main__":...
test_rel_uri_attr.py
Source:test_rel_uri_attr.py
...4 def test_search(self):5 widget_page = widget_rel_uri_attr.Page()6 widget_page.open()7 self.widget_search_result_page = widget_page.search("search term")8 self.widget_search_result_page.should_have_results(3)9 def tearDown(self):10 self.widget_search_result_page.close()11if __name__ == "__main__":...
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!!