Skip to content

Commit 2f11bb5

Browse files
Add tests
1 parent 6bff8bd commit 2f11bb5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/acquisition/covidcast/test_database.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,29 @@ def test_insert_or_update_batch_exception_reraised(self):
137137

138138
cc_rows = {MagicMock(geo_id='CA', val=1, se=0, sample_size=0)}
139139
self.assertRaises(Exception, database.insert_or_update_batch, cc_rows)
140+
141+
def test_insert_or_update_batch_row_count_returned(self):
142+
"""Test that the row count is returned"""
143+
mock_connector = MagicMock()
144+
database = Database()
145+
database.connect(connector_impl=mock_connector)
146+
connection = mock_connector.connect()
147+
cursor = connection.cursor()
148+
cursor.rowcount = 3
149+
150+
cc_rows = [MagicMock(geo_id='CA', val=1, se=0, sample_size=0)]
151+
result = database.insert_or_update_batch(cc_rows)
152+
self.assertEqual(result, 3)
153+
154+
def test_insert_or_update_batch_none_returned(self):
155+
"""Test that None is returned when row count cannot be returned"""
156+
mock_connector = MagicMock()
157+
database = Database()
158+
database.connect(connector_impl=mock_connector)
159+
connection = mock_connector.connect()
160+
cursor = connection.cursor()
161+
cursor.rowcount = -1
162+
163+
cc_rows = [MagicMock(geo_id='CA', val=1, se=0, sample_size=0)]
164+
result = database.insert_or_update_batch(cc_rows)
165+
self.assertIsNone(result)

0 commit comments

Comments
 (0)