def test_sync_no_mtime_update_when_no_pull(lochness_subject_raw_json): Lochness, subject, raw_json = lochness_subject_raw_json sync(Lochness, subject, False) init_mtime = raw_json.stat().st_mtime # second sync without update in the db sync(Lochness, subject, False) assert init_mtime == raw_json.stat().st_mtime rmtree('tmp_lochness')
def test_sync_det_update_no_file_leads_to_pull(lochness_subject_raw_json): Lochness, subject, raw_json = lochness_subject_raw_json sync(Lochness, subject, False) init_mtime = raw_json.stat().st_mtime os.remove(raw_json) text_body = "redcap_url=https%3A%2F%2Fredcap.partners.org%2Fredcap%2F&project_url=https%3A%2F%2Fredcap.partners.org%2Fredcap%2Fredcap_v10.0.30%2Findex.php%3Fpid%3D26709&project_id=26709&username=kc244&record=subject_1&instrument=inclusionexclusion_checklist&inclusionexclusion_checklist_complete=0" save_post_from_redcap(text_body, Lochness['redcap']['data_entry_trigger_csv']) # second sync without update in the db sync(Lochness, subject, False) assert raw_json.is_file() rmtree('tmp_lochness')
def test_initialize_metadata_then_sync(args_and_Lochness): args, Lochness = args_and_Lochness # before initializing metadata for study in args.studies: phoenix_path = Path(Lochness['phoenix_root']) general_path = phoenix_path / 'GENERAL' metadata = general_path / study / f"{study}_metadata.csv" initialize_metadata(Lochness, study, 'record_id1', 'cons_date') for subject in lochness.read_phoenix_metadata(Lochness, studies=['StudyA']): sync(Lochness, subject, False) show_tree_then_delete('tmp_lochness')
def test_sync_det_update_while_diff_file_leads_to_data_overwrite( lochness_subject_raw_json): Lochness, subject, raw_json = lochness_subject_raw_json sync(Lochness, subject, False) # change the content of the existing json with open(raw_json, 'w') as json_file: json.dump({'test': 'test'}, json_file) text_body = "redcap_url=https%3A%2F%2Fredcap.partners.org%2Fredcap%2F&project_url=https%3A%2F%2Fredcap.partners.org%2Fredcap%2Fredcap_v10.0.30%2Findex.php%3Fpid%3D26709&project_id=26709&username=kc244&record=subject_1&instrument=inclusionexclusion_checklist&inclusionexclusion_checklist_complete=0" save_post_from_redcap(text_body, Lochness['redcap']['data_entry_trigger_csv']) # second sync without update in the db sync(Lochness, subject, False) with open(raw_json, 'r') as json_file: new_content_dict = json.load(json_file) assert {'test': 'test'} != new_content_dict rmtree('tmp_lochness')
def test_sync_det_update_while_file_leads_to_mtime_update( lochness_subject_raw_json): Lochness, subject, raw_json = lochness_subject_raw_json sync(Lochness, subject, False) init_mtime = raw_json.stat().st_mtime text_body = "redcap_url=https%3A%2F%2Fredcap.partners.org%2Fredcap%2F&project_url=https%3A%2F%2Fredcap.partners.org%2Fredcap%2Fredcap_v10.0.30%2Findex.php%3Fpid%3D26709&project_id=26709&username=kc244&record=subject_1&instrument=inclusionexclusion_checklist&inclusionexclusion_checklist_complete=0" save_post_from_redcap(text_body, Lochness['redcap']['data_entry_trigger_csv']) with open(raw_json, 'r') as json_file: init_content_dict = json.load(json_file) # second sync without update in the db sync(Lochness, subject, False) with open(raw_json, 'r') as json_file: new_content_dict = json.load(json_file) assert init_content_dict == new_content_dict assert init_mtime < raw_json.stat().st_mtime rmtree('tmp_lochness')
def test_sync_twice(lochness_subject_raw_json): Lochness, subject, raw_json = lochness_subject_raw_json sync(Lochness, subject, False) # second sync without update in the db sync(Lochness, subject, False) rmtree('tmp_lochness')
def test_sync_init(lochness_subject_raw_json): Lochness, subject, raw_json = lochness_subject_raw_json sync(Lochness, subject, False) assert raw_json.is_file() == True rmtree('tmp_lochness')