Skip to content

Commit

Permalink
code style fixes, enable flake8 in Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Jan 31, 2020
1 parent de04853 commit 3467210
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cache:
install:
- pip install 'coverage<4' # coverage>=4 has issues with python3
- pip install -q $DJANGO_VERSION
- pip install -q coveralls
- pip install -q coveralls flake8
- pip install -r demoproject/requirements.txt
- pip install -r requirements.txt

Expand All @@ -40,6 +40,7 @@ before_cache:
- rm -f $HOME/.cache/pip/log/debug.log

script:
- flake8
- django-admin --version
- python -Wall $VIRTUAL_ENV/bin/coverage run setup.py test

Expand Down
7 changes: 5 additions & 2 deletions admin_tools_stats/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#
from admin_tools_stats.app_label_renamer import AppLabelRenamer
from admin_tools_stats.models import DashboardStats, DashboardStatsCriteria

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from admin_tools_stats.models import DashboardStatsCriteria, DashboardStats
from admin_tools_stats.app_label_renamer import AppLabelRenamer
AppLabelRenamer(native_app_label=u'admin_tools_stats', app_label=_('Admin Tools Stats')).main()


Expand All @@ -25,6 +26,7 @@ class DashboardStatsCriteriaAdmin(admin.ModelAdmin):
ordering = ('id', )
save_as = True


admin.site.register(DashboardStatsCriteria, DashboardStatsCriteriaAdmin)


Expand All @@ -39,4 +41,5 @@ class DashboardStatsAdmin(admin.ModelAdmin):
ordering = ('id', )
save_as = True


