Пример #1
0
    def test_elastic_clickthrough_get(self):
        """Test elastic clickthrough read API."""
        click_kind, search_kind = self._make_elastic_metric_kinds()
        MetricFactory(kind=click_kind, start=date(2000, 1, 1), value=1)
        MetricFactory(kind=search_kind, start=date(2000, 1, 1), value=10)
        MetricFactory(kind=click_kind, start=date(2000, 1, 9), value=2)
        MetricFactory(kind=search_kind, start=date(2000, 1, 9), value=20)

        url = reverse('api.kpi.search-ctr')
        response = self.client.get(url + '?format=json')
        data = json.loads(response.content)
        eq_(data['objects'], [{
            'clicks': 2,
            'searches': 20,
            'start': '2000-01-09'
        }, {
            'clicks': 1,
            'searches': 10,
            'start': '2000-01-01'
        }])

        # Test filtering by start date:
        response = self.client.get(url + '?format=json&min_start=2000-01-09')
        data = json.loads(response.content)
        eq_(data['objects'], [{
            'searches': 20,
            'start': '2000-01-09',
            'clicks': 2
        }])
Пример #2
0
    def test_elastic_clickthrough_get(self):
        """Test elastic clickthrough read API."""
        click_kind, search_kind = self._make_elastic_metric_kinds()
        MetricFactory(kind=click_kind, start=date(2000, 1, 1), value=1)
        MetricFactory(kind=search_kind, start=date(2000, 1, 1), value=10)
        MetricFactory(kind=click_kind, start=date(2000, 1, 9), value=2)
        MetricFactory(kind=search_kind, start=date(2000, 1, 9), value=20)

        url = reverse("api.kpi.search-ctr")
        response = self.client.get(url + "?format=json")
        data = json.loads(response.content)
        eq_(
            data["objects"],
            [
                {
                    "clicks": 2,
                    "searches": 20,
                    "start": "2000-01-09"
                },
                {
                    "clicks": 1,
                    "searches": 10,
                    "start": "2000-01-01"
                },
            ],
        )

        # Test filtering by start date:
        response = self.client.get(url + "?format=json&min_start=2000-01-09")
        data = json.loads(response.content)
        eq_(data["objects"], [{
            "searches": 20,
            "start": "2000-01-09",
            "clicks": 2
        }])
Пример #3
0
    def test_exit_survey_results(self):
        """Test the exist survey results API call."""
        # Create the metrics
        kind = MetricKindFactory(code=EXIT_SURVEY_YES_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=1337)
        kind = MetricKindFactory(code=EXIT_SURVEY_NO_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=42)
        kind = MetricKindFactory(code=EXIT_SURVEY_DONT_KNOW_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=777)

        # Verify the results returned from the API
        r = self._get_api_result("api.kpi.exit-survey")
        eq_(r["objects"][0]["yes"], 1337)
        eq_(r["objects"][0]["no"], 42)
        eq_(r["objects"][0]["dont_know"], 777)
Пример #4
0
    def test_l10n_coverage(self):
        """Test l10n coverage API call."""
        # Create the metrics
        kind = MetricKindFactory(code=L10N_METRIC_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=56)

        # The l10n coverage should be 56%.
        r = self._get_api_result("api.kpi.l10n-coverage")
        eq_(r["objects"][0]["coverage"], 56)
Пример #5
0
    def test_visitors(self):
        """Test unique visitors API call."""
        # Create the metric.
        kind = MetricKindFactory(code=VISITORS_METRIC_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=42)

        # There should be 42 visitors.
        r = self._get_api_result("api.kpi.visitors")
        eq_(r["objects"][0]["visitors"], 42)
Пример #6
0
    def test_process_exit_surveys(self, requests):
        """Verify the metrics inserted by process_exit_surveys cron job."""
        requests.get.return_value.content = SURVEY_GIZMO_EXIT_SURVEY_RESPONSE

        # Create the kinds.
        yes_kind = MetricKindFactory(code=EXIT_SURVEY_YES_CODE)
        no_kind = MetricKindFactory(code=EXIT_SURVEY_NO_CODE)
        dunno_kind = MetricKindFactory(code=EXIT_SURVEY_DONT_KNOW_CODE)
        two_days_back = date.today() - timedelta(days=2)

        # Add a metric for 2 days ago so only 1 new day is collected.
        MetricFactory(kind=yes_kind, start=two_days_back)

        # Collect and process.
        _process_exit_survey_results()

        # Verify.
        eq_(4, Metric.objects.count())
        eq_(2, Metric.objects.filter(kind=yes_kind)[1].value)
        eq_(1, Metric.objects.get(kind=no_kind).value)
        eq_(1, Metric.objects.get(kind=dunno_kind).value)