-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_postgres_crud.py
56 lines (42 loc) · 1.85 KB
/
test_postgres_crud.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
import unittest
from fragments.postgres_db.postgres_crud import (
get_item_by_ticker,
get_items_after_launch_year,
get_all_items,
add_item,
remove_item,
update_item,
)
class TestPostgresCrud(unittest.TestCase):
def test_get_item_by_ticker(self):
self.assertEqual(get_item_by_ticker("BTC"), (1, "BTC", "Bitcoin", 2009))
def test_get_item_by_ticker_no_result(self):
self.assertEqual(get_item_by_ticker("XRP"), None)
def test_get_items_after_launch_year(self):
self.assertEqual(len(get_items_after_launch_year(2000)), 3)
def test_get_items_after_launch_year_no_results(self):
self.assertEqual(len(get_items_after_launch_year(2020)), 0)
def test_get_all_items_ordered_by_launch_year(self):
result = get_all_items()
self.assertEqual(result[0], (3, "SOL", "Solana", 2020))
self.assertEqual(result[1], (2, "ETH", "Ethereum", 2015))
self.assertEqual(result[2], (1, "BTC", "Bitcoin", 2009))
def test_add_item(self):
self.assertEqual(add_item(("PEPE", "Pepe", 2023)), "ok")
remove_item("PEPE")
def test_add_item_duplicate(self):
self.assertEqual(add_item(("BTC", "Bitcoin", 2009)), "ok")
def test_remove_item(self):
add_item(("PEPE", "Pepe", 2023))
self.assertEqual(len(get_all_items()), 4)
self.assertEqual(remove_item("PEPE"), ("PEPE", "Pepe", 2023))
self.assertEqual(len(get_all_items()), 3)
def test_remove_item_nonexistent(self):
self.assertEqual(remove_item("XRP"), None)
def test_update_item(self):
self.assertEqual(update_item(("BTC", "Bitcoin", 2000)), ("BTC", "Bitcoin", 2000))
update_item(("BTC", "Bitcoin", 2009))
def test_update_item_nonexistent(self):
self.assertEqual(update_item(("XRP", "Ripple", 2012)), None)
if __name__ == "__main__":
unittest.main()