def test_create_content_issues_dashboard(time): time.return_value = 5000 param_source = ElasticlogsKibanaSource( track=StaticTrack(), params={ "dashboard": "content_issues", "index_pattern": "elasticlogs-*" }, utcnow=lambda: datetime(year=2019, month=11, day=11)) response = param_source.params() assert response == load("content_issues")
def test_create_discover_random_window_length(time, fieldstats): time.return_value = 5000 param_source = ElasticlogsKibanaSource( track=StaticTrack(), params={ "dashboard": "discover", "index_pattern": "elasticlogs-*", "window_length": "random", "seed": 1573430400000 }, utcnow=lambda: datetime(year=2019, month=11, day=11)) param_source.partition(0, 1) response = param_source.params() assert response == load("discover-random-window-length")
def test_create_content_issues_dashboard_with_max_concurrent_shard_requests( time): time.return_value = 5000 param_source = ElasticlogsKibanaSource( track=StaticTrack(), params={ "dashboard": "content_issues", "index_pattern": "elasticlogs-*", "max_concurrent_shard_requests": 13, }, utcnow=lambda: datetime(year=2019, month=11, day=11)) response = param_source.params() assert "max_concurrent_shard_requests" in response["params"].keys() assert response["params"]["max_concurrent_shard_requests"] == 13
def test_invalid_dashboard_raises_error(): with pytest.raises(ConfigurationError) as ex: ElasticlogsKibanaSource(track=StaticTrack(), params={ "dashboard": "unknown", "index_pattern": "elasticlogs*" }) assert "Unknown dashboard [unknown]. Must be one of ['traffic', 'content_issues', 'discover']." == str( ex.value)
def test_determine_interval(): test_params = [ # window size, expected interval (1, "1s"), (10, "1s"), (100, "5s"), (1000, "30s"), (10000, "5m"), (100000, "30m"), (1000000, "3h"), (10000000, "7d"), (100000000, "30d"), ] for window_size, expected_interval in test_params: assert ElasticlogsKibanaSource.determine_interval( window_size_seconds=window_size, target_bars=50, max_bars=100) == expected_interval
def test_index_pattern_is_mandatory(): with pytest.raises(KeyError) as ex: ElasticlogsKibanaSource(track=StaticTrack(), params={"dashboard": "traffic"}) assert "'index_pattern'" == str(ex.value)
def test_dashboard_is_mandatory(): with pytest.raises(KeyError) as ex: ElasticlogsKibanaSource(track=StaticTrack(), params={"index_pattern": "elasticlogs*"}) assert "'dashboard'" == str(ex.value)