Skip to content

Commit

Permalink
Merged v1.4.1 into master.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Dec 12, 2016
1 parent 7aee10e commit aa3ffe1
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Changelog
=========


v1.4.1 - 2016-12-12
^^^^^^^^^^^^^^^^^^^
- Consumption chart hangs due to unique_key violation (`#174 <https://github.com/dennissiemensma/dsmr-reader/issues/174>`_).
- NoReverseMatch at / Reverse for 'docs' (`#175 <https://github.com/dennissiemensma/dsmr-reader/issues/175>`_).


v1.4.0 - 2016-11-28
^^^^^^^^^^^^^^^^^^^
- Push notifications for Notify My Android / Prowl (iOS), written by Jeroen Peters (`#152 <https://github.com/dennissiemensma/dsmr-reader/issues/152>`_).
Expand Down
1 change: 1 addition & 0 deletions docs/credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Testers & contributors
- `Gert Schaafsma <https://www.linkedin.com/in/gertschaafsma>`_
- `Bert-Jan Vos <https://www.linkedin.com/in/bert-jan-vos-82011712>`_
- Sevickson (`Github profile <https://github.com/sevickson>`_)
- Koen Volleberg (`Github profile <https://github.com/kvolleberg>`_)


DSMR help
Expand Down
2 changes: 1 addition & 1 deletion dsmr_consumption/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def compact(dsmr_reading):

# Electricity should be unique, because it's the reading with the lowest interval anyway.
if grouping_type == ConsumptionSettings.COMPACTOR_GROUPING_BY_READING:
ElectricityConsumption.objects.create(
ElectricityConsumption.objects.get_or_create(
read_at=dsmr_reading.timestamp,
delivered_1=dsmr_reading.electricity_delivered_1,
returned_1=dsmr_reading.electricity_returned_1,
Expand Down
23 changes: 23 additions & 0 deletions dsmr_consumption/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ def test_processing(self):
else:
self.assertEqual(GasConsumption.objects.count(), 0)

def test_duplicate_processing(self):
""" Duplicate readings should not crash the compactor when not grouping. """
# Default is grouping by minute, so make sure to revert that here.
consumption_settings = ConsumptionSettings.get_solo()
consumption_settings.compactor_grouping_type = ConsumptionSettings.COMPACTOR_GROUPING_BY_READING
consumption_settings.save()

# Just duplicate one, as it will cause: IntegrityError UNIQUE constraint failed: ElectricityConsumption.read_at
duplicate_reading = DsmrReading.objects.all()[0]
duplicate_reading.pk = None
duplicate_reading.save()

dsmr_consumption.services.compact_all()

self.assertTrue(DsmrReading.objects.processed().exists())
self.assertFalse(DsmrReading.objects.unprocessed().exists())
self.assertEqual(ElectricityConsumption.objects.count(), 3)

if self.support_gas_readings:
self.assertEqual(GasConsumption.objects.count(), 2)
else:
self.assertEqual(GasConsumption.objects.count(), 0)

@mock.patch('django.utils.timezone.now')
def test_grouping(self, now_mock):
""" Test grouping per minute, instead of the default 10-second interval. """
Expand Down
21 changes: 21 additions & 0 deletions dsmr_frontend/migrations/0009_docs_no_reverse_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations


def convert_notifications(apps, schema_editor):
""" Fixes any broken URL's in pending migrations due to: NoReverseMatch at / Reverse for 'docs' #175. """
Notification = apps.get_model('dsmr_frontend', 'Notification')
Notification.objects.filter(redirect_to='frontend:docs').update(redirect_to='frontend:docs-redirect')


class Migration(migrations.Migration):

dependencies = [
('dsmr_frontend', '0008_merge_electricity_tariffs_notification'),
]

operations = [
migrations.RunPython(convert_notifications),
]
41 changes: 41 additions & 0 deletions dsmr_frontend/tests/regression/test_renamed_docs_reverse_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.db.migrations.executor import MigrationExecutor
from django.core.urlresolvers import reverse, NoReverseMatch
from django.test import TestCase, Client
from django.db import connection
from django.apps import apps

from dsmr_frontend.models.message import Notification
from django.db.migrations.recorder import MigrationRecorder


class TestRegression(TestCase):
"""
Regression for: NoReverseMatch at / Reverse for 'docs' #175.
Thanks to: https://www.caktusgroup.com/blog/2016/02/02/writing-unit-tests-django-migrations/
"""

@property
def app(self):
return apps.get_containing_app_config(type(self).__module__).name

def setUp(self):
self.client = Client()

def test_no_reverse_match_docs(self):
""" Test whether the docs URL in old notfications are converted to their new location. """
Notification.objects.create(
message='Fake',
redirect_to='frontend:docs', # Non-existing legacy.
)

with self.assertRaises(NoReverseMatch):
# This SHOULD crash.
self.client.get(reverse('frontend:dashboard'))

# Now we fake applying the migration (again for this test).
MigrationRecorder.Migration.objects.filter(app='dsmr_frontend', name='0009_docs_no_reverse_match').delete()
MigrationExecutor(connection=connection).migrate([(self.app, '0009_docs_no_reverse_match')])

# The error should be fixed now.
response = self.client.get(reverse('frontend:dashboard'))
self.assertEqual(response.status_code, 200)
2 changes: 1 addition & 1 deletion dsmrreader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
from django.utils.version import get_version


VERSION = (1, 4, 0, 'final', 0)
VERSION = (1, 4, 1, 'final', 0)

__version__ = get_version(VERSION)
Binary file modified dsmrreader/locales/nl/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion dsmrreader/locales/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: DSMR Reader\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-11-28 18:49+0100\n"
"POT-Creation-Date: 2016-12-12 21:17+0100\n"
"PO-Revision-Date: 2016-11-27 17:57+0100\n"
"Last-Translator: Dennis Siemensma <dsmr@dennissiemensma.nl>\n"
"Language-Team: Dennis Siemensma <dsmr@dennissiemensma.nl>\n"
Expand Down

0 comments on commit aa3ffe1

Please sign in to comment.