forked from nogibjj/SQL_DY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_create_sqlite3.py
36 lines (34 loc) · 1.11 KB
/
test_create_sqlite3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Prepare for testing
import sqlite3
def test_create_sqlite3():
## Create a connection to the database
conn = sqlite3.connect('games.db')
cursor = conn.cursor()
# Check if the table exists
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='games';")
if cursor.fetchone() is None:
# fail the test
print("Table 'games' does not exist")
exit(1)
else:
print("Table 'games' exists")
def test_insert_data():
## Create a connection to the database
conn = sqlite3.connect('games.db')
cursor = conn.cursor()
# Check if the table exists
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='games';")
if cursor.fetchone() is None:
# fail the test
print("Table 'games' does not exist")
exit(1)
else:
print("Table 'games' exists")
# Check if the table has data
cursor.execute("SELECT * FROM games;")
if cursor.fetchone() is None:
# fail the test
print("Table 'games' has no data")
exit(1)
else:
print("Table 'games' has data")