def setUp(self): self.vumi_helper = self.add_helper(DjangoVumiApiHelper()) self.diamondash_api = FakeDiamondashApiClient() layout = ToyDashboardLayout([{ 'type': 'lvalue', 'time_range': '1d', 'title': 'Spam (24h)', 'target': { 'metric_type': 'foo', 'name': 'spam', }, }, { 'type': 'lvalue', 'time_range': '1d', 'title': 'Ham (24h)', 'target': { 'metric_type': 'foo', 'name': 'ham', }, }]) self.monkey_patch(client, 'get_diamondash_api', lambda: self.diamondash_api) self.dashboard = Dashboard('ackbar-the-dashboard', layout)
class TestDashboard(GoDjangoTestCase): def setUp(self): self.vumi_helper = self.add_helper(DjangoVumiApiHelper()) self.diamondash_api = FakeDiamondashApiClient() layout = ToyDashboardLayout([{ 'type': 'lvalue', 'time_range': '1d', 'title': 'Spam (24h)', 'target': { 'metric_type': 'foo', 'name': 'spam', }, }, { 'type': 'lvalue', 'time_range': '1d', 'title': 'Ham (24h)', 'target': { 'metric_type': 'foo', 'name': 'ham', }, }]) self.monkey_patch(client, 'get_diamondash_api', lambda: self.diamondash_api) self.dashboard = Dashboard('ackbar-the-dashboard', layout) def test_sync(self): self.diamondash_api.set_response({'happy': 'config'}) self.dashboard.sync() [request] = self.diamondash_api.get_requests() self.assertEqual( request['data'], { 'name': 'ackbar-the-dashboard', 'widgets': [{ 'type': 'lvalue', 'time_range': '1d', 'title': 'Spam (24h)', 'target': 'foo.spam', }, { 'type': 'lvalue', 'time_range': '1d', 'title': 'Ham (24h)', 'target': 'foo.ham', }] }) self.assertEqual(self.dashboard.get_config(), {'happy': 'config'}) def test_sync_for_error_responses(self): self.diamondash_api.set_error_response(404, ':(') self.assertRaises(DashboardSyncError, self.dashboard.sync) def get_config_before_sync(self): self.assertRaises(self.dashboard.get_config, DashboardError)
class TestDashboard(GoDjangoTestCase): def setUp(self): self.vumi_helper = self.add_helper(DjangoVumiApiHelper()) self.diamondash_api = FakeDiamondashApiClient() layout = ToyDashboardLayout([{ 'type': 'lvalue', 'time_range': '1d', 'title': 'Spam (24h)', 'target': { 'metric_type': 'foo', 'name': 'spam', }, }, { 'type': 'lvalue', 'time_range': '1d', 'title': 'Ham (24h)', 'target': { 'metric_type': 'foo', 'name': 'ham', }, }]) self.monkey_patch( client, 'get_diamondash_api', lambda: self.diamondash_api) self.dashboard = Dashboard('ackbar-the-dashboard', layout) def test_sync(self): self.diamondash_api.set_response({'happy': 'config'}) self.dashboard.sync() [request] = self.diamondash_api.get_requests() self.assertEqual(request['data'], { 'name': 'ackbar-the-dashboard', 'widgets': [{ 'type': 'lvalue', 'time_range': '1d', 'title': 'Spam (24h)', 'target': 'foo.spam', }, { 'type': 'lvalue', 'time_range': '1d', 'title': 'Ham (24h)', 'target': 'foo.ham', }] }) self.assertEqual(self.dashboard.get_config(), {'happy': 'config'}) def test_sync_for_error_responses(self): self.diamondash_api.set_error_response(404, ':(') self.assertRaises(DashboardSyncError, self.dashboard.sync) def get_config_before_sync(self): self.assertRaises(self.dashboard.get_config, DashboardError)
def get(self, request, conversation): try: # build the dashboard name = "go.conversations.%s" % conversation.key layout = self.build_layout(conversation) dashboard = Dashboard(name, layout) # give the dashboard to diamondash dashboard.sync() dashboard_config = json.dumps(dashboard.get_config()) except Exception, e: self.on_error(e, sys.exc_info()) dashboard_config = None
def setUp(self): self.vumi_helper = self.add_helper(DjangoVumiApiHelper()) self.diamondash_api = FakeDiamondashApiClient() layout = ToyDashboardLayout([{ 'type': 'lvalue', 'time_range': '1d', 'title': 'Spam (24h)', 'target': { 'metric_type': 'foo', 'name': 'spam', }, }, { 'type': 'lvalue', 'time_range': '1d', 'title': 'Ham (24h)', 'target': { 'metric_type': 'foo', 'name': 'ham', }, }]) self.monkey_patch( client, 'get_diamondash_api', lambda: self.diamondash_api) self.dashboard = Dashboard('ackbar-the-dashboard', layout)