def test_get_random_str_P1(self):
     """
     test length
     :return:
     """
     a = utils.get_random_str()
     print a
     self.assertEqual(32, len(a))
     a = utils.get_random_str(128)
     self.assertEqual(128, len(a))
    def test_delete_P1(self):
        app_name = utils.get_random_str(6)
        result = self.app.create(app_name, "default")
        self.assertEqual("OK", result.status)

        result = self.app.delete(app_name)
        self.assertEqual("OK", result.status)
 def test_get_random_str_P3(self):
     """
     test sample characters
     :return:
     """
     a = utils.get_random_str(sample_characters=string.digits)
     self.assertTrue(re.match("^[0-9]{32}$", a))
    def test_create_duplicate_N1(self):

        app_name = utils.get_random_str(6)
        result = self.app.create(app_name, "default2")
        self.assertEqual("OK", result.status)

        result = self.app.create(app_name, "default2")
        self.assertEqual("FAIL", result.status)
    def test_get_random_str_P2(self):
        """
        test collision
        random 10000 strings with len 32, no reduplication, so, the collision probability is very small!
        :return:
        """
        test_num = 10000

        number_set = set()

        for i in range(0, test_num):
            number_set.add(utils.get_random_str())

        self.assertEqual(test_num, len(number_set))
Beispiel #6
0
from opensearchsdk.core.client import OpensearchClientFactory
from opensearchsdk.service.application import ApplicationMgr
from opensearchsdk.service.data import DataMgr
from opensearchsdk.service.search import Search, Q
from opensearchsdk.config import Config

# if you want to open debug log, please set it to True
Config.DEBUG = True

# create a client, this is singleton
client = OpensearchClientFactory.create_client("hangzhou", "external", "XVqTa2Rl5fGpml7c", "ZRXQN8Azm15Z7bWKgD0zVzS0OJR6A9")

# create a application
# ApplicationMgr is thread safe
app = ApplicationMgr(client)
app_name = utils.get_random_str(6)
# make sure you have created a template named default2 manually
resp = app.create(app_name, "default2")

# you could get mission result by:
if resp.success():
    print("create app %s success" % app_name)

# and you could get return json object
print(resp.result)

# upload to this application a document
# DataMgr is also thread safe
# you could reuse client
data_mgr = DataMgr(client)
json_str = """