Skip to content

Commit

Permalink
exclude migrations from testing
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Dec 28, 2021
1 parent d02b381 commit 3bfb2ad
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[run]
omit =
*virtualenvs*,
*migrations*,
*site-packages*
include = admin_tools_stats*
plugins =
django_coverage_plugin
Expand Down
16 changes: 16 additions & 0 deletions admin_tools_stats/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.test import TestCase
from model_mommy import mommy

from admin_tools_stats.forms import ChartSettingsForm


class ChartSettingsFormTests(TestCase):

def test_operations_list(self):
stats = mommy.make(
'DashboardStats',
allowed_type_operation_field_name=['Sum', 'Count'],
operation_field_name="auth,user",
)
ch = ChartSettingsForm(stats)
self.assertEqual(ch.fields['select_box_operation_field'].choices, [('', '(divide all)'), ('auth', 'auth'), ('user', 'user')])
13 changes: 10 additions & 3 deletions admin_tools_stats/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#
import datetime

import django
from django.test.utils import override_settings
from django.urls import reverse
from model_mommy import mommy
Expand Down Expand Up @@ -64,11 +65,14 @@ def test_get_charts_query(self):
a = AnalyticsView()
a.request = self.client.request()
a.request.user = mommy.make("User", is_superuser=True)
self.assertQuerysetEqual(a.get_charts_query(), ['<DashboardStats: kid_graph>', '<DashboardStats: user_graph>'])
if django.VERSION > (3, 2):
self.assertQuerysetEqual(a.get_charts_query(), [self.kid_stats, self.stats])
else:
self.assertQuerysetEqual(a.get_charts_query(), ['<DashboardStats: kid_graph>', '<DashboardStats: user_graph>'])

def test_get_charts_query_usser(self):
a = AnalyticsView()
mommy.make(
kid_graph_user = mommy.make(
'DashboardStats',
graph_title="Kid chart",
date_field_name="birthday",
Expand All @@ -79,7 +83,10 @@ def test_get_charts_query_usser(self):
)
a.request = self.client.request()
a.request.user = mommy.make("User")
self.assertQuerysetEqual(a.get_charts_query(), ['<DashboardStats: kid_graph_user>'])
if django.VERSION > (3, 2):
self.assertQuerysetEqual(a.get_charts_query(), [kid_graph_user])
else:
self.assertQuerysetEqual(a.get_charts_query(), ['<DashboardStats: kid_graph_user>'])

def test_get_templates_names(self):
a = AnalyticsView()
Expand Down
8 changes: 4 additions & 4 deletions admin_tools_stats/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,22 @@ def setUp(self):

def test_clean_error_model_app_app_name(self):
stats = mommy.make('DashboardStats', model_name="User1", model_app_name="auth1", graph_key="error_graph")
with self.assertRaisesRegexp(ValidationError, "model_name.*No installed app with label"):
with self.assertRaisesRegex(ValidationError, "model_name.*No installed app with label"):
stats.clean()

def test_clean_error_model_name(self):
stats = mommy.make('DashboardStats', model_name="User1", model_app_name="auth", graph_key="error_graph")
with self.assertRaisesRegexp(ValidationError, "model_name.*App 'auth' doesn't have a 'User1' model."):
with self.assertRaisesRegex(ValidationError, "model_name.*App 'auth' doesn't have a 'User1' model."):
stats.clean()

def test_clean_error_operation_field(self):
stats = mommy.make('DashboardStats', model_name="User", model_app_name="auth", graph_key="error_graph", operation_field_name='asdf')
with self.assertRaisesRegexp(ValidationError, "operation_field_name.*Cannot resolve keyword 'asdf' into field. Choices are:"):
with self.assertRaisesRegex(ValidationError, "operation_field_name.*Cannot resolve keyword 'asdf' into field. Choices are:"):
stats.clean()

def test_clean_error_date_field(self):
stats = mommy.make('DashboardStats', model_name="User", model_app_name="auth", graph_key="error_graph", date_field_name='asdf')
with self.assertRaisesRegexp(ValidationError, "date_field_name.*Cannot resolve keyword 'asdf' into field. Choices are:"):
with self.assertRaisesRegex(ValidationError, "date_field_name.*Cannot resolve keyword 'asdf' into field. Choices are:"):
stats.clean()

@skipIf(settings.DATABASES['default']['ENGINE'] == 'django.db.backends.mysql', 'no support of USE_TZ=False in mysql')
Expand Down
1 change: 0 additions & 1 deletion demoproject/demoproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
Expand Down

0 comments on commit 3bfb2ad

Please sign in to comment.