Esempio n. 1
0
    def test_visitors(self):
        """Test unique visitors API call."""
        # Create the metric.
        kind = metric_kind(code=VISITORS_METRIC_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=42, save=True)

        # There should be 42 visitors.
        r = self._get_api_result("kpi_visitors")
        eq_(r["objects"][0]["visitors"], 42)
Esempio n. 2
0
    def test_l10n_coverage(self):
        """Test l10n coverage API call."""
        # Create the metrics
        kind = metric_kind(code=L10N_METRIC_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=56, save=True)

        # The l10n coverage should be 56%.
        r = self._get_api_result("kpi_l10n_coverage")
        eq_(r["objects"][0]["coverage"], 56)
Esempio n. 3
0
    def test_l10n_coverage(self):
        """Test l10n coverage API call."""
        # Create the metrics
        kind = metric_kind(code=L10N_METRIC_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=56,
               save=True)

        # The l10n coverage should be 56%.
        r = self._get_api_result('kpi_l10n_coverage')
        eq_(r['objects'][0]['coverage'], 56)
Esempio n. 4
0
    def test_visitors(self):
        """Test unique visitors API call."""
        # Create the metric.
        kind = metric_kind(code=VISITORS_METRIC_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=42,
               save=True)

        # There should be 42 visitors.
        r = self._get_api_result('kpi_visitors')
        eq_(r['objects'][0]['visitors'], 42)
Esempio n. 5
0
    def test_elastic_clickthrough_get(self):
        """Test elastic clickthrough read API."""
        click_kind, search_kind = self._make_elastic_metric_kinds()
        metric(kind=click_kind,
               start=date(2000, 1, 1),
               value=1,
               save=True)
        metric(kind=search_kind,
               start=date(2000, 1, 1),
               value=10,
               save=True)
        metric(kind=click_kind,
               start=date(2000, 1, 9),
               value=2,
               save=True)
        metric(kind=search_kind,
               start=date(2000, 1, 9),
               value=20,
               save=True)

        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': u'2000-01-09'},
            {'clicks': 1, 'searches': 10,
             'start': u'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'], [{u'searches': 20, u'start': u'2000-01-09',
                               u'clicks': 2}])
Esempio n. 6
0
    def test_elastic_clickthrough_get(self):
        """Test elastic clickthrough read API."""
        click_kind, search_kind = self._make_elastic_metric_kinds()
        metric(kind=click_kind, start=date(2000, 1, 1), value=1, save=True)
        metric(kind=search_kind, start=date(2000, 1, 1), value=10, save=True)
        metric(kind=click_kind, start=date(2000, 1, 9), value=2, save=True)
        metric(kind=search_kind, start=date(2000, 1, 9), value=20, save=True)

        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': u'2000-01-09'
        }, {
            'clicks': 1,
            'searches': 10,
            'start': u'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'], [{
            u'searches': 20,
            u'start': u'2000-01-09',
            u'clicks': 2
        }])
Esempio n. 7
0
    def test_elastic_clickthrough_get(self):
        """Test elastic clickthrough read API."""
        click_kind, search_kind = self._make_elastic_metric_kinds()
        metric(kind=click_kind, start=date(2000, 1, 1), value=1, save=True)
        metric(kind=search_kind, start=date(2000, 1, 1), value=10, save=True)
        metric(kind=click_kind, start=date(2000, 1, 9), value=2, save=True)
        metric(kind=search_kind, start=date(2000, 1, 9), value=20, save=True)

        url = reverse('api_dispatch_list',
                      kwargs={
                          'resource_name': 'elastic-clickthrough-rate',
                          'api_name': 'v1'
                      })
        response = self.client.get(url + '?format=json')
        self.assertContains(  # Beware of dict order changes someday.
            response,
            '"objects": [{"clicks": 2, "resource_uri": "", "searches": 20, '
            '"start": "2000-01-09"}, '
            '{"clicks": 1, "resource_uri": "", "searches": 10, '
            '"start": "2000-01-01"}]')

        # Test filtering by start date:
        response = self.client.get(url + '?format=json&min_start=2000-01-09')
        self.assertContains(  # Beware of dict order changes someday.
            response,
            '"objects": [{"clicks": 2, "resource_uri": "", "searches": 20, '
            '"start": "2000-01-09"}]')
