Tests that the _create_table
()
| 198 | |
| 199 | |
| 200 | def test_create_table(): |
| 201 | """ |
| 202 | Tests that the _create_table |
| 203 | """ |
| 204 | |
| 205 | mock_connect_client = MagicMock() |
| 206 | with patch.dict( |
| 207 | mysql_cache.__context__, |
| 208 | { |
| 209 | "mysql_table_name": "salt", |
| 210 | "mysql_client": mock_connect_client, |
| 211 | "mysql_kwargs": {"db": "salt_cache"}, |
| 212 | }, |
| 213 | ): |
| 214 | with patch.object(mysql_cache, "run_query") as mock_run_query: |
| 215 | mock_run_query.return_value = (MagicMock(), 1) |
| 216 | |
| 217 | sql_call = """CREATE TABLE IF NOT EXISTS salt ( |
| 218 | bank CHAR(255), |
| 219 | etcd_key CHAR(255), |
| 220 | data MEDIUMBLOB, |
| 221 | last_update TIMESTAMP NOT NULL |
| 222 | DEFAULT CURRENT_TIMESTAMP |
| 223 | ON UPDATE CURRENT_TIMESTAMP, |
| 224 | PRIMARY KEY(bank, etcd_key) |
| 225 | );""" |
| 226 | expected_calls = [call(mock_connect_client, sql_call)] |
| 227 | try: |
| 228 | mysql_cache._create_table() |
| 229 | except SaltCacheError: |
| 230 | pytest.fail("This test should not raise an exception") |
| 231 | mock_run_query.assert_has_calls(expected_calls, True) |