class TestConversationReportsLayout(GoDjangoTestCase): def setUp(self): self.vumi_helper = self.add_helper(DjangoVumiApiHelper()) self.user_helper = self.vumi_helper.make_django_user() self.conv = self.user_helper.create_conversation(u'dummy') self.layout = ConversationReportsLayout(self.conv) def test_conversation_metric_handling(self): self.assertEqual( self.layout.handle_metric({ 'metric_type': 'conversation', 'name': 'foo', }), "go.campaigns.%s.conversations.%s.foo.avg" % (self.conv.user_account.key, self.conv.key)) def test_conversation_metric_handling_for_missing_fields(self): self.assertRaises( DashboardParseError, self.layout.handle_metric, {'metric_type': 'conversation'}) def test_account_metric_handling(self): self.assertEqual( self.layout.handle_metric({ 'metric_type': 'account', 'store': 'red', 'name': 'foo', }), "go.campaigns.%s.stores.red.foo.avg" % (self.conv.user_account.key)) def test_account_metric_handling_with_agg_method(self): self.assertEqual( self.layout.handle_metric({ 'metric_type': 'account', 'store': 'red', 'name': 'foo', 'aggregator': 'max' }), "go.campaigns.%s.stores.red.foo.max" % (self.conv.user_account.key)) def test_account_metric_handling_for_missing_fields(self): self.assertRaises( DashboardParseError, self.layout.handle_metric, {'metric_type': 'account', 'store': 'red'}) self.assertRaises( DashboardParseError, self.layout.handle_metric, {'metric_type': 'account', 'name': 'foo'})
class TestConversationReportsLayout(GoDjangoTestCase): def setUp(self): self.vumi_helper = self.add_helper(DjangoVumiApiHelper()) self.user_helper = self.vumi_helper.make_django_user() self.conv = self.user_helper.create_conversation(u'dummy') self.layout = ConversationReportsLayout(self.conv) def test_conversation_metric_handling(self): self.assertEqual( self.layout.handle_metric({ 'metric_type': 'conversation', 'name': 'foo', }), "go.campaigns.%s.conversations.%s.foo.avg" % (self.conv.user_account.key, self.conv.key)) def test_conversation_metric_handling_for_missing_fields(self): self.assertRaises(DashboardParseError, self.layout.handle_metric, {'metric_type': 'conversation'}) def test_account_metric_handling(self): self.assertEqual( self.layout.handle_metric({ 'metric_type': 'account', 'store': 'red', 'name': 'foo', }), "go.campaigns.%s.stores.red.foo.avg" % (self.conv.user_account.key)) def test_account_metric_handling_with_agg_method(self): self.assertEqual( self.layout.handle_metric({ 'metric_type': 'account', 'store': 'red', 'name': 'foo', 'aggregator': 'max' }), "go.campaigns.%s.stores.red.foo.max" % (self.conv.user_account.key)) def test_account_metric_handling_for_missing_fields(self): self.assertRaises(DashboardParseError, self.layout.handle_metric, { 'metric_type': 'account', 'store': 'red' }) self.assertRaises(DashboardParseError, self.layout.handle_metric, { 'metric_type': 'account', 'name': 'foo' })
def build_layout(self, conversation): """ Returns a conversation's dashboard widget data. Override to specialise dashboard building. """ reports_config = self._get_reports_config(conversation) if reports_config is None: return super(JSBoxReportsView, self).build_layout(conversation) layout_config = reports_config.get('layout') layout = ConversationReportsLayout(conversation, layout_config) return layout
def setUp(self): self.vumi_helper = self.add_helper(DjangoVumiApiHelper()) self.user_helper = self.vumi_helper.make_django_user() self.conv = self.user_helper.create_conversation(u'dummy') self.layout = ConversationReportsLayout(self.conv)
def setUp(self): self.vumi_helper = self.add_helper(DjangoVumiApiHelper()) self.user_helper = self.vumi_helper.make_django_user() self.conv = self.user_helper.create_conversation(u'dummy') self.layout = ConversationReportsLayout(self.conv)