def test_graylog_api_str(): g = api.GraylogAPI("dummyhost", 80, '/', "dummy", password="******") assert str(g) == 'dummyhost:80' g = api.GraylogAPI("dummyhost", 80, 'api', "dummy", password="******") assert str(g) == 'dummyhost:80/api' g = api.GraylogAPI("dummyhost", 80, '/api/', "dummy", password="******") assert str(g) == 'dummyhost:80/api'
def test_graylog_api_search(): httpretty.register_uri(httpretty.GET, "http://dummyhost:80/search/universal/absolute", body=generate_search_result(), content_type="application/json") # More of some dummy tests now g = api.GraylogAPI("dummyhost", 80, "dummy", password="******") sr = api.SearchRange("10 minutes ago", arrow.now()) q = api.SearchQuery(sr) result = g.search(q) assert len(result.messages) == 1 assert result.query == "*" q = api.SearchQuery(sr, fields=["level", "module", "message", "timestamp"], sort="level", ascending=True) qq = q.copy_with_range(sr) result = g.search(qq) assert len(result.messages) == 1 assert result.query == "*" q = api.SearchQuery(sr, fields=["level", "module", "message", "timestamp"], sort="level", ascending=False) result = g.search(q) assert len(result.messages) == 1 assert result.query == "*" result = g.search(q, fetch_all=True) assert len(result.messages) == 1 assert result.query == "*"
def test_streams(): httpretty.register_uri(httpretty.GET, "http://dummyhost:80/streams", body='[{"somestream" : "a" }]', content_type="application/json") # More of some dummy tests now g = api.GraylogAPI("dummyhost", 80, '/', "dummy", password="******") result = g.streams() expected = [{"somestream": "a"}] assert result == expected
def test_userinfo(): httpretty.register_uri(httpretty.GET, "http://dummyhost:80/users/testuser", body='{"someuser" : "info" }', content_type="application/json") # More of some dummy tests now g = api.GraylogAPI("dummyhost", 80, '/', "dummy", password="******") result = g.user_info("testuser") expected = {"someuser": "******"} assert result == expected
def test_to_many_results(): httpretty.register_uri(httpretty.GET, "http://dummyhost:80/search/universal/absolute", body=generate_search_result(1000000), content_type="application/json") # More of some dummy tests now g = api.GraylogAPI("dummyhost", 80, '/', "dummy", password="******") sr = api.SearchRange("10 minutes ago", arrow.now()) q = api.SearchQuery(sr) with pytest.raises(RuntimeError): result = g.search(q, fetch_all=True)
def test_graylog_endpoint_api_search(): httpretty.register_uri(httpretty.GET, "http://dummyhost:80/api/search/universal/absolute", body=generate_search_result(), content_type="application/json") # More of some dummy tests now g = api.GraylogAPI("dummyhost", 80, 'api', "dummy", password="******") sr = api.SearchRange("10 minutes ago", arrow.now()) q = api.SearchQuery(sr) result = g.search(q) assert len(result.messages) == 1 assert result.query == "*"