8435: Crash when trying to link existing place as an enclosing place using P0001 number; added tests, updated Travis testing

This commit is contained in:
Doug Blank 2015-03-15 00:33:39 -04:00 committed by Ross Gammon
parent 7970b04113
commit 88c06d41fb
3 changed files with 80 additions and 1 deletions

View File

@ -21,5 +21,5 @@ install:
script: script:
- mkdir -p /home/travis/.gramps/grampsdb/ - mkdir -p /home/travis/.gramps/grampsdb/
- DJANGO_SETTINGS_MODULE=gramps.webapp.settings nosetests3 --exclude=TestcaseGenerator --exclude=exportvcard_test --exclude=plugins --exclude=vcard --exclude=merge_ref_test --exclude=test_util_test --exclude=gramps.webapp --exclude=test2_exec_CLI --exclude=widgets --exclude=gui --exclude=test3_files_in_import_dir --exclude=test_manual_run gramps - DJANGO_SETTINGS_MODULE=gramps.webapp.settings nosetests3 --exclude=TestcaseGenerator --exclude=exportvcard_test --exclude=plugins --exclude=vcard --exclude=merge_ref_test --exclude=test_util_test --exclude=gramps.webapp --exclude=test2_exec_CLI --exclude=widgets --exclude=test3_files_in_import_dir --exclude=test_manual_run gramps

View File

@ -271,6 +271,7 @@ class EditReference(ManagedWindow, DbGUIElement):
if new_id: if new_id:
old_primary = self.db.get_from_name_and_gramps_id(type, new_id) old_primary = self.db.get_from_name_and_gramps_id(type, new_id)
if old_primary: if old_primary:
description = None
if type == 'Event': if type == 'Event':
msg1 = _("Cannot save event. ID already exists.") msg1 = _("Cannot save event. ID already exists.")
description = old_primary.get_description() description = old_primary.get_description()
@ -280,6 +281,8 @@ class EditReference(ManagedWindow, DbGUIElement):
elif type == 'Repository': elif type == 'Repository':
msg1 = _("Cannot save repository. ID already exists.") msg1 = _("Cannot save repository. ID already exists.")
description = old_primary.get_name() description = old_primary.get_name()
else:
msg1 = _("Cannot save item. ID already exists.")
if description: if description:
msg2 = _("You have attempted to use the existing Gramps " msg2 = _("You have attempted to use the existing Gramps "
"ID with value %(id)s. This value is already " "ID with value %(id)s. This value is already "

View File

@ -0,0 +1,76 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2013 Doug Blank <doug.blank@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
""" Unittest for editreference.py """
import unittest
import sys
try:
if sys.version_info < (3,3):
from mock import Mock, patch
else:
from unittest.mock import Mock, patch
MOCKING = True
except:
MOCKING = False
from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
Repository, MediaObject, Note, Tag)
from gramps.gen.merge.diff import DictionaryDb
from gramps.cli.user import User
from gramps.gen.dbstate import DbState
from gramps.gen.merge.diff import *
from gramps.gui.editors.editreference import EditReference
class MockWindow():
def set_transient_for(self, *args, **kwargs):
pass
def show_all(self):
pass
class MockEditReference(EditReference):
def __init__(self, dbstate, uistate, track, source, source_ref, update):
self.window = MockWindow()
super().__init__(dbstate, uistate, track, source, source_ref, update)
example = os.path.abspath(
os.path.join(os.path.dirname(os.path.abspath(__file__)),
"../../../..",
"example/gramps/example.gramps"))
class TestEditReference(unittest.TestCase):
def setUp(self):
self.db = DictionaryDb()
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_editreference(self):
dbstate = DbState()
dbstate.db = self.db
source = Place()
source.gramps_id = "P0001"
self.db.place_map[source.handle] = source
editor = MockEditReference(dbstate, uistate=None, track=[],
source=source, source_ref=None, update=None)
with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED:
editor.check_for_duplicate_id("Place")
self.assertTrue(MockED.called)
if __name__ == "__main__":
unittest.main()