2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2013 Doug Blank <doug.blank@gmail.com>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
""" Unittest for editreference.py """
26
if sys.version_info < (3,3):
27
from mock import Mock, patch
29
from unittest.mock import Mock, patch
34
from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
35
Repository, MediaObject, Note, Tag)
36
from gramps.gen.merge.diff import DictionaryDb
37
from gramps.cli.user import User
38
from gramps.gen.dbstate import DbState
39
from gramps.gen.merge.diff import *
40
from gramps.gui.editors.editreference import EditReference
43
def set_transient_for(self, *args, **kwargs):
48
class MockEditReference(EditReference):
49
def __init__(self, dbstate, uistate, track, source, source_ref, update):
50
self.window = MockWindow()
51
super().__init__(dbstate, uistate, track, source, source_ref, update)
53
example = os.path.abspath(
54
os.path.join(os.path.dirname(os.path.abspath(__file__)),
56
"example/gramps/example.gramps"))
58
class TestEditReference(unittest.TestCase):
60
self.db = DictionaryDb()
62
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
63
def test_editreference(self):
67
source.gramps_id = "P0001"
68
self.db.place_map[source.handle] = source
69
editor = MockEditReference(dbstate, uistate=None, track=[],
70
source=source, source_ref=None, update=None)
71
with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED:
72
editor.check_for_duplicate_id("Place")
73
self.assertTrue(MockED.called)
75
if __name__ == "__main__":