예제 #1
0
def test_send_request_timout():
    """This test will trigge a timout error."""
    # GIVEN a request and a request that timouts
    url = "http://www.badurl.com"
    responses.add(
        responses.GET,
        url,
        body=requests.exceptions.Timeout(),
    )
    # WHEN requesting
    with pytest.raises(requests.exceptions.Timeout):
        # THEN assert that the a Timeout is raised
        scout_requests.get_request(url)
예제 #2
0
def test_get_request():
    """Test functions that accepts an url and returns decoded data from it"""

    # test function with url that exists
    url = "http://www.github.com"
    decoded_resp = get_request(url)
    assert "<!DOCTYPE html>" in decoded_resp
예제 #3
0
파일: panel.py 프로젝트: AspirinCode/scout
def load_panel_app(adapter, panel_id=None, institute="cust000"):
    """Load PanelApp panels into scout database

    If no panel_id load all PanelApp panels

    Args:
        adapter(scout.adapter.MongoAdapter)
        panel_id(str): The panel app panel id
    """
    base_url = "https://panelapp.genomicsengland.co.uk/WebServices/{0}/"

    hgnc_map = adapter.genes_by_alias()

    if panel_id:
        panel_ids = [panel_id]

    if not panel_id:

        LOG.info("Fetching all panel app panels")
        data = get_request(base_url.format("list_panels"))

        json_lines = json.loads(data)

        panel_ids = [panel_info["Panel_Id"] for panel_info in json_lines["result"]]

    for panel_id in panel_ids:
        panel_data = get_request(base_url.format("get_panel") + panel_id)

        parsed_panel = parse_panel_app_panel(
            panel_info=json.loads(panel_data)["result"],
            hgnc_map=hgnc_map,
            institute=institute,
        )
        parsed_panel["panel_id"] = panel_id

        if len(parsed_panel["genes"]) == 0:
            LOG.warning(
                "Panel {} is missing genes. Skipping.".format(
                    parsed_panel["display_name"]
                )
            )
            continue

        try:
            adapter.load_panel(parsed_panel=parsed_panel)
        except Exception as err:
            raise err
예제 #4
0
def test_get_request_bad_url():
    """Test functions that accepts an url and returns decoded data from it"""

    # test function with a url that is not valid
    url = "fakeyurl"
    with pytest.raises(ValueError) as err:
        # function should raise error
        assert get_request(url)
예제 #5
0
def test_get_request_bad_url():
    """Test function that accepts an url and returns decoded data from it"""

    # test function with a url that is not valid
    url = "fakeyurl"
    with pytest.raises(requests.exceptions.MissingSchema):
        # function should raise error
        assert scout_requests.get_request(url)
예제 #6
0
def test_get_request():
    """Test functions that accepts an url and returns decoded data from it"""

    # GIVEN an URL
    url = "http://www.github.com"
    responses.add(
        responses.GET,
        url,
        status=200,
    )

    # WHEN requesting
    response = scout_requests.get_request(url)
    # THEN assert that the reponse is correct
    assert response.status_code == 200
예제 #7
0
def test_get_request_bad_request():
    """Test functions that accepts an url and returns decoded data from it"""

    # GIVEN an URL
    url = "http://www.badurl.com"
    responses.add(
        responses.GET,
        url,
        status=404,
    )
    # WHEN requesting
    with pytest.raises(requests.exceptions.HTTPError):
        response = scout_requests.get_request(url)
        # THEN assert that the a httperror is raised
        assert response.status_code == 404