-
-
Notifications
You must be signed in to change notification settings - Fork 407
/
test_memory.py
37 lines (27 loc) 路 1.05 KB
/
test_memory.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
import asynctest
import asynctest.mock as mock
from opsdroid.memory import Memory
class TestMemory(asynctest.TestCase):
"""Test the opsdroid memory class."""
def setup(self):
return Memory()
async def test_memory(self):
memory = self.setup()
data = "Hello world!"
await memory.put("test", data)
self.assertEqual(data, await memory.get("test"))
self.assertIsNone(await memory.get("nonexistant"))
async def test_empty_memory(self):
memory = self.setup()
self.assertEqual(None, await memory.get("test"))
async def test_database_callouts(self):
memory = self.setup()
memory.databases = [mock.MagicMock()]
memory.databases[0].get = mock.CoroutineMock()
memory.databases[0].put = mock.CoroutineMock()
data = "Hello world!"
await memory.put("test", data)
self.assertTrue(memory.databases[0].put.called)
memory.databases[0].reset_mock()
await memory.get("test")
self.assertTrue(memory.databases[0].get.called)