~rosco2/ubuntu/wily/gramps/bug-1492304

« back to all changes in this revision

Viewing changes to gramps/gui/editors/test/test_editreference.py

  • Committer: Package Import Robot
  • Author(s): Ross Gammon
  • Date: 2015-08-11 23:03:11 UTC
  • mfrom: (1.4.3)
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: package-import@ubuntu.com-20150811230311-acjr8gcfe8isx7ij
* New upstream release
* Drop patches applied upstream or cherry-picked from there
* Add version constraints for gtk and pygobject
* Add goocanvas dependency - available soon
* Drop webkit dpendency as HTML view has been removed
* Force removal of upstream packages when installing Debian one
  (LP: #1464845)
* Drop fixperm override as permissions fixed upstream
* Fix spelling error in changelog
* Switch to nose for unit tests
* Add build dependencies for the nose tests
* Update copyright file
* Add uversionmangle to watch file to deal with alpha/beta versions
* Add manual test cases
* Drop FAQ URL from upstream metadata - changes every release
* Add patch to fix transparent windows in Ubuntu.
  Thanks to Lance Orner (LP: #1451259)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Gramps - a GTK+/GNOME based genealogy program
 
3
#
 
4
# Copyright (C) 2013 Doug Blank <doug.blank@gmail.com>
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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.
 
19
#
 
20
 
 
21
""" Unittest for editreference.py """
 
22
 
 
23
import unittest
 
24
import sys
 
25
try:
 
26
    if sys.version_info < (3,3):
 
27
        from mock import Mock, patch
 
28
    else:
 
29
        from unittest.mock import Mock, patch
 
30
    MOCKING = True
 
31
except:
 
32
    MOCKING = False
 
33
 
 
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
 
41
 
 
42
class MockWindow():
 
43
    def set_transient_for(self, *args, **kwargs):
 
44
        pass
 
45
    def show_all(self):
 
46
        pass
 
47
 
 
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)
 
52
 
 
53
example = os.path.abspath(
 
54
    os.path.join(os.path.dirname(os.path.abspath(__file__)),
 
55
                 "../../../..", 
 
56
                 "example/gramps/example.gramps"))
 
57
 
 
58
class TestEditReference(unittest.TestCase):
 
59
    def setUp(self):
 
60
        self.db = DictionaryDb() 
 
61
 
 
62
    @unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
 
63
    def test_editreference(self):
 
64
        dbstate = DbState()
 
65
        dbstate.db = self.db
 
66
        source = Place() 
 
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)
 
74
 
 
75
if __name__ == "__main__":
 
76
    unittest.main()