def test_druid_returns_error(self): # given client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ), "druid/v2/fail_request") # when / then with pytest.raises(IOError): yield client.topn(datasource="testdatasource", granularity="all", intervals="2015-12-29/pt1h", aggregations={"count": doublesum("count")}, dimension="user_name", metric="count", filter=Dimension("user_lang") == "en", threshold=1, context={"timeout": 1000})
def test_druid_returns_error(self): # given client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ), "druid/v2/fail_request") # when / then with pytest.raises(IOError): yield client.topn( datasource="testdatasource", granularity="all", intervals="2015-12-29/pt1h", aggregations={"count": doublesum("count")}, dimension="user_name", metric="count", filter=Dimension("user_lang") == "en", threshold=1, context={"timeout": 1000})
def test_client_allows_to_export_last_query(self): # given client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ), "druid/v2/return_results") yield client.topn(datasource="testdatasource", granularity="all", intervals="2015-12-29/pt1h", aggregations={"count": doublesum("count")}, dimension="user_name", metric="count", filter=Dimension("user_lang") == "en", threshold=1, context={"timeout": 1000}) # when / then # assert that last_query.export_tsv method was called (it should throw an exception, given empty path) with pytest.raises(TypeError): client.export_tsv(None)
def test_client_allows_passing_default_parameters(self): # given client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ), "druid/v2/return_results", defaults=dict(request_timeout=120)) top = yield client.topn(datasource="testdatasource", granularity="all", intervals="2015-12-29/pt1h", aggregations={"count": doublesum("count")}, dimension="user_name", metric="count", filter=Dimension("user_lang") == "en", threshold=1, context={"timeout": 1000}) # then self.assertIsNotNone(top) self.assertEqual(len(top.result), 1) self.assertEqual(len(top.result[0]['result']), 1)
def test_client_allows_to_export_last_query(self): # given client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ), "druid/v2/return_results") yield client.topn( datasource="testdatasource", granularity="all", intervals="2015-12-29/pt1h", aggregations={"count": doublesum("count")}, dimension="user_name", metric="count", filter=Dimension("user_lang") == "en", threshold=1, context={"timeout": 1000}) # when / then # assert that last_query.export_tsv method was called (it should throw an exception, given empty path) with pytest.raises(TypeError): client.export_tsv(None)
def test_druid_returns_results(self): # given client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ), "druid/v2/return_results") # when top = yield client.topn( datasource="testdatasource", granularity="all", intervals="2015-12-29/pt1h", aggregations={"count": doublesum("count")}, dimension="user_name", metric="count", filter=Dimension("user_lang") == "en", threshold=1, context={"timeout": 1000}) # then self.assertIsNotNone(top) self.assertEqual(len(top.result), 1) self.assertEqual(len(top.result[0]['result']), 1)