Skip to content

Commit d9109e1

Browse files
API voor live gas verbruik #562
1 parent e35d271 commit d9109e1

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

dsmr_api/tests/v2/test_consumption.py

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def test_get(self, now_mock):
7373
class GasLive(APIv2TestCase):
7474
@mock.patch('django.utils.timezone.now')
7575
def test_get(self, now_mock):
76+
# Without gas.
77+
result = self._request('gas-live')
78+
self.assertEqual(result, {})
79+
7680
now_mock.return_value = timezone.make_aware(timezone.datetime(2019, 4, 20))
7781
GasConsumption.objects.create(**{
7882
"read_at": "2019-04-19T12:00:00+02:00",

dsmr_api/tests/v2/test_generic.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from django.db.migrations.executor import MigrationExecutor
1+
from django.contrib.auth.models import User
22
from django.urls.base import reverse
3-
from django.db import connection
43
from django.apps import apps
54

65
from dsmr_api.models import APISettings
@@ -34,11 +33,7 @@ def app(self):
3433

3534
def test_user_does_not_exist(self):
3635
""" Tests what happens when the API user was not created. """
37-
if connection.vendor == 'sqlite': # pragma: no cover
38-
return self.skipTest(reason='SQLite cannot be used while foreign key constraint checks are enabled')
39-
40-
# Roll back migration creating the API user.
41-
MigrationExecutor(connection=connection).migrate([(self.app, '0002_generate_random_auth_key')])
36+
User.objects.all().delete()
4237

4338
response = self.client.get(
4439
reverse('{}:dsmrreading'.format(self.NAMESPACE)),

dsmr_consumption/services.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,7 @@ def live_gas_consumption():
341341
# Don't even bother when no data available.
342342
return data
343343

344-
latest_timestamp = timezone.localtime(latest_data.read_at)
345-
346-
# In case the smart meter is running a clock in the future.
347-
if latest_timestamp > timezone.now():
348-
latest_timestamp = timezone.now()
349-
350-
data['timestamp'] = latest_timestamp
344+
data['timestamp'] = timezone.localtime(latest_data.read_at)
351345
data['currently_delivered'] = latest_data.currently_delivered
352346

353347
try:

0 commit comments

Comments
 (0)