Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding ability to disable collection

  • Loading branch information...
commit 1a76ee3ad0bf587f440da8249295a65052ad834d 1 parent 26261c9
Frank Wiles authored
21 app_metrics/tests/base_tests.py
@@ -92,12 +92,29 @@ def test_yearly_aggregation(self):
92 92 self.assertEqual(year1.num, 2)
93 93 self.assertEqual(year2.num, 3)
94 94
  95 +class DisabledTests(TestCase):
  96 + """ Test disabling collection """
  97 +
  98 + def setUp(self):
  99 + super(DisabledTests, self).setUp()
  100 + self.old_disabled = getattr(settings, 'APP_METRICS_DISABLED', False)
  101 + settings.APP_METRICS_DISABLED = True
  102 + self.metric1 = create_metric(name='Test Disable', slug='test_disable')
  103 +
  104 + def test_disabled(self):
  105 + self.assertEqual(MetricItem.objects.filter(metric__slug='test_disable').count(), 0)
  106 + settings.APP_METRICS_DISABLE = True
  107 + metric('test_disable')
  108 + self.assertEqual(MetricItem.objects.filter(metric__slug='test_disable').count(), 0)
  109 +
  110 + def tearDown(self):
  111 + settings.APP_METRICS_DISABLED = self.old_disabled
  112 + super(DisabledTests, self).tearDown()
  113 +
95 114 class TrendingTests(TestCase):
96 115 """ Test that our trending logic works """
97 116
98 117 def setUp(self):
99   - #self.user1 = User.objects.create_user('user1', 'user1@example.com', 'user1pass')
100   - #self.user2 = User.objects.create_user('user2', 'user2@example.com', 'user2pass')
101 118 self.metric1 = create_metric(name='Test Trending1', slug='test_trend1')
102 119 self.metric2 = create_metric(name='Test Trending2', slug='test_trend2')
103 120
6 app_metrics/tests/settings.py
@@ -2,6 +2,11 @@
2 2 DATABASE_NAME='test_app_metrics'
3 3 SITE_ID = 1
4 4 DEBUG = True
  5 +TEST_RUNNER = 'django_coverage.coverage_runner.CoverageRunner'
  6 +COVERAGE_MODULE_EXCLUDES = [
  7 + 'tests$', 'settings$', 'urls$',
  8 + 'common.views.test', '__init__', 'django',
  9 + 'migrations', 'djcelery']
5 10
6 11 INSTALLED_APPS = [
7 12 'django.contrib.admin',
@@ -20,3 +25,4 @@
20 25
21 26 APP_METRICS_BACKEND = 'app_metrics.backends.db'
22 27 APP_METRICS_MIXPANEL_TOKEN = None
  28 +APP_METRICS_DISABLED = False
2  setup.py
@@ -26,7 +26,7 @@
26 26 'celery',
27 27 'django-celery',
28 28 ],
29   - tests_require = ['mock'],
  29 + tests_require = ['mock', 'django-coverage', 'coverage'],
30 30 classifiers=[
31 31 'Development Status :: 4 - Beta',
32 32 'Environment :: Web Environment',

0 comments on commit 1a76ee3

Please sign in to comment.
Something went wrong with that request. Please try again.