2017-04-15 00:14:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# Copyright (C) 2017 Christian Thomas Jacobs.
|
|
|
|
|
|
|
|
# This file is part of PyQSO.
|
|
|
|
|
|
|
|
# PyQSO 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 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# PyQSO 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 PyQSO. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-04-15 00:19:33 +00:00
|
|
|
import unittest
|
|
|
|
try:
|
|
|
|
import unittest.mock as mock
|
|
|
|
except ImportError:
|
|
|
|
import mock
|
|
|
|
import os
|
2017-04-15 00:14:17 +00:00
|
|
|
from pyqso.logbook import *
|
|
|
|
|
|
|
|
|
|
|
|
class TestLogbook(unittest.TestCase):
|
|
|
|
|
|
|
|
""" The unit tests for the Logbook class. """
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
""" Set up the Logbook object and connection to the test database needed for the unit tests. """
|
|
|
|
self.logbook = Logbook(application=mock.MagicMock())
|
|
|
|
path_to_test_database = os.path.join(os.path.realpath(os.path.dirname(__file__)), os.pardir, "res/test.db")
|
|
|
|
success = self.logbook.db_connect(path_to_test_database)
|
2017-04-20 21:50:08 +00:00
|
|
|
assert(success)
|
|
|
|
self.logbook.logs = self.logbook.get_logs()
|
|
|
|
assert(self.logbook.logs is not None)
|
|
|
|
# Check that the logs have been retrieved.
|
|
|
|
temp = []
|
2017-04-15 00:14:17 +00:00
|
|
|
for log_name in ["test", "test2"]:
|
|
|
|
l = Log(self.logbook.connection, log_name)
|
|
|
|
l.populate()
|
2017-04-20 21:50:08 +00:00
|
|
|
temp.append(l)
|
|
|
|
assert(self.logbook.logs[0].name == temp[0].name)
|
|
|
|
assert(self.logbook.logs[1].name == temp[1].name)
|
2017-04-15 00:14:17 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
""" Disconnect from the test database. """
|
|
|
|
success = self.logbook.db_disconnect()
|
2017-04-20 21:50:08 +00:00
|
|
|
assert(success)
|
2017-04-15 00:14:17 +00:00
|
|
|
|
|
|
|
def test_log_name_exists(self):
|
|
|
|
""" Check that only the log called 'test' exists. """
|
2017-04-20 21:50:08 +00:00
|
|
|
assert(self.logbook.log_name_exists("test")) # Log 'test' exists.
|
|
|
|
assert(not self.logbook.log_name_exists("hello")) # Log 'hello' should not exist.
|
2017-04-15 00:14:17 +00:00
|
|
|
|
|
|
|
def test_log_count(self):
|
2017-04-20 22:24:50 +00:00
|
|
|
""" Check the log count. """
|
2017-04-20 21:50:08 +00:00
|
|
|
assert(self.logbook.log_count == 2)
|
2017-04-15 00:14:17 +00:00
|
|
|
|
|
|
|
def test_record_count(self):
|
2017-04-20 22:24:50 +00:00
|
|
|
""" Check the total number of records over all the logs in the logbook. """
|
|
|
|
assert(self.logbook.record_count == 7)
|
2017-04-15 00:14:17 +00:00
|
|
|
|
|
|
|
if(__name__ == '__main__'):
|
|
|
|
unittest.main()
|