-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgres_connector.test.py
More file actions
46 lines (39 loc) · 1.23 KB
/
postgres_connector.test.py
File metadata and controls
46 lines (39 loc) · 1.23 KB
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
37
38
39
40
41
42
43
44
45
######
# This is a test file to test the PostgresConnector class
# To run the test, please run the following command: `python3 postgres_connector.test.py`
######
from postgres_connector import PostgresConnector
# Test the PostgresConnector class
with PostgresConnector() as db:
# Test database connection
columns, results = db.execute_query("SELECT version()")
if results:
print("Database connection successful:")
for row in results:
print(row)
# Create a mock test table
db.execute_query("""
DROP TABLE IF EXISTS mocktb;
CREATE TABLE mocktb (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
value INTEGER
)
""")
# Insert some test data
db.execute_query("""
INSERT INTO mocktb (name, value) VALUES
('test1', 100),
('test2', 200),
('test3', 300)
""")
# Test SELECT query
columns, results = db.execute_query("SELECT * FROM mocktb ORDER BY id")
print("\nTest table contents:")
print("Columns:", columns)
for row in results:
print(row)
# Test markdown output
markdown_output = db.fetch_table_data()
print("\nMarkdown output:")
print(markdown_output)