Пример #1
0
    async def test_get(self):
        db = RedisDatabase({})
        db.client = MockRedisClient()
        db.client.execute = amock.CoroutineMock(return_value='{"key":"value"}')

        result = await db.get("string")

        self.assertDictEqual(result, dict(key="value"))
Пример #2
0
    async def test_get_return_None(self):
        db = RedisDatabase({})
        db.client = MockRedisClient()
        db.client.get = amock.CoroutineMock(return_value=None)

        result = await db.get("string")

        self.assertEqual(result, None)
Пример #3
0
    async def test_disconnect(self):
        db = RedisDatabase({})
        db.client = MockRedisClient()
        db.client.close = amock.CoroutineMock()

        result = await db.disconnect()

        self.assertTrue(db.client.close.called)
Пример #4
0
    async def test_delete(self):
        db = RedisDatabase({})
        db.client = MockRedisClient()
        db.client.execute = amock.CoroutineMock()
        db.client.execute.return_value = None

        result = await db.delete("string")

        self.assertEqual(result, None)
Пример #5
0
async def test_disconnect(mocker):
    database = RedisDatabase({})
    database.client = mocker.Mock()
    attrs = {"close.return_value": return_async_value("None")}
    database.client.configure_mock(**attrs)

    await database.disconnect()

    assert database.client.close.called
Пример #6
0
async def test_get_return_none(mocker, caplog):
    caplog.set_level(logging.DEBUG)
    database = RedisDatabase({})
    database.client = mocker.Mock()
    attrs = {"execute_command.return_value": return_async_value(None)}
    database.client.configure_mock(**attrs)

    result = await database.get("key")

    assert result is None
    assert "Getting" in caplog.text
Пример #7
0
async def test_delete(mocker, caplog):
    caplog.set_level(logging.DEBUG)
    database = RedisDatabase({})
    database.client = mocker.Mock()
    attrs = {"execute_command.return_value": return_async_value("None")}
    database.client.configure_mock(**attrs)

    await database.delete("key")

    database.client.execute_command.assert_called_with("DEL", "key")
    assert "Deleting" in caplog.text
Пример #8
0
async def test_put(mocker, caplog):
    caplog.set_level(logging.DEBUG)
    database = RedisDatabase({})
    database.client = mocker.Mock()
    attrs = {"execute.return_value": return_async_value("None")}
    database.client.configure_mock(**attrs)

    await database.put("key", dict(data_key="data_value"))

    database.client.execute.assert_called_with(
        "SET", "key", json.dumps(dict(data_key="data_value"), cls=JSONEncoder))
    assert "Putting" in caplog.text
Пример #9
0
async def test_get(mocker, caplog):
    caplog.set_level(logging.DEBUG)
    database = RedisDatabase({})
    database.client = mocker.Mock()
    attrs = {
        "execute_command.return_value": return_async_value('{"data_key":"data_value"}')
    }
    database.client.configure_mock(**attrs)

    result = await database.get("key")

    assert result == dict(data_key="data_value")
    database.client.execute_command.assert_called_with("GET", "key")
    assert "Getting" in caplog.text
Пример #10
0
    async def test_put(self):
        db = RedisDatabase({})
        db.client = MockRedisClient()
        db.client.set = amock.CoroutineMock(return_value='{"key":"value"}')

        result = await db.put("string", dict(key="value"))