Example #1
0
def test_https_warning(token, api_mock):
    """
    Test that connection object has the right properties.
    """
    with pytest.warns(UserWarning,
                      match="Communications with this server are NOT SECURE."):
        c = Connection("foo", token)
Example #2
0
def test_get_result_by_id(api_response, api_mock, token):
    """
    Test requesting a query by id makes the right calls.
    """
    api_response.json.return_value = {
        "query_id": "99",
        "query_result": [{
            "name": "foo"
        }],
    }
    type(api_response).status_code = PropertyMock(side_effect=(303, 200))
    api_response.headers = {"Location": "/Test"}
    c = Connection("foo", token)

    df = get_result_by_query_id(c, "99")

    # Query id should be requested
    assert (call("foo/api/0/poll/99", allow_redirects=False)
            in api_mock.get.call_args_list)

    # Query json should be requested
    assert call("foo/Test",
                allow_redirects=False) in api_mock.get.call_args_list
    # Query result should contain the id, and the dataframe
    assert 1 == len(df)
    assert "foo" == df.name[0]
Example #3
0
def test_get_result_by_id_error(http_code, exception, api_response, token):
    """
    Test requesting a query by id raises appropriate exceptions.
    """
    api_response.status_code = http_code
    c = Connection("foo", token)
    with pytest.raises(exception):
        get_result_by_query_id(c, "99")
Example #4
0
def test_login(token, api_mock):
    """
    Test that connection object has the right properties.
    """
    c = Connection("foo", token)
    assert "foo" == c.url
    assert token == c.token
    assert "bar" == c.user
    assert "Authorization" in c.session.headers
Example #5
0
def test_login(token):
    """
    Test that connection object has the right properties.
    """
    c = Connection(url="foo", token=token)
    assert "foo" == c.url
    assert token == c.token
    assert "bar" == c.user
    assert "Authorization" in c.session.headers
    assert isinstance(c.session.verify,
                      Mock)  # Shouldn't be set if no ssl_certificate passed
Example #6
0
def test_get_result_by_params(monkeypatch, api_mock, token):
    """
    Test requesting a query based on params makes the right calls.
    """
    api_mock.post.return_value.status_code = 202
    api_mock.post.return_value.headers = {"Location": "/99"}
    c = Connection("foo", token)
    dummy_method = Mock()
    monkeypatch.setattr(flowclient.client, "get_result_by_query_id",
                        dummy_method)
    get_result(c, {"query_kind": "query_type", "params": {"param": "value"}})
    # Should request the query by id
    dummy_method.assert_called_with(c, "99")
Example #7
0
def test_connection_repr(token, api_mock):
    """
    Test string representation of Connection object is correct.
    """
    c = Connection("foo", token)
    assert "bar@foo v0" == str(c)
Example #8
0
def test_no_warning_for_https(token, api_mock, monkeypatch):
    """ Test that no insecure warning is raised when connecting via https. """
    monkeypatch.delattr("flowclient.client.HTTP20Adapter")  # Disable hyper
    with pytest.warns(None) as warnings_record:
        c = Connection("https://foo", token)
    assert not warnings_record.list
Example #9
0
def test_missing_ident_error():
    bad_token = jwt.encode({"not_identity": "bar"}, "secret")
    with pytest.raises(FlowclientConnectionError):
        Connection(url="foo", token=bad_token)
Example #10
0
def test_token_decode_error(token):
    broken_token = token[25:]
    with pytest.raises(FlowclientConnectionError):
        Connection(url="foo", token=broken_token)
Example #11
0
def test_ssl_cert_path_set(token):
    """
    Test that if a path to certificate is given it gets set on the session object.
    """
    c = Connection(url="foo", token=token, ssl_certificate="DUMMY_CERT_PATH")
    assert "DUMMY_CERT_PATH" == c.session.verify
Example #12
0
def test_no_warning_for_https(token, monkeypatch):
    """ Test that no insecure warning is raised when connecting via https. """
    with pytest.warns(None) as warnings_record:
        c = Connection(url="https://foo", token=token)
    assert not warnings_record.list