@@ -469,6 +469,51 @@ def test_update_electricity_statistics(self, now_mock):
469
469
self .assertEqual (stats .highest_return_l2_timestamp , reading_timestamp )
470
470
self .assertEqual (stats .highest_return_l3_timestamp , reading_timestamp )
471
471
472
+ @mock .patch ('django.utils.timezone.now' )
473
+ def test_update_electricity_statistics_single_phase (self , now_mock ):
474
+ now_mock .return_value = timezone .make_aware (timezone .datetime (2018 , 1 , 1 , hour = 0 ))
475
+ stats = ElectricityStatistics .get_solo ()
476
+ self .assertIsNone (stats .highest_usage_l1_value )
477
+ self .assertIsNone (stats .highest_usage_l2_value )
478
+ self .assertIsNone (stats .highest_usage_l3_value )
479
+ self .assertIsNone (stats .highest_return_l1_value )
480
+ self .assertIsNone (stats .highest_return_l2_value )
481
+ self .assertIsNone (stats .highest_return_l3_value )
482
+
483
+ # This has to differ, to make sure the right timestamp is used.
484
+ reading_timestamp = timezone .now ()
485
+ reading = DsmrReading .objects .create (
486
+ timestamp = reading_timestamp ,
487
+ electricity_delivered_1 = 0 ,
488
+ electricity_returned_1 = 0 ,
489
+ electricity_delivered_2 = 0 ,
490
+ electricity_returned_2 = 0 ,
491
+ electricity_currently_delivered = 0.6 ,
492
+ electricity_currently_returned = 1.6 ,
493
+ phase_currently_delivered_l1 = 0.1 ,
494
+ phase_currently_returned_l1 = 1.1 ,
495
+ )
496
+
497
+ # Alter time, processing of reading is later.
498
+ now_mock .return_value = timezone .make_aware (timezone .datetime (2018 , 1 , 1 , hour = 12 ))
499
+ self .assertNotEqual (reading_timestamp , timezone .now ())
500
+ dsmr_stats .services .update_electricity_statistics (reading = reading )
501
+
502
+ # Should be updated now.
503
+ stats = ElectricityStatistics .get_solo ()
504
+ self .assertEqual (stats .highest_usage_l1_value , Decimal ('0.100' ))
505
+ self .assertEqual (stats .highest_usage_l2_value , None )
506
+ self .assertEqual (stats .highest_usage_l3_value , None )
507
+ self .assertEqual (stats .highest_return_l1_value , Decimal ('1.100' ))
508
+ self .assertEqual (stats .highest_return_l2_value , None )
509
+ self .assertEqual (stats .highest_return_l3_value , None )
510
+ self .assertEqual (stats .highest_usage_l1_timestamp , reading_timestamp )
511
+ self .assertEqual (stats .highest_usage_l2_timestamp , None )
512
+ self .assertEqual (stats .highest_usage_l3_timestamp , None )
513
+ self .assertEqual (stats .highest_return_l1_timestamp , reading_timestamp )
514
+ self .assertEqual (stats .highest_return_l2_timestamp , None )
515
+ self .assertEqual (stats .highest_return_l3_timestamp , None )
516
+
472
517
473
518
class TestServicesWithoutGas (TestServices ):
474
519
fixtures = ['dsmr_stats/electricity-consumption.json' ]
0 commit comments