本文整理汇总了Python中keywords.MobileRestClient.MobileRestClient.create_session_header方法的典型用法代码示例。如果您正苦于以下问题:Python MobileRestClient.create_session_header方法的具体用法?Python MobileRestClient.create_session_header怎么用?Python MobileRestClient.create_session_header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keywords.MobileRestClient.MobileRestClient
的用法示例。
在下文中一共展示了MobileRestClient.create_session_header方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_replication_with_session_cookie
# 需要导入模块: from keywords.MobileRestClient import MobileRestClient [as 别名]
# 或者: from keywords.MobileRestClient.MobileRestClient import create_session_header [as 别名]
def test_replication_with_session_cookie(setup_client_syncgateway_test):
"""Regression test for https://github.com/couchbase/couchbase-lite-android/issues/817
1. SyncGateway Config with guest disabled = true and One user added (e.g. user1 / 1234)
2. Create a new session on SGW for the user1 by using POST /_session.
Capture the SyncGatewaySession cookie from the set-cookie in the response header.
3. Start continuous push and pull replicator on the LiteServ with SyncGatewaySession cookie.
Make sure that both replicators start correctly
4. Delete the session from SGW by sending DELETE /_sessions/ to SGW
5. Cancel both push and pull replicator on the LiteServ
6. Repeat step 1 and 2
"""
ls_db = "ls_db"
sg_db = "db"
cluster_config = setup_client_syncgateway_test["cluster_config"]
ls_url = setup_client_syncgateway_test["ls_url"]
sg_url = setup_client_syncgateway_test["sg_url"]
sg_admin_url = setup_client_syncgateway_test["sg_admin_url"]
sg_helper = SyncGateway()
sg_helper.start_sync_gateway(
cluster_config=cluster_config,
url=sg_url,
config="{}/walrus-user.json".format(SYNC_GATEWAY_CONFIGS)
)
log_info("Running 'test_replication_with_session_cookie'")
log_info("ls_url: {}".format(ls_url))
log_info("sg_admin_url: {}".format(sg_admin_url))
log_info("sg_url: {}".format(sg_url))
client = MobileRestClient()
client.create_database(url=ls_url, name=ls_db)
# Get session header for user_1
session_header = client.create_session_header(url=sg_url, db=sg_db, name="user_1", password="foo")
# Get session id from header
session_parts = re.split("=|;", session_header)
session_id = session_parts[1]
log_info("{}: {}".format(session_parts[0], session_id))
session = (session_parts[0], session_id)
# Start authenticated push replication
repl_one = client.start_replication(
url=ls_url,
continuous=True,
from_db=ls_db,
to_url=sg_url,
to_db=sg_db,
to_auth=session_header
)
# Start authenticated pull replication
repl_two = client.start_replication(
url=ls_url,
continuous=True,
from_url=sg_url,
from_db=sg_db,
from_auth=session_header,
to_db=ls_db,
)
# Wait for 2 replications to be 'Idle', On .NET they may not be immediately available via _active_tasks
client.wait_for_replication_status_idle(ls_url, repl_one)
client.wait_for_replication_status_idle(ls_url, repl_two)
replications = client.get_replications(ls_url)
assert len(replications) == 2, "2 replications (push / pull should be running)"
num_docs_pushed = 100
# Sanity test docs
ls_docs = client.add_docs(url=ls_url, db=ls_db, number=num_docs_pushed, id_prefix="ls_doc", channels=["ABC"])
assert len(ls_docs) == num_docs_pushed
sg_docs = client.add_docs(url=sg_url, db=sg_db, number=num_docs_pushed, id_prefix="sg_doc", auth=session, channels=["ABC"])
assert len(sg_docs) == num_docs_pushed
all_docs = client.merge(ls_docs, sg_docs)
log_info(all_docs)
client.verify_docs_present(url=sg_admin_url, db=sg_db, expected_docs=all_docs)
client.verify_docs_present(url=ls_url, db=ls_db, expected_docs=all_docs)
# GET from session endpoint /{db}/_session/{session-id}
session = client.get_session(url=sg_admin_url, db=sg_db, session_id=session_id)
assert len(session["userCtx"]["channels"]) == 2, "There should be only 2 channels for the user"
assert "ABC" in session["userCtx"]["channels"], "The channel info should contain 'ABC'"
assert session["userCtx"]["name"] == "user_1", "The user should have the name 'user_1'"
assert len(session["authentication_handlers"]) == 2, "There should be 2 authentication_handlers"
assert "default" in session["authentication_handlers"], "Did not find 'default' in authentication_headers"
assert "cookie" in session["authentication_handlers"], "Did not find 'cookie' in authentication_headers"
log_info("SESSIONs: {}".format(session))
# Delete session via sg admin port and _user rest endpoint
client.delete_session(url=sg_admin_url, db=sg_db, user_name="user_1", session_id=session_id)
#.........这里部分代码省略.........