MCPcopy Create free account
hub / github.com/saltstack/salt / test_store

Function test_store

tests/pytests/unit/cache/test_mysql_cache.py:38–91  ·  view source on GitHub ↗

Tests that the store function writes the data to the serializer for storage.

()

Source from the content-addressed store, hash-verified

36
37
38def test_store():
39 """
40 Tests that the store function writes the data to the serializer for storage.
41 """
42
43 mock_connect_client = MagicMock()
44 with patch.object(mysql_cache, "_init_client") as mock_init_client:
45 with patch.dict(
46 mysql_cache.__context__,
47 {
48 "mysql_table_name": "salt",
49 "mysql_client": mock_connect_client,
50 },
51 ):
52 with patch.object(mysql_cache, "run_query") as mock_run_query:
53 mock_run_query.return_value = (MagicMock(), 1)
54
55 expected_calls = [
56 call(
57 mock_connect_client,
58 "REPLACE INTO salt (bank, etcd_key, data) values(%s,%s,%s)",
59 args=("minions/minion", "key1", b"\xa4data"),
60 )
61 ]
62
63 try:
64 mysql_cache.store(bank="minions/minion", key="key1", data="data")
65 except SaltCacheError:
66 pytest.fail("This test should not raise an exception")
67 mock_run_query.assert_has_calls(expected_calls, True)
68
69 with patch.object(mysql_cache, "run_query") as mock_run_query:
70 mock_run_query.return_value = (MagicMock(), 2)
71
72 expected_calls = [
73 call(
74 mock_connect_client,
75 "REPLACE INTO salt (bank, etcd_key, data) values(%s,%s,%s)",
76 args=("minions/minion", "key2", b"\xa4data"),
77 )
78 ]
79
80 try:
81 mysql_cache.store(bank="minions/minion", key="key2", data="data")
82 except SaltCacheError:
83 pytest.fail("This test should not raise an exception")
84 mock_run_query.assert_has_calls(expected_calls, True)
85
86 with patch.object(mysql_cache, "run_query") as mock_run_query:
87 mock_run_query.return_value = (MagicMock(), 0)
88 with pytest.raises(SaltCacheError) as exc_info:
89 mysql_cache.store(bank="minions/minion", key="data", data="data")
90 expected = "Error storing minions/minion data returned 0"
91 assert expected in str(exc_info.value)
92
93
94def test_fetch():

Callers

nothing calls this directly

Calls 2

callFunction · 0.50
storeMethod · 0.45

Tested by

no test coverage detected