Skip to content

Commit f9efcd3

Browse files
committed
Actually just fix the test
1 parent b7f3215 commit f9efcd3

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

awscli/telemetry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def _create_host_id_table(self):
111111

112112
def _ensure_host_id(self):
113113
cur = self.execute(self._CHECK_HOST_ID)
114-
host_id_ct = cur.fetchone()
115-
if host_id_ct and host_id_ct[0] == 0:
114+
host_id_ct = cur.fetchone()[0]
115+
if host_id_ct == 0:
116116
self.execute(
117117
self._INSERT_HOST_ID,
118118
# Hardcode `0` as primary key to ensure

tests/functional/test_telemetry.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,25 @@ def test_ensure_database_setup(self, session_conn):
108108
assert cursor.fetchall() == [('session',), ('host_id',)]
109109

110110
def test_timeout_does_not_raise_exception(self, session_conn):
111+
test_query = """
112+
SELECT name
113+
FROM sqlite_master
114+
WHERE type='table'
115+
AND name='session';
116+
"""
117+
111118
class FakeConnection(sqlite3.Connection):
112119
def execute(self, query, *parameters):
113120
# Simulate timeout by always raising.
114-
raise sqlite3.OperationalError()
121+
if query == test_query:
122+
raise sqlite3.OperationalError()
123+
# Mock host id count query.
124+
cur = MagicMock()
125+
cur.fetchone.return_value = (1,)
126+
return cur
115127

116128
fake_conn = CLISessionDatabaseConnection(FakeConnection(":memory:"))
117-
cursor = fake_conn.execute(
118-
"""
119-
SELECT name
120-
FROM sqlite_master
121-
WHERE type='table'
122-
AND name='session';
123-
"""
124-
)
129+
cursor = fake_conn.execute(test_query)
125130
assert cursor.fetchall() == []
126131

127132

0 commit comments

Comments
 (0)