Skip to content
Snippets Groups Projects
Commit 1d85d8db authored by morkolai's avatar morkolai
Browse files

#52 Test for update_last_updated

parent 6287576d
No related branches found
No related tags found
1 merge request!27#52 Automatisk oppdatering av kodebok basert på tid
Pipeline #73925 failed
......@@ -117,6 +117,24 @@ class DatabaseTest(unittest.TestCase):
last_update, r"(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})"
)
def test_update_last_updated(self):
"""Assert that the time gets updated when running method."""
# Get two datetimes that should only differ by sleep_time
stmt = "SELECT Timestamp FROM LastUpdated"
self.database.update_last_updated()
first_time = self.database.conn.execute(stmt).fetchall()[0][0]
sleep_time = 2
sleep(sleep_time)
self.database.update_last_updated()
second_time = self.database.conn.execute(stmt).fetchall()[0][0]
# Converts from string to datetime object
first_time = datetime.strptime(first_time, "%Y-%m-%d %H:%M:%S.%f")
second_time = datetime.strptime(second_time, "%Y-%m-%d %H:%M:%S.%f")
# Calculates difference in seconds
time_diff = (second_time - first_time).total_seconds()
# Compares difference with sleep_time
self.assertAlmostEqual(time_diff, sleep_time, delta=0.2)
def test_get_categories(self):
"""Assert function get_categories works as expected."""
file_path = os.path.join(TESTDATA_PATH, "CategoryWords.txt")
......@@ -241,13 +259,13 @@ class DatabaseTest(unittest.TestCase):
stmt = "UPDATE LastUpdated SET Timestamp = ? LIMIT 1"
self.database.conn.execute(stmt, (datetime.now(),))
# Sleeps to make time difference
sleep_time = 3
sleep_time = 2
sleep(sleep_time)
# Calculates expected return value and gets return value
expected_time = (24 * 60 * 60) - sleep_time
actual_time = self.database.seconds_to_next_update()
# Compares expected and function return value with
self.assertAlmostEqual(expected_time, actual_time, delta=0.3)
self.assertAlmostEqual(expected_time, actual_time, delta=0.2)
def test_add_code(self):
"""Test add a single code to CodeBook."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment