From 906eb84b1c67048e5bc672369b2e90cd72a80bce Mon Sep 17 00:00:00 2001
From: Mattia Mancini <mancini@astron.nl>
Date: Wed, 10 Oct 2018 13:54:40 +0000
Subject: [PATCH] OSB-28: implemented first database tests

---
 .gitattributes                                |  1 +
 .../monitoringdb/tests/__init__.py            |  2 +-
 .../monitoringdb/tests/t_django_insert.py     | 38 +++++++++++++++++++
 .../tests/t_stationtest_model_creation.py     |  1 +
 .../tests/t_stationtest_parser.py             |  2 -
 5 files changed, 41 insertions(+), 3 deletions(-)
 create mode 100644 LCU/Maintenance/DBInterface/monitoringdb/tests/t_django_insert.py

diff --git a/.gitattributes b/.gitattributes
index f8c79e2ac43..75b2fda7be0 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1826,6 +1826,7 @@ LCU/Maintenance/DBInterface/monitoringdb/station_test_raw_parser.py -text
 LCU/Maintenance/DBInterface/monitoringdb/tests/__init__.py -text
 LCU/Maintenance/DBInterface/monitoringdb/tests/common.py -text
 LCU/Maintenance/DBInterface/monitoringdb/tests/old_tests.py -text
+LCU/Maintenance/DBInterface/monitoringdb/tests/t_django_insert.py -text
 LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_model_creation.py -text
 LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_parser.py -text
 LCU/Maintenance/DBInterface/monitoringdb/tests/test_generic_stationtestdata.csv -text
diff --git a/LCU/Maintenance/DBInterface/monitoringdb/tests/__init__.py b/LCU/Maintenance/DBInterface/monitoringdb/tests/__init__.py
index a23cebb546d..c54420b6cdc 100644
--- a/LCU/Maintenance/DBInterface/monitoringdb/tests/__init__.py
+++ b/LCU/Maintenance/DBInterface/monitoringdb/tests/__init__.py
@@ -1 +1 @@
-__all__ = ['t_stationtest_model_creation', 't_stationtest_parser']
\ No newline at end of file
+__all__ = ['t_stationtest_model_creation', 't_stationtest_parser', 't_django_insert']
\ No newline at end of file
diff --git a/LCU/Maintenance/DBInterface/monitoringdb/tests/t_django_insert.py b/LCU/Maintenance/DBInterface/monitoringdb/tests/t_django_insert.py
new file mode 100644
index 00000000000..b0561c23646
--- /dev/null
+++ b/LCU/Maintenance/DBInterface/monitoringdb/tests/t_django_insert.py
@@ -0,0 +1,38 @@
+from django.test import TestCase
+
+import lofar.maintenance.django_postgresql.settings as settings
+
+import lofar.maintenance.monitoringdb.serializers.component_error as component_error
+from lofar.maintenance.monitoringdb.models.station import Station
+from lofar.maintenance.monitoringdb.models.station_test import StationTest
+from datetime import datetime
+
+from lofar.maintenance.monitoringdb.models.component_error import ComponentError
+
+
+class TestStationTestInsert(TestCase):
+    def test_insert_station_test_no_component_errors(self):
+        pass
+
+
+class TestComponentErrorInsert(TestCase):
+    def test_insert_component_error_with_details(self):
+
+        station_entry = Station(location='Here', name='CS001C', type='C')
+        station_entry.save()
+        station_test_entry = StationTest(start_datetime=datetime(2017, 4, 12, 0,0,0),
+                                         end_datetime=datetime(2017, 4, 12, 1,0,0),
+                                         checks='Some checks',
+                                         station=station_entry
+                                         )
+        station_test_entry.save()
+        test_data = {'component': {'component_id': 50, 'type': 'LBL'}, 'details': {'xoff': '11', 'yoff': '25', 'xval': 77.0, 'yval': 75.9}, 'type': 'DOWN'}
+
+        component_error_entry = component_error.ComponentErrorSerializer.insert_component_error(station_test_entry,
+                                                                        station_entry,
+                                                                        test_data)
+        component_error_entry.save()
+
+        id = component_error_entry.pk
+
+        print(ComponentError.objects.get(pk=id).details)
\ No newline at end of file
diff --git a/LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_model_creation.py b/LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_model_creation.py
index e198e8af583..ebb74d66956 100644
--- a/LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_model_creation.py
+++ b/LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_model_creation.py
@@ -10,5 +10,6 @@ class TestStationTestModelCreation(unittest.TestCase):
             result = raw_parser.dict_from_raw_station_test(test)
             print(result)
 
+
 if __name__ == '__main__':
     unittest.main()
\ No newline at end of file
diff --git a/LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_parser.py b/LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_parser.py
index 039e4ae7009..0932b463468 100644
--- a/LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_parser.py
+++ b/LCU/Maintenance/DBInterface/monitoringdb/tests/t_stationtest_parser.py
@@ -2,9 +2,7 @@ import unittest
 
 from .common import *
 
-
 class TestStationTestsParser(unittest.TestCase):
-
     def test_element_error_details_parsing(self):
         preparsed_element_error = ['20180508', 'HBA', '044', 'E_FAIL',
                                    {'x1': '99.5 140 101.6 99.8 140 102.4'},
-- 
GitLab