예제 #1
0
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'})
예제 #2
0
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'
        })
예제 #3
0
    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
예제 #4
0
 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)
예제 #5
0
 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)