class TestApplication(unittest.TestCase):
    """
    You need create template manually, create templates with name default and default2
    """

    def setUp(self):
        client = OpensearchClientFactory.create_client("hangzhou", "external", "XVqTa2Rl5fGpml7c", "ZRXQN8Azm15Z7bWKgD0zVzS0OJR6A9")
        self.app = ApplicationMgr(client)

    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_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_delete_noexists_P1(self):
        result = self.app.delete("not_exists")
        self.assertEqual("FAIL", result.status)

    def test_multiple_thread(self):
        pass

    def test_view(self):
        result = self.app.view("test1")
        self.assertEqual("OK", result.status)
Пример #2
0
        """
resp = data_mgr.upload(app_name, "main", json_str)

# a little like create app's result:
if resp.success():
    print("upload date to %s success" % app_name)

print(resp.result)

# search is NOT thread safe, please create a instance for each query
search = Search(client)
search.query("title").index_name(app_name)
results = search.results()

# search result is also like common result, you could do anything you want when get json object
if results.success():
    print("query success")

print results.result

# if you want to use some complex query, you could use Q, for example
search = Search(client)  # remember, search is NOT thread safe, please create a new one
search.query(Q(default="title"), Q(default="中文") | Q(default="title3")).rank("校长").index_name("F7xBML")
results = search.results()
# Q(xxx) | Q(yyy) means xxx OR yyy, it support & -> AND, | -> OR, ~ -> ANDNOT

# delete this application
app.delete(app_name)

# hope you like it, for more detail usage, you could find in unit test cases