Skip to content

Commit

Permalink
Fixing error on points_hz template tag for uninitialized user.
Browse files Browse the repository at this point in the history
* Implemented initial test cases.
* Update .travis.yml to install required SQLite packages for testing.
  • Loading branch information
audaciouscode committed Aug 1, 2017
1 parent f6805be commit dab1845
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -12,6 +12,9 @@ service:

addons:
postgresql: 9.5
apt:
packages:
- libsqlite3-mod-spatialite

before_install:
- export PYTHONPATH=$HOME/builds/audaciouscode/pdk
Expand Down
5 changes: 4 additions & 1 deletion models.py
Expand Up @@ -41,7 +41,10 @@ def install_supports_jsonfield():
global DB_SUPPORTS_JSON # pylint: disable=global-statement

if True and DB_SUPPORTS_JSON is None:
DB_SUPPORTS_JSON = connection.pg_version >= 90400
try:
DB_SUPPORTS_JSON = connection.pg_version >= 90400
except AttributeError:
DB_SUPPORTS_JSON = False

return DB_SUPPORTS_JSON

Expand Down
2 changes: 2 additions & 0 deletions templates/tests/point_hz_test.txt
@@ -0,0 +1,2 @@
{% load passive_data_kit %}
{% point_hz source %}
3 changes: 3 additions & 0 deletions templatetags/passive_data_kit.py
Expand Up @@ -99,6 +99,9 @@ def render(self, context):

frequency = source.point_frequency()

if frequency is None:
frequency = 0

value = "{:10.3f}".format(frequency) + " Hz"

if frequency < 1.0:
Expand Down
20 changes: 20 additions & 0 deletions test_templatetags.py
@@ -0,0 +1,20 @@
from django.template.loader import render_to_string
from django.test import TestCase

from .models import DataSource

class PointsHzTestCase(TestCase):
def setUp(self):
DataSource.objects.create(name='PointsHz Test User', identifier='points-hz-test')

def test_tests_working(self):
context = {
'source': DataSource.objects.get(identifier='points-hz-test')
}

result = render_to_string('tests/point_hz_test.txt', context)

self.assertEqual('<span data-toggle="tooltip" data-placement="top" title=" 0.000 samples per week"> 0.000 mHz</span>', result.strip())

def tearDown(self):
DataSource.objects.get(identifier='points-hz-test').delete()
4 changes: 4 additions & 0 deletions travis_settings.py
Expand Up @@ -72,6 +72,10 @@
}
}

if 'test' in sys.argv or 'test_coverage' in sys.argv: #Covers regular testing and django-coverage
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.spatialite'
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

Expand Down

0 comments on commit dab1845

Please sign in to comment.