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
예제 #2
0
    def test_post_researcher(self):
        current_time = str(datetime.now())
        res = api_types.Researcher(f"Researcher_TEST_{current_time}",
                                   "POST_TEST", "internal",
                                   "*****@*****.**", "")
        result_uri = LIMS_API.post_researcher(res)

        res_soup = BeautifulSoup(LIMS_API.tools.api.get(result_uri), "xml")
        res_soup = res_soup.find("res:researcher")

        assert result_uri is not None
        assert current_time in res_soup.find("first-name").text
예제 #3
0
    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
예제 #4
0
    def test_get_researcher_uri_with_one_and_two_existing_researchers(self):
        current_time = datetime.now()

        res = api_types.Researcher(f"Test-{current_time}", "Last Name",
                                   f"{LIMS_API.tools.api.host}labs/1",
                                   "*****@*****.**", "")

        uri_answer = BeautifulSoup(_post_researcher(current_time), "xml")
        uri_answer = uri_answer.find("res:researcher")["uri"]

        assert len(LIMS_API.get_researcher_uri(res)) == 1
        assert LIMS_API.get_researcher_uri(res) == [uri_answer]

        uri_answer = BeautifulSoup(_post_researcher(current_time), "xml")
        uri_answer = uri_answer.find("res:researcher")["uri"]

        assert len(LIMS_API.get_researcher_uri(res)) == 2
예제 #5
0
def _post_researcher(current_time, res=None):
    """Method that will post a researcher and return a request."""

    if res is None:
        res = api_types.Researcher(f"Test-{current_time}", "Last Name",
                                   f"{LIMS_API.tools.api.host}labs/1",
                                   "*****@*****.**", "")

    template_path = (os.path.join(
        os.path.split(__file__)[0], "post_researcher_template.xml"))
    with open(template_path, 'r') as file:
        template = Template(file.read())
        response_xml = template.render(first_name=res.first_name,
                                       last_name=res.last_name,
                                       lab_uri=res.lab_type,
                                       email=res.email)
    url = f"{LIMS_API.tools.api.host}researchers"
    return LIMS_API.tools.api.post(url, response_xml)
예제 #6
0
def setUpModule():
    creds_path = (os.path.join(
        os.path.split(__file__)[0], "lims_dev_token.json"))
    with open(creds_path, 'r') as file:
        creds = json.load(file)

    global LIMS_API
    global LIMS_UTIL
    global DEFAULT_RES

    LIMS_API = project_lims_tools.ProjectLimsApi(host=creds["host"],
                                                 username=creds["username"],
                                                 password=creds["password"])
    LIMS_UTIL = project_lims_tools.LimsUtility(host=creds["host"],
                                               username=creds["username"],
                                               password=creds["password"])

    DEFAULT_RES = api_types.Researcher(
        "System", "Administrator", "internal", "",
        f"{LIMS_API.tools.api.host}researchers/1")

    assert LIMS_API is not None
    assert LIMS_UTIL is not None
예제 #7
0
 def test_post_researcher_already_in_system(self):
     res = api_types.Researcher("Already_In", "System", "internal",
                                "*****@*****.**", "")
     LIMS_API.post_researcher(res)
     LIMS_API.post_researcher(res)
예제 #8
0
 def test_get_researcher_uri_with_non_existing_researcher(self):
     res = api_types.Researcher("TEST_NOT", "_PRESENT", "internal",
                                "*****@*****.**", "")
     assert len(LIMS_API.get_researcher_uri(res)) == 0