-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_main.py
57 lines (42 loc) · 1.37 KB
/
test_main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Test goes here
"""
from unittest.mock import patch, MagicMock
from mylib.extract import extract
from mylib.transform_load import load
from mylib.query import query
def test_extract():
test_1 = extract()
assert test_1 is not None
@patch("databricks.sql.connect")
def test_load(mock_connect):
"""test load"""
# Create a mock connection and cursor
mock_conn = MagicMock()
mock_cursor = MagicMock()
mock_connect.return_value = mock_conn
mock_conn.cursor.return_value = mock_cursor
# Simulate an empty database (no rows returned)
mock_cursor.fetchall.return_value = []
# Call the load function
test_2 = load()
# Ensure the result matches the expected success message
assert test_2 == "Database loaded or already contains data"
@patch("databricks.sql.connect")
def test_query(mock_connect):
"""test query"""
# Create a mock connection and cursor
mock_conn = MagicMock()
mock_cursor = MagicMock()
mock_connect.return_value = mock_conn
mock_conn.cursor.return_value = mock_cursor
# Simulate query results
mock_cursor.fetchall.return_value = [("2000", "1", "1", "6", "9083")]
# Call the query function
test_3 = query()
# Ensure the result matches the expected success message
assert test_3 == "Query successful"
if __name__ == "__main__":
test_extract()
test_load()
test_query()