def test_create_containers(self): current_time = str(datetime.now()) prj = api_types.Project(f"Project_TEST_{current_time}", DEFAULT_RES, str(datetime.today().date()), [], "") custom_form = api_types.CustomForm(f"TEST_{current_time}", "0000", "0000") current_time = [] sample_list = [] for x in range(5): current_time.append(datetime.now().__str__()) time.sleep(.1) sample = api_types.Sample("Test_{}".format(current_time[x])) sample.con = api_types.Container("Test_{}".format(current_time[x]), "96 well plate", "", "") sample_list.append(sample) custom_form.samples = sample_list con_uris = LIMS_UTIL.create_containers(0000, prj, custom_form) assert con_uris is not None cons_soup = BeautifulSoup(LIMS_API.tools.api.get(con_uris), "xml") cons_soup = cons_soup.find_all("con:container") con_names = [con_soup.find("name") for con_soup in cons_soup] for i, con_name in enumerate(con_names): assert con_name.text.split("_")[-1] in current_time
def extract_project_info(req_soup, full_name=False): """Extract the relevant project info from a request. Arguments: req_soup (BS4 soup object): The soup of the request. full_name (boolean): Whether or not to capture the entire project name or just the last hyphenated element. Returns: prj_info (Project): The required info to post a project. """ if full_name: prj_name = req_soup.find("name").string else: prj_name = req_soup.find("name").string.split('-')[-1] res_name = req_soup.find("owner").find("name").string email = req_soup.find("owner").find("email").string # NOTE: Change this line to your own institution's email domain. if "email.arizona.edu" in email: res_lab = "internal" else: res_lab = "external" # Replace all not ascii chars with ascii ones, and any symbols with '-'. prj_res = api_types.Researcher( extract_custom_forms._sanitize_text(res_name.split()[0]), extract_custom_forms._sanitize_text(res_name.split()[-1]), extract_custom_forms._sanitize_text(res_lab), email, "") prj_info = api_types.Project(prj_name, prj_res) return prj_info
def test_create_project_not_in_system(self): current_time = str(datetime.now()) prj = api_types.Project(f"Project_TEST_{current_time}", DEFAULT_RES, str(datetime.today().date()), [], "") prj_uri = LIMS_UTIL.create_project(0000, prj) assert prj_uri != "" prj_soup = BeautifulSoup(LIMS_API.tools.api.get(prj_uri), "xml") prj_soup = prj_soup.find("prj:project") assert current_time in prj_soup.find("name").text
def test_create_researcher_not_in_system(self): current_time = str(datetime.now()) res = api_types.Researcher(f"Researcher_TEST_{current_time}", "POST_TEST", "internal", "*****@*****.**", "") prj = api_types.Project(f"Project_TEST_{current_time}", res, str(datetime.today().date()), [], "") res_uri = LIMS_UTIL.create_researcher(0000, prj) assert res_uri is not None res_soup = BeautifulSoup(LIMS_API.tools.api.get(res_uri), "xml") res_soup = res_soup.find("res:researcher") assert current_time in res_soup.find("first-name").text
def _post_project(prj=None): """Method that will post a project and return an api_types.Project.""" template_path = (os.path.join( os.path.split(__file__)[0], "post_project_template.xml")) with open(template_path, 'r') as file: template = Template(file.read()) response_xml = template.render( name=f"Project_TEST_{datetime.now()}", open_date=str(datetime.today().date()), res_uri=f"{LIMS_API.tools.api.host}researchers/1") prj_response = LIMS_API.tools.api.post( f"{LIMS_API.tools.api.host}projects", response_xml) prj_response_soup = BeautifulSoup(prj_response, "xml").find("prj:project") prj = api_types.Project(prj_response_soup.find("name"), DEFAULT_RES, datetime.today().date(), [], prj_response_soup["uri"]) return prj
def test_post_project(self): prj = api_types.Project(f"Project_TEST_{datetime.now()}", DEFAULT_RES, str(datetime.today().date()), [], "") result_uri = LIMS_API.post_project(prj) assert result_uri is not None
def test_post_project_already_in_system(self): prj = api_types.Project("Already_in_system", DEFAULT_RES, str(datetime.today().date()), [], "") LIMS_API.post_project(prj) LIMS_API.post_project(prj)