diff options
| author | Rolf Erik Lekang <me@rolflekang.com> | 2015-02-03 10:07:31 +0100 |
|---|---|---|
| committer | Rolf Erik Lekang <me@rolflekang.com> | 2015-02-03 10:07:31 +0100 |
| commit | 13f3f59cd4d6bccac43970c3753b8e23d3df2803 (patch) | |
| tree | 05b6cd1e9579776ea495ae2a5dc4e0d3cf05ed59 /dashboard | |
| parent | 2c290e4c9d39071f0df47b913ee21b32c630f99e (diff) | |
Add test for update_metric management command
Diffstat (limited to 'dashboard')
| -rw-r--r-- | dashboard/tests.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/dashboard/tests.py b/dashboard/tests.py index cdb40ee4..9936378b 100644 --- a/dashboard/tests.py +++ b/dashboard/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import codecs import json +from django.core import management from django.http import Http404 from django.test import TestCase, RequestFactory from django_hosts.resolvers import reverse @@ -109,3 +110,27 @@ class GithubItemCountMetricTestCase(TestCase, MetricMixin): # and then with 42 items on the second page mocker.get(self.api_url2, text=json.dumps([{'id': i} for i in range(42)])) self.assertEqual(self.instance.fetch(), 142) + + +class UpdateMetricCommandTestCase(TestCase): + github_url = 'https://api.github.com/repos/django/django/pulls?state=closed&per_page=100&page=1' + + def setUp(self): + GithubItemCountMetric.objects.create( + name='Pull Requests (Closed)', + link_url="https://github.com/django/django/pulls", + period="instant", + unit_plural="pull requests", + slug="pull-requests-closed", + unit="pull request", + api_url="https://api.github.com/repos/django/django/pulls?state=closed" + ) + + @requests_mock.mock() + @mock.patch('dashboard.utils.reset_generation_key') + def test_update_metric(self, mocker, mock_reset_generation_key): + mocker.get(self.github_url, text=json.dumps([{'id': i} for i in range(10)])) + management.call_command('update_metrics', verbosity=0) + self.assertTrue(mock_reset_generation_key.called) + data = GithubItemCountMetric.objects.last().data.last() + self.assertEqual(data.measurement, 10) |
