Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions test/test_update_data_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@


class TestUpdate(unittest.TestCase):

def setUp(self):

conn = sqlite3.connect("meter_db.sqlite")
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS meter_table')
cur.execute('CREATE TABLE meter_table (meter_id TEXT, energy INTEGER,date TEXT, status BOOLEAN)')
cur.execute('INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )', ("00fe00", 0, "2021-06-26 18:41:23.580757", True))
cur.execute('INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )', ("00ff01", 0, "2021-06-26 18:41:23.580757", True))
cur.execute('INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )', ("00ff02", 0, "2021-06-26 18:41:23.580757", True))
cur.execute('INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )', ("00ff03", 0, "2021-06-26 18:41:23.580757", True))
cur.execute('INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )', ("00ff04", 0, "2021-06-26 18:41:23.580757", True))
cur.execute(
'CREATE TABLE meter_table (meter_id TEXT, energy INTEGER,date TEXT, status BOOLEAN)'
)
cur.execute(
'INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )',
("00fe00", 0, "2021-06-26 18:41:23.580757", True))
cur.execute(
'INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )',
("00ff01", 0, "2021-06-26 18:41:23.580757", True))
cur.execute(
'INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )',
("00ff02", 0, "2021-06-26 18:41:23.580757", True))
cur.execute(
'INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )',
("00ff03", 0, "2021-06-26 18:41:23.580757", True))
cur.execute(
'INSERT INTO meter_table (meter_id, energy,date, status) VALUES (?, ?, ?, ? )',
("00ff04", 0, "2021-06-26 18:41:23.580757", True))
conn.commit()
cur.close()

Expand All @@ -32,7 +43,8 @@ def testUpdateExistingMeter(self):
update_date_base("00fe00", expected_data)
conn = sqlite3.connect("meter_db.sqlite")
cur = conn.cursor()
cur.execute('SELECT * FROM meter_table WHERE meter_id = ?', ("00fe00",))
cur.execute('SELECT * FROM meter_table WHERE meter_id = ?',
("00fe00", ))
actual_data = cur.fetchone()[1]
self.assertEqual(actual_data, expected_data, "Should be equal")
cur.close()
Expand All @@ -43,8 +55,9 @@ def testUpdateNonExistingMeter(self):
update_date_base("00ff00", expected_data)
conn = sqlite3.connect("meter_db.sqlite")
cur = conn.cursor()
cur.execute('SELECT * FROM meter_table WHERE meter_id = ?', ("00ff00",))
actual_data = cur.fetchone()
cur.execute('SELECT * FROM meter_table WHERE meter_id = ?',
("00ff00", ))
actual_data = cur.fetchone()
self.assertIsNone(actual_data, "Should be None")
cur.close()

Expand Down