def test_create_parameter_groups_using_stored_settings_no_settings(): 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() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, mock_connect) stored_settings = ExportToFieldLogger.update_stored_settings(parameter_groups) assert stored_settings == []
def test_create_parameter_groups_using_stored_settings(): stored_settings = [(0, ((u'parameter_list', [u'p1.u1;it1:h1, p2.u2;it2:h2']), (u'key0_2', u'value0_2'))), (1, ((u'location_suffix', u'value1_1'), (u'key1_2', u'value1_2')))] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, mock_connect) stored_settings = create_test_string(ExportToFieldLogger.update_stored_settings(parameter_groups)) reference = u'[[0, ((parameter_list, [p1.u1;it1:h1, p2.u2;it2:h2]))], [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': (None, None)} tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'parameter_list', [u'p1.u1;it1:h1 ']), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj')))] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, mock_connect) parameter_groups[0]._obsid_list.addItems([u'1']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = create_test_string(printlist) mock_MessagebarAndLog.critical.assert_called_with(bar_msg=u'Critical: Obsid 1 did not have lat-lon coordinates. Check obs_points table')
def test_create_export_printlist_assert_empty_parameter_list(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {u'1': (None, None)} tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'final_parameter_name', u'par1'), (u'sublocation_suffix', u'group'), (u'location_suffix', u'proj')))] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, mock_connect) parameter_groups[0]._obsid_list.addItems([u'1']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = create_test_string(printlist) mock_MessagebarAndLog.warning.assert_called_with(bar_msg=u'Warning: Empty parameter list for group nr 1')
def test_create_export_printlist_not_same_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'parameter_list', [u'par1;type1;hint1']), (u'sublocation_suffix', u'group1'), (u'location_suffix', u'proj'))), (1, ((u'parameter_list', [u'par2;type2;hint2']), (u'sublocation_suffix', u'group2'), (u'location_suffix', u'proj')))] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, mock_connect) parameter_groups[0]._obsid_list.addItems([u'1', u'4']) parameter_groups[1]._obsid_list.addItems([u'2', u'3', u'4']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = create_test_string(printlist) reference_string = u'[FileVersion 1;2, NAME;INPUTTYPE;HINT, par1;type1;hint1 , par2;type2;hint2 , NAME;SUBNAME;LAT;LON;INPUTFIELD, 1.proj;1.proj.group1;lat1;lon1;par1, 2.proj;2.proj.group2;lat2;lon2;par2, 4.proj;4.proj.group1;lat4;lon4;par1, 4.proj;4.proj.group2;lat4;lon4;par2]' assert reference_string == test_string
def test_create_export_printlist_duplicate_sub_location_suffixes(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'parameter_list', [u'par1;type1;hint1']), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'))), (1, ((u'parameter_list', [u'par2;type2;hint2']), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj')))] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, mock_connect) parameter_groups[0]._obsid_list.addItems([u'1']) parameter_groups[1]._obsid_list.addItems([u'1']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = printlist assert test_string is None assert call.critical(bar_msg=u'Critical: Combination of obsid, locationsuffix and sublocation suffix must be unique') in mock_MessagebarAndLog.mock_calls
def test_create_export_printlist_assert_no_critical_msg(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {u'1': (123, 465), u'2': (123, 465), u'3': (123, 465)} stored_settings = [(0, ((u'parameter_list', [u'p1.u1;it1:h1', u'l.comment;test;make a comment']), (u'location_suffix', u'ls'), (u'sublocation_suffix', u'with_p1_u1_and_l_comment'))), (1, ((u'parameter_list', [u'comment;test;make a general comment']), (u'location_suffix', u'ls'), (u'sublocation_suffix', u'with_comment')))] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, mock_connect) parameter_groups[0]._obsid_list.addItems([u'1', u'2', u'3']) parameter_groups[1]._obsid_list.addItems([u'1', u'2', u'3']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = create_test_string(printlist) mock_MessagebarAndLog.critical.assert_not_called() reference_string = u'[FileVersion 1;3, NAME;INPUTTYPE;HINT, p1.u1;it1:h1 , l.comment;test;make a comment , comment;test;make a general comment , NAME;SUBNAME;LAT;LON;INPUTFIELD, 1.ls;1.ls.with_comment;123;465;comment, 1.ls;1.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment, 2.ls;2.ls.with_comment;123;465;comment, 2.ls;2.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment, 3.ls;3.ls.with_comment;123;465;comment, 3.ls;3.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment]' assert test_string == reference_string