Beispiel #1
0
    def test_index(self):
        tasks.index_finance_daily_inapp.delay(self.ids)
        self.refresh(timesleep=1)

        document = InappPayment.search().filter(config__addon=self.app.pk
            ).values_dict('date', 'inapp', 'revenue', 'count', 'refunds')[0]

        eq_(self.inapp_name, document['inapp'])

        date = document['date']
        ex_date = self.expected[self.inapp_name]['date']
        eq_((date.year, date.month, date.day),
            (ex_date.year, ex_date.month, ex_date.day))

        document = {
            self.inapp_name: {
                    'count': document['count'],
                    'revenue': int(document['revenue']),
                    'refunds': document['refunds']
            }
        }
        del(self.expected[self.inapp_name]['date'])

        self.expected[self.inapp_name]['revenue'] = (
            int(self.expected[self.inapp_name]['revenue']))
        eq_(document, self.expected)
Beispiel #2
0
    def test_index(self):
        tasks.index_finance_total_inapp_by_currency([self.app.pk])
        self.refresh(timesleep=1)

        # Grab document for each source breakdown and compare.
        for currency in self.currencies:
            # For some reason, query fails if uppercase letter in filter.
            document = (InappPayment.search().
                        filter(addon=self.app.pk, inapp=self.inapp_name,
                               currency=currency.lower()).
                        values_dict('currency', 'revenue', 'count',
                                    'refunds',
                                    'revenue_non_normalized'))[0]
            document = {'count': document['count'],
                        'revenue': int(document['revenue']),
                        'refunds': document['refunds'],
                        'revenue_non_normalized':
                            int(document['revenue_non_normalized'])}

            expected_inapp = self.expected[self.inapp_name]
            expected_inapp[currency]['revenue'] = (
                int(expected_inapp[currency]['revenue'])
            )
            expected_inapp[currency]['revenue_non_normalized'] = (
                int(expected_inapp[currency]['revenue_non_normalized'])
            )
            eq_(document, expected_inapp[currency])
Beispiel #3
0
    def test_index(self):
        tasks.index_finance_daily_inapp.delay(self.ids)
        self.refresh(timesleep=1)

        document = InappPayment.search().filter(
            config__addon=self.app.pk).values_dict('date', 'inapp', 'revenue',
                                                   'count', 'refunds')[0]

        eq_(self.inapp_name, document['inapp'])

        date = document['date']
        ex_date = self.expected[self.inapp_name]['date']
        eq_((date.year, date.month, date.day),
            (ex_date.year, ex_date.month, ex_date.day))

        document = {
            self.inapp_name: {
                'count': document['count'],
                'revenue': int(document['revenue']),
                'refunds': document['refunds']
            }
        }
        del (self.expected[self.inapp_name]['date'])

        self.expected[self.inapp_name]['revenue'] = (int(
            self.expected[self.inapp_name]['revenue']))
        eq_(document, self.expected)
Beispiel #4
0
    def test_index(self):
        tasks.index_finance_daily_inapp.delay(self.ids)
        self.refresh(timesleep=1)

        document = (
            InappPayment.search()
            .filter(config__addon=self.app.pk)
            .values_dict("date", "inapp", "revenue", "count", "refunds")[0]
        )

        eq_(self.inapp_name, document["inapp"])

        date = document["date"]
        ex_date = self.expected[self.inapp_name]["date"]
        eq_((date.year, date.month, date.day), (ex_date.year, ex_date.month, ex_date.day))

        document = {
            self.inapp_name: {
                "count": document["count"],
                "revenue": int(document["revenue"]),
                "refunds": document["refunds"],
            }
        }
        del (self.expected[self.inapp_name]["date"])

        self.expected[self.inapp_name]["revenue"] = int(self.expected[self.inapp_name]["revenue"])
        eq_(document, self.expected)
Beispiel #5
0
    def test_index(self):
        tasks.index_finance_total_inapp_by_currency([self.app.pk])
        self.refresh(timesleep=1)

        # Grab document for each source breakdown and compare.
        for currency in self.currencies:
            # For some reason, query fails if uppercase letter in filter.
            document = (InappPayment.search().filter(
                addon=self.app.pk,
                inapp=self.inapp_name,
                currency=currency.lower()).values_dict(
                    'currency', 'revenue', 'count', 'refunds',
                    'revenue_non_normalized'))[0]
            document = {
                'count': document['count'],
                'revenue': int(document['revenue']),
                'refunds': document['refunds'],
                'revenue_non_normalized':
                int(document['revenue_non_normalized'])
            }

            expected_inapp = self.expected[self.inapp_name]
            expected_inapp[currency]['revenue'] = (int(
                expected_inapp[currency]['revenue']))
            expected_inapp[currency]['revenue_non_normalized'] = (int(
                expected_inapp[currency]['revenue_non_normalized']))
            eq_(document, expected_inapp[currency])
