|
import os |
|
import unittest |
|
import common_util |
|
from unittest import mock |
|
from petrel_client.client import Client |
|
test_dir = os.path.dirname(os.path.realpath(__file__)) |
|
|
|
|
|
class TestRead(unittest.TestCase): |
|
def setUp(self): |
|
|
|
self._mock_get_with_info = mock.Mock() |
|
self._mock_get_with_info.return_value = "23", {} |
|
|
|
self._patcher = mock.patch( |
|
'petrel_client.ceph.s3.s3_client.S3Client.get_with_info', |
|
self._mock_get_with_info) |
|
self._patcher.start() |
|
pass |
|
|
|
def tearDown(self): |
|
self._patcher.stop() |
|
pass |
|
|
|
|
|
def test_read1(self): |
|
_conf_path = test_dir + '/conf/petreloss.conf' |
|
c = Client(conf_path=_conf_path) |
|
|
|
data = c.get('cluster1:s3://lili1.test2/sometest') |
|
|
|
self.assertEqual("23", data) |
|
|
|
|
|
@mock.patch("petrel_client.ceph.s3.s3_client.S3Client.get_with_info") |
|
|
|
def test_read2(self, mock_get_with_info): |
|
mock_get_with_info.return_value = "15", {} |
|
_conf_path = test_dir + '/conf/petreloss.conf' |
|
c = Client(conf_path=_conf_path) |
|
data = c.get('cluster1:s3://lili1.test2/sometest') |
|
self.assertEqual("15", data) |
|
|
|
|
|
def test_read3(self): |
|
mock_get_with_info = mock.Mock() |
|
mock_get_with_info.return_value = "15", {} |
|
_conf_path = test_dir + '/conf/petreloss.conf' |
|
c = Client(conf_path=_conf_path) |
|
with mock.patch( |
|
'petrel_client.ceph.s3.s3_client.S3Client.get_with_info', |
|
mock_get_with_info): |
|
data = c.get('cluster1:s3://lili1.test2/sometest') |
|
self.assertEqual("15", data) |
|
|
|
|
|
if __name__ == '__main__': |
|
common_util.run_test() |