def test_create_export_objects_using_stored_settings_no_settings(): tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'key0_1', u'value0_1'), (u'key0_2', u'value0_2'))), (1, ((u'key1_1', u'value1_1'), (u'key1_2', u'value1_2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) stored_settings = ExportToFieldLogger.update_stored_settings(export_objects) assert stored_settings == []
def test_create_export_objects_using_stored_settings(): tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'final_parameter_name', u'value0_1'), (u'key0_2', u'value0_2'))), (1, ((u'location_suffix', u'value1_1'), (u'key1_2', u'value1_2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) stored_settings = create_test_string(ExportToFieldLogger.update_stored_settings(export_objects)) reference = u'[(0, ((final_parameter_name, value0_1))), (1, ((location_suffix, value1_1)))]' assert stored_settings == reference
def test_create_export_printlist_assert_no_latlon(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {u'1': (u'lat1', u'lon1'), u'2': (u'lat2', u'lon2'), u'4': (u'lat4', u'lon4')} tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'final_parameter_name', u'par1'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type1'), (u'hint', u'hint1'))), (1, ((u'final_parameter_name', u'par2'), (u'sublocation_suffix', u'proj2.group'), (u'location_suffix', u'proj2'), (u'input_type', u'type2'), (u'hint', u'hint2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) export_objects[0].obsid_list.addItems([u'1', u'4']) export_objects[1].obsid_list.addItems([u'2', u'3', u'4']) printlist = ExportToFieldLogger.create_export_printlist(export_objects) test_string = create_test_string(printlist) mock_MessagebarAndLog.critical.assert_called_with(bar_msg=u'Critical: Obsid did not have lat-lon coordinates. Check obs_points table')
def test_create_export_printlist(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {u'1': (u'lat1', u'lon1'), u'2': (u'lat2', u'lon2'), u'4': (u'lat4', u'lon4')} tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'final_parameter_name', u'par1'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type1'), (u'hint', u'hint1'))), (1, ((u'final_parameter_name', u'par2'), (u'sublocation_suffix', u'proj2.group'), (u'location_suffix', u'proj2'), (u'input_type', u'type2'), (u'hint', u'hint2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) export_objects[0].obsid_list.addItems([u'1', u'4']) export_objects[1].obsid_list.addItems([u'2', u'3', u'4']) printlist = ExportToFieldLogger.create_export_printlist(export_objects) test_string = create_test_string(printlist) reference_string = u'[FileVersion 1;2, NAME;INPUTTYPE;HINT, par1;type1;hint1, par2;type2;hint2, NAME;sublocation;LAT;LON;INPUTFIELD, 1.proj;1.proj.group;lat1;lon1;par1, 2.proj2;2.proj2.group;lat2;lon2;par2, 4.proj;4.proj.group;lat4;lon4;par1, 4.proj2;4.proj2.group;lat4;lon4;par2]' assert reference_string == test_string
def test_create_export_printlist_duplicate_parameters(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {u'1': (u'lat1', u'lon1')} tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'final_parameter_name', u'par1'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type1'), (u'hint', u'hint1'))), (1, ((u'final_parameter_name', u'par1'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type2'), (u'hint', u'hint2'))), (2, ((u'final_parameter_name', u'comment'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type2'), (u'hint', u'hint2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) export_objects[0].obsid_list.addItems([u'1']) export_objects[1].obsid_list.addItems([u'1']) test_string = create_test_string(ExportToFieldLogger.create_export_printlist(export_objects)) parameter = u'par1' mock_MessagebarAndLog.warning.assert_called_with(bar_msg=u"Warning: Parameter " + parameter + u' error. See log message panel', log_msg=u'The parameter ' + parameter + u' already exists. Only the first occurence one will be written to file.') reference_string = u'[FileVersion 1;2, NAME;INPUTTYPE;HINT, par1;type1;hint1, comment;type2;hint2, NAME;sublocation;LAT;LON;INPUTFIELD, 1.proj;1.proj.group;lat1;lon1;par1]' assert test_string == reference_string