Beispiel #6
0
    def test_index(self):
        tasks.index_finance_total_inapp([self.app.pk])
        self.refresh(timesleep=1)

        document = (
            InappPayment.search()
            .filter(addon=self.app.pk, inapp=self.inapp_name)
            .values_dict("revenue", "count", "refunds")
        )[0]

        document = {"count": document["count"], "revenue": int(document["revenue"]), "refunds": document["refunds"]}
        self.expected[self.inapp_name]["revenue"] = int(self.expected[self.inapp_name]["revenue"])

        eq_(document, self.expected[self.inapp_name])
Beispiel #7
0
    def test_index(self):
        tasks.index_finance_total_inapp([self.app.pk])
        self.refresh(timesleep=1)

        document = (InappPayment.search().
                    filter(addon=self.app.pk, inapp=self.inapp_name).
                    values_dict('revenue', 'count', 'refunds'))[0]

        document = {'count': document['count'],
                    'revenue': int(document['revenue']),
                    'refunds': document['refunds']}
        self.expected[self.inapp_name]['revenue'] = int(
            self.expected[self.inapp_name]['revenue'])

        eq_(document, self.expected[self.inapp_name])
Beispiel #8
0
    def test_index(self):
        tasks.index_finance_total_inapp_by_src([self.app.pk])
        self.refresh(timesleep=1)

        # Grab document for each source breakdown and compare.
        for source in self.sources:
            # For some reason, query fails if uppercase letter in filter.
            document = (
                InappPayment.search()
                .filter(addon=self.app.pk, inapp=self.inapp_name, source=source.lower())
                .values_dict("source", "revenue", "count", "refunds")
            )[0]
            document = {"count": document["count"], "revenue": int(document["revenue"]), "refunds": document["refunds"]}
            self.expected_inapp[source]["revenue"] = int(self.expected_inapp[source]["revenue"])
            eq_(document, self.expected_inapp[source])
Beispiel #9
0
def stats_report(request, addon, report, inapp=None, category_field=None):
    """
    Stats page. Passes in context variables into template which is read by the
    JS to build a URL. The URL calls a *_series view which determines
    necessary arguments for get_series_*. get_series_* queries ES for the data,
    which is later formatted into .json or .csv and made available to the JS.
    """
    if addon.status is not amo.STATUS_PUBLIC and not check_stats_permission(
        request, addon, for_contributions=True, no_raise=True
    ):
        return redirect(addon.get_detail_url())
    check_stats_permission(request, addon)

    # For inapp, point template to same as non-inapp, but still use
    # different report names.
    template_name = "appstats/reports/%s.html" % report.replace("_inapp", "")
    if inapp:
        stats_base_url = addon.get_stats_inapp_url(action="revenue", inapp=inapp)
    else:
        stats_base_url = reverse("mkt.stats.overview", args=[addon.app_slug])
    view = get_report_view(request)

    # Get list of in-apps for drop-down in-app selector.
    inapps = []
    # Until we figure out why ES stores strings in lowercase despite
    # the field being set to not analyze, we grab the lowercase version
    # from ES and do a case-insensitive query to the ORM to un-lowercase.
    inapps_lower = list(
        set(payment["inapp"] for payment in list(InappPayment.search().filter(addon=addon.id).values_dict("inapp")))
    )
    for inapp_name in inapps_lower:
        inapps.append(InappPayment.objects.filter(name__iexact=inapp_name)[0].name)

    return jingo.render(
        request,
        template_name,
        {
            "addon": addon,
            "report": report,
            "view": view,
            "stats_base_url": stats_base_url,
            "inapp": inapp,
            "inapps": inapps,
        },
    )
Beispiel #10
0
    def test_index(self):
        tasks.index_finance_total_inapp([self.app.pk])
        self.refresh(timesleep=1)

        document = (InappPayment.search().filter(
            addon=self.app.pk,
            inapp=self.inapp_name).values_dict('revenue', 'count',
                                               'refunds'))[0]

        document = {
            'count': document['count'],
            'revenue': int(document['revenue']),
            'refunds': document['refunds']
        }
        self.expected[self.inapp_name]['revenue'] = int(
            self.expected[self.inapp_name]['revenue'])

        eq_(document, self.expected[self.inapp_name])