admin.site.register(DashboardStats, DashboardStatsAdmin)
35 changes: 23 additions & 12 deletions admin_tools_stats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,21 @@ class DashboardStatsCriteria(models.Model):
**Name of DB table**: dash_stats_criteria
"""
criteria_name = models.CharField(max_length=90, db_index=True,
verbose_name=_('criteria name'),
help_text=_("it needs to be one word unique. Ex. status, yesno"))
criteria_name = models.CharField(
max_length=90, db_index=True,
verbose_name=_('criteria name'),
help_text=_("it needs to be one word unique. Ex. status, yesno"),
)
criteria_fix_mapping = jsonfield.fields.JSONField(
null=True, blank=True,
verbose_name=_("fixed criteria / value"),
help_text=_("a JSON dictionary of key-value pairs that will be used for the criteria"))
help_text=_("a JSON dictionary of key-value pairs that will be used for the criteria"),
)
dynamic_criteria_field_name = models.CharField(
max_length=90, blank=True, null=True,
verbose_name=_("dynamic criteria field name"),
help_text=_("ex. for call records - disposition"))
help_text=_("ex. for call records - disposition"),
)
criteria_dynamic_mapping = jsonfield.fields.JSONField(
null=True, blank=True,
verbose_name=_("dynamic criteria / value"),
Expand Down Expand Up @@ -192,33 +196,40 @@ class DashboardStats(models.Model):
graph_key = models.CharField(
unique=True, max_length=90,
verbose_name=_('graph identifier'),
help_text=_("it needs to be one word unique. ex. auth, mygraph"))
help_text=_("it needs to be one word unique. ex. auth, mygraph"),
)
graph_title = models.CharField(
max_length=90, db_index=True,
verbose_name=_('graph title'),
help_text=_("heading title of graph box"))
help_text=_("heading title of graph box"),
)
model_app_name = models.CharField(
max_length=90, verbose_name=_('app name'),
help_text=_("ex. auth / dialer_cdr"))
help_text=_("ex. auth / dialer_cdr"),
)
model_name = models.CharField(
max_length=90, verbose_name=_('model name'),
help_text=_("ex. User"))
help_text=_("ex. User"),
)
date_field_name = models.CharField(
max_length=90, verbose_name=_("date field name"),
help_text=_("ex. date_joined, invitation__invitation_date"),
)
user_field_name = models.CharField(
max_length=90, verbose_name=_("user field name"),
null=True, blank=True,
help_text=_("ex. owner, invitation__owner"))
help_text=_("ex. owner, invitation__owner"),
)
operation_field_name = models.CharField(
max_length=90, verbose_name=_("Operate field name"),
null=True, blank=True,
help_text=_("The field you want to aggregate, ex. amount, salaries__total_income"))
help_text=_("The field you want to aggregate, ex. amount, salaries__total_income"),
)
type_operation_field_name = models.CharField(
max_length=90, verbose_name=_("Choose Type operation"),
null=True, blank=True, choices=operation,
help_text=_("choose the type operation what you want to aggregate, ex. Sum"))
help_text=_("choose the type operation what you want to aggregate, ex. Sum"),
)
default_chart_type = models.CharField(
max_length=90,
verbose_name=_("Default chart type"),
Expand Down
22 changes: 12 additions & 10 deletions admin_tools_stats/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def tearDown(self):


class ModelTests(ClearCacheMixin, TestCase):
maxDiff=None
maxDiff = None

def setUp(self):
self.stats = mommy.make(
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_get_multi_series_dynamic_field_name(self):
criteria_dynamic_mapping={
"": [None, "All"],
"false": [False, "Inactive"],
"true": [True, "Active"]
"true": [True, "Active"],
},
use_as='multiple_series',
)
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_get_multi_series_dynamic_field_name_old_format(self):
dynamic_criteria_field_name="is_active",
criteria_dynamic_mapping={
"False": "Inactive",
"True": "Active"
"True": "Active",
},
use_as='multiple_series',
)
Expand Down Expand Up @@ -359,7 +359,7 @@ def test_get_multi_series_dynamic_criteria(self):
criteria_dynamic_mapping={
"": [None, "All"],
"false": [True, "Inactive"],
"true": [False, "Active"]
"true": [False, "Active"],
},
use_as='multiple_series',
id=5,
Expand All @@ -369,7 +369,11 @@ def test_get_multi_series_dynamic_criteria(self):
self.stats.refresh_from_db()
mommy.make('User', date_joined=datetime.datetime(2010, 10, 10, tzinfo=datetime.timezone.utc))
url = reverse('chart-data', kwargs={'graph_key': 'user_graph'})
url += "?time_since=2010-10-08&time_until=2010-10-12&select_box_interval=days&select_box_chart_type=discreteBarChart&select_box_multiple_series=5"
url += "?time_since=2010-10-08"
url += "&time_until=2010-10-12"
url += "&select_box_interval=days"
url += "&select_box_chart_type=discreteBarChart"
url += "&select_box_multiple_series=5"
response = self.client.get(url)
self.assertContains(response, ('"key": "Inactive"'))
self.assertContains(response, ('"key": "Active"'))
Expand All @@ -396,12 +400,11 @@ def setUp(self):
"CHANUNAVAIL": "CHANUNAVAIL",
"NOANSWER": "NOANSWER",
"CONGESTION": "CONGESTION",
"CANCEL": "CANCEL"
"CANCEL": "CANCEL",
},
)
self.dashboard_stats_criteria.save()
self.assertEqual(
self.dashboard_stats_criteria.__str__(), 'call_type')
self.assertEqual(self.dashboard_stats_criteria.__str__(), 'call_type')

# DashboardStats model
self.dashboard_stats = DashboardStats(
Expand All @@ -421,8 +424,7 @@ def setUp(self):
self.assertEqual(self.dashboard_stats.__str__(), 'user_graph_test')

def test_dashboard_criteria(self):
self.assertEqual(
self.dashboard_stats_criteria.criteria_name, "call_type")
self.assertEqual(self.dashboard_stats_criteria.criteria_name, "call_type")
self.assertEqual(self.dashboard_stats.graph_key, 'user_graph_test')

def teardown(self):
Expand Down
23 changes: 15 additions & 8 deletions admin_tools_stats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
# Arezqui Belaid <info@star2billing.com>
#

from django.contrib.auth.models import User
from django.test import TestCase, Client
from django.test.client import RequestFactory
import base64
import unittest
import inspect
import unittest

from django.contrib.auth.models import User
from django.test import Client, TestCase
from django.test.client import RequestFactory


def build_test_suite_from(test_cases):
Expand All @@ -35,8 +36,11 @@ def build_test_suite_from(test_cases):
for item in mod.__dict__.values():
if type(item) is type and issubclass(item, test_case):
tests.append(item)
test_suites.append(unittest.TestSuite(
map(unittest.TestLoader().loadTestsFromTestCase, tests)))
test_suites.append(
unittest.TestSuite(
map(unittest.TestLoader().loadTestsFromTestCase, tests),
),
)

return unittest.TestSuite(test_suites)

Expand All @@ -63,8 +67,11 @@ def setUp(self):

self.factory = RequestFactory()

def assertContainsAny(self, response, texts, status_code=200,
msg_prefix='', html=False):

def assertContainsAny(
self, response, texts, status_code=200,
msg_prefix='', html=False,
):
total_count = 0
for text in texts:
text_repr, real_count, msg_prefix = self._assert_contains(response, text, status_code, msg_prefix, html)
Expand Down
6 changes: 4 additions & 2 deletions admin_tools_stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ def get_context_data(self, *args, interval=None, graph_key=None, **kwargs):

tooltip_date_format, context['extra']['x_axis_format'] = interval_dateformat_map[interval]

extra_serie = {"tooltip": {"y_start": "", "y_end": ""},
"date_format": tooltip_date_format}
extra_serie = {
"tooltip": {"y_start": "", "y_end": ""},
"date_format": tooltip_date_format,
}

context['values'] = {
'x': xdata,
Expand Down

0 comments on commit 3467210

Please sign in to comment.