Esempio n. 8
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 = metric_kind(code=EXIT_SURVEY_YES_CODE, save=True)
        no_kind = metric_kind(code=EXIT_SURVEY_NO_CODE, save=True)
        dunno_kind = metric_kind(code=EXIT_SURVEY_DONT_KNOW_CODE, save=True)
        two_days_back = date.today() - timedelta(days=2)

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

        # 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)
Esempio n. 9
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 = metric_kind(code=EXIT_SURVEY_YES_CODE, save=True)
        no_kind = metric_kind(code=EXIT_SURVEY_NO_CODE, save=True)
        dunno_kind = metric_kind(code=EXIT_SURVEY_DONT_KNOW_CODE, save=True)
        two_days_back = date.today() - timedelta(days=2)

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

        # 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)
Esempio n. 10
0
    def test_exit_survey_results(self):
        """Test the exist survey results API call."""
        # Create the metrics
        kind = metric_kind(code=EXIT_SURVEY_YES_CODE, save=True)
        metric(kind=kind,
               start=date.today(),
               end=date.today(),
               value=1337,
               save=True)
        kind = metric_kind(code=EXIT_SURVEY_NO_CODE, save=True)
        metric(kind=kind,
               start=date.today(),
               end=date.today(),
               value=42,
               save=True)
        kind = metric_kind(code=EXIT_SURVEY_DONT_KNOW_CODE, save=True)
        metric(kind=kind,
               start=date.today(),
               end=date.today(),
               value=777,
               save=True)

        # 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)
Esempio n. 11
0
    def test_exit_survey_results(self):
        """Test the exist survey results API call."""
        # Create the metrics
        kind = metric_kind(code=EXIT_SURVEY_YES_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=1337, save=True)
        kind = metric_kind(code=EXIT_SURVEY_NO_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=42, save=True)
        kind = metric_kind(code=EXIT_SURVEY_DONT_KNOW_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=777, save=True)

        # Verify the results returned from the API
        r = self._get_api_result("kpi_exit_survey_results")
        eq_(r["objects"][0]["yes"], 1337)
        eq_(r["objects"][0]["no"], 42)
        eq_(r["objects"][0]["dont_know"], 777)
Esempio n. 12
0
    def test_elastic_clickthrough_get(self):
        """Test elastic clickthrough read API."""
        click_kind, search_kind = self._make_elastic_metric_kinds()
        metric(kind=click_kind, start=date(2000, 1, 1), value=1, save=True)
        metric(kind=search_kind, start=date(2000, 1, 1), value=10, save=True)
        metric(kind=click_kind, start=date(2000, 1, 9), value=2, save=True)
        metric(kind=search_kind, start=date(2000, 1, 9), value=20, save=True)

        url = reverse("api_dispatch_list", kwargs={"resource_name": "elastic-clickthrough-rate", "api_name": "v1"})
        response = self.client.get(url + "?format=json")
        self.assertContains(  # Beware of dict order changes someday.
            response,
            '"objects": [{"clicks": 2, "resource_uri": "", "searches": 20, '
            '"start": "2000-01-09"}, '
            '{"clicks": 1, "resource_uri": "", "searches": 10, '
            '"start": "2000-01-01"}]',
        )

        # Test filtering by start date:
        response = self.client.get(url + "?format=json&min_start=2000-01-09")
        self.assertContains(  # Beware of dict order changes someday.
            response, '"objects": [{"clicks": 2, "resource_uri": "", "searches": 20, ' '"start": "2000-01-09"}]'
        )