Beispiel #11
0
    def test_index(self):
        tasks.index_finance_total_inapp_by_src([self.app.pk])
        self.refresh(timesleep=1)

        # Grab document for each source breakdown and compare.
        for source in self.sources:
            # For some reason, query fails if uppercase letter in filter.
            document = (InappPayment.search().
                        filter(addon=self.app.pk, inapp=self.inapp_name,
                               source=source.lower()).
                        values_dict('source', 'revenue', 'count',
                                    'refunds'))[0]
            document = {'count': document['count'],
                        'revenue': int(document['revenue']),
                        'refunds': document['refunds']}
            self.expected_inapp[source]['revenue'] = (
                int(self.expected_inapp[source]['revenue'])
            )
            eq_(document, self.expected_inapp[source])
Beispiel #12
0
def stats_report(request, addon, report, inapp=None, category_field=None):
    """
    Stats page. Passes in context variables into template which is read by the
    JS to build a URL. The URL calls a *_series view which determines
    necessary arguments for get_series_*. get_series_* queries ES for the data,
    which is later formatted into .json or .csv and made available to the JS.
    """
    if (addon.status is not amo.STATUS_PUBLIC and not check_stats_permission(
            request, addon, for_contributions=True, no_raise=True)):
        return redirect(addon.get_detail_url())
    check_stats_permission(request, addon)

    # For inapp, point template to same as non-inapp, but still use
    # different report names.
    template_name = 'appstats/reports/%s.html' % report.replace('_inapp', '')
    if inapp:
        stats_base_url = addon.get_stats_inapp_url(action='revenue',
                                                   inapp=inapp)
    else:
        stats_base_url = reverse('mkt.stats.overview', args=[addon.app_slug])
    view = get_report_view(request)

    # Get list of in-apps for drop-down in-app selector.
    inapps = []
    # Until we figure out why ES stores strings in lowercase despite
    # the field being set to not analyze, we grab the lowercase version
    # from ES and do a case-insensitive query to the ORM to un-lowercase.
    inapps_lower = list(
        set(payment['inapp'] for payment in list(InappPayment.search().filter(
            addon=addon.id).values_dict('inapp'))))
    for inapp_name in inapps_lower:
        inapps.append(
            InappPayment.objects.filter(name__iexact=inapp_name)[0].name)

    return jingo.render(
        request, template_name, {
            'addon': addon,
            'report': report,
            'view': view,
            'stats_base_url': stats_base_url,
            'inapp': inapp,
            'inapps': inapps,
        })
Beispiel #13
0
    def test_index(self):
        tasks.index_finance_total_inapp_by_src([self.app.pk])
        self.refresh(timesleep=1)

        # Grab document for each source breakdown and compare.
        for source in self.sources:
            # For some reason, query fails if uppercase letter in filter.
            document = (InappPayment.search().filter(
                addon=self.app.pk,
                inapp=self.inapp_name,
                source=source.lower()).values_dict('source', 'revenue',
                                                   'count', 'refunds'))[0]
            document = {
                'count': document['count'],
                'revenue': int(document['revenue']),
                'refunds': document['refunds']
            }
            self.expected_inapp[source]['revenue'] = (int(
                self.expected_inapp[source]['revenue']))
            eq_(document, self.expected_inapp[source])
Beispiel #14
0
    def test_index(self):
        tasks.index_finance_total_inapp_by_currency([self.app.pk])
        self.refresh(timesleep=1)

        # Grab document for each source breakdown and compare.
        for currency in self.currencies:
            # For some reason, query fails if uppercase letter in filter.
            document = (
                InappPayment.search()
                .filter(addon=self.app.pk, inapp=self.inapp_name, currency=currency.lower())
                .values_dict("currency", "revenue", "count", "refunds", "revenue_non_normalized")
            )[0]
            document = {
                "count": document["count"],
                "revenue": int(document["revenue"]),
                "refunds": document["refunds"],
                "revenue_non_normalized": int(document["revenue_non_normalized"]),
            }

            expected_inapp = self.expected[self.inapp_name]
            expected_inapp[currency]["revenue"] = int(expected_inapp[currency]["revenue"])
            expected_inapp[currency]["revenue_non_normalized"] = int(expected_inapp[currency]["revenue_non_normalized"])
            eq_(document, expected_inapp[currency])