class TestData(unittest.TestCase): def setUp(self): client = OpensearchClientFactory.create_client("hangzhou", "external", "XVqTa2Rl5fGpml7c", "ZRXQN8Azm15Z7bWKgD0zVzS0OJR6A9") self.data_mgr = DataMgr(client) def test_upload_P1(self): with codecs.open("../files/test4_main.txt") as ifh: json_str = ifh.read() resp = self.data_mgr.upload("test5", "main", json_str) self.assertTrue(resp.success()) def test_upload_P2(self): json_str = """ [ { "cmd": "add", "timestamp": 1401342874777, "fields": { "id": "1", "title": "This is the title", "body": "This is the body" } }, { "cmd": "update", "timestamp": 1401342874778, "fields": { "id": "2", "title": "This is the new title" } }, { "cmd": "delete", "fields": { "id": "3" } } ] """ resp = self.data_mgr.upload("F7xBML", "main", json_str) self.assertTrue(resp.success())
def setUp(self): client = OpensearchClientFactory.create_client("hangzhou", "external", "XVqTa2Rl5fGpml7c", "ZRXQN8Azm15Z7bWKgD0zVzS0OJR6A9") self.data_mgr = DataMgr(client)
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 = """ [ { "cmd": "add", "timestamp": 1401342874777, "fields": { "id": "1", "title": "This is the title", "body": "This is the body" } }, { "cmd": "update", "timestamp": 1401342874778, "fields": {