Fix get_total method and add unit tests

This commit is contained in:
Nick Hall 2016-12-06 17:32:12 +00:00
parent 35b7495438
commit 3e69fa5cbe
2 changed files with 25 additions and 5 deletions

View File

@ -1960,17 +1960,19 @@ class DbWriteBase(DbReadBase):
"""
Get the total of primary objects.
"""
# TODO: should this include tags and citations?
person_len = self.get_number_of_people()
family_len = self.get_number_of_families()
event_len = self.get_number_of_events()
source_len = self.get_number_of_sources()
place_len = self.get_number_of_places()
repo_len = self.get_number_of_repositories()
obj_len = self.get_number_of_media()
source_len = self.get_number_of_sources()
citation_len = self.get_number_of_citations()
media_len = self.get_number_of_media()
note_len = self.get_number_of_notes()
tag_len = self.get_number_of_tags()
return person_len + family_len + event_len + \
place_len + source_len + obj_len + repo_len
return (person_len + family_len + event_len + place_len + repo_len +
source_len + citation_len + media_len + note_len + tag_len)
def set_birth_death_index(self, person):
"""

View File

@ -687,6 +687,16 @@ class DbRandomTest(unittest.TestCase):
person = self.db.find_initial_person()
self.assertEqual(person.handle, default_handle)
################################################################
#
# Test get_total method
#
################################################################
def test_get_total(self):
total = sum([len(self.handles[obj_type])
for obj_type in self.handles.keys()])
self.assertEqual(self.db.get_total(), total)
#-------------------------------------------------------------------------
#
# DbEmptyTest class
@ -776,6 +786,14 @@ class DbEmptyTest(unittest.TestCase):
mapping = self.db.get_name_group_mapping('Clark')
self.assertEqual(mapping, 'Clarke')
################################################################
#
# Test get_total method
#
################################################################
def test_get_total(self):
self.assertEqual(self.db.get_total(), 0)
#-------------------------------------------------------------------------
#
# DbPersonTest class