diff --git a/.travis.yml b/.travis.yml index 4ffc702..42a313c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,9 @@ service: addons: postgresql: 9.5 + apt: + packages: + - libsqlite3-mod-spatialite before_install: - export PYTHONPATH=$HOME/builds/audaciouscode/pdk diff --git a/models.py b/models.py index b7123f1..6a610db 100644 --- a/models.py +++ b/models.py @@ -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 diff --git a/templates/tests/point_hz_test.txt b/templates/tests/point_hz_test.txt new file mode 100644 index 0000000..8434d47 --- /dev/null +++ b/templates/tests/point_hz_test.txt @@ -0,0 +1,2 @@ +{% load passive_data_kit %} +{% point_hz source %} \ No newline at end of file diff --git a/templatetags/passive_data_kit.py b/templatetags/passive_data_kit.py index 0464dc5..14c5059 100644 --- a/templatetags/passive_data_kit.py +++ b/templatetags/passive_data_kit.py @@ -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: diff --git a/test_templatetags.py b/test_templatetags.py new file mode 100644 index 0000000..91e6254 --- /dev/null +++ b/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(' 0.000 mHz', result.strip()) + + def tearDown(self): + DataSource.objects.get(identifier='points-hz-test').delete() diff --git a/travis_settings.py b/travis_settings.py index dbbcc29..16140d2 100644 --- a/travis_settings.py +++ b/travis_settings.py @@ -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/