Skip to content
Snippets Groups Projects
Commit 7c0a4e16 authored by wactbprot's avatar wactbprot
Browse files

overwrite entry if result.Value length is > 1, +unittests

parent 0e3d67e4
No related branches found
No related tags found
No related merge requests found
......@@ -204,10 +204,18 @@ class DB(System):
found = False
for entr in doc[last_entr]:
if entr.get('Type') == result.get('Type'):
found = True
if isinstance(result.get('Value'), list) and len(result.get('Value')) > 1:
entr = result # override
self.log.debug("value is list an length > 1, overwrite")
entr['Value'] = result.get('Value') # override
entr['Unit'] = result.get('Unit')
if result.get('SdValue'):
if entr.get('SdValue'):
entr['SdValue'] = result['SdValue']
if result.get('N'):
if entr.get('N'):
entr['N'] = result['N']
else:
found = True
entr['Value'].append( result['Value'] )
entr['Unit'] = result['Unit']
if result.get('SdValue'):
......
......@@ -46,8 +46,23 @@ class TestDB(unittest.TestCase):
self.db.doc_write_result(doc, doc_path="Calibration.Measurement.AuxValues.Pressure", result={"Type":"offset_x1", "Value":[1,2,3], "Unit":"Pa"})
self.db.doc_write_result(doc, doc_path="Calibration.Measurement.AuxValues.Pressure", result={"Type":"offset_x0.1", "Value":[4,5,6], "Unit":"Pa"})
self.db.doc_write_result(doc, doc_path="Calibration.Measurement.AuxValues.Pressure", result={"Type":"offset_x0.01", "Value":[7,8,9], "Unit":"Pa"})
auxvalues = doc.get('Calibration').get('Measurement', {}).get('AuxValues', {}).get('Pressure', {})
self.assertEqual(len(auxvalues), 4)
self.assertEqual(auxvalues[1].get('Value')[2], 3)
self.assertEqual(auxvalues[2].get('Value')[2], 6)
self.assertEqual(auxvalues[3].get('Value')[2], 9)
pressure = doc.get('Calibration').get('Measurement', {}).get('AuxValues', {}).get('Pressure', {})
self.assertEqual(len(pressure), 4)
self.assertEqual(pressure[1].get('Value')[2], 3)
self.assertEqual(pressure[2].get('Value')[2], 6)
self.assertEqual(pressure[3].get('Value')[2], 9)
def test_doc_write_result_5(self):
"""should override if len(value) > 1
"""
doc = {'Calibration': {'Measurement': {'AuxValues': {}}}}
self.db.doc_write_result(doc, doc_path="Calibration.Measurement.AuxValues.Pressure", result={"Type":"offset_x0.1", "Value":[1,2,3], "Unit":"Pa"})
self.db.doc_write_result(doc, doc_path="Calibration.Measurement.AuxValues.Pressure", result={"Type":"offset_x0.1", "Value":[4,5,6], "Unit":"Pa"})
pressure = doc.get('Calibration').get('Measurement', {}).get('AuxValues', {}).get('Pressure', {})
self.assertEqual(len(pressure), 1)
self.assertEqual(pressure[0].get('Value')[2], 6)
self.db.doc_write_result(doc, doc_path="Calibration.Measurement.AuxValues.Pressure", result={"Type":"offset_x0.1", "Value":[7,8,9], "Unit":"Pa"})
pressure = doc.get('Calibration').get('Measurement', {}).get('AuxValues', {}).get('Pressure', {})
self.assertEqual(len(pressure), 1)
self.assertEqual(pressure[0].get('Value')[2], 9)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment