本文整理汇总了Python中weblab.core.coordinator.clients.weblabdeusto.WebLabDeustoClient.logout方法的典型用法代码示例。如果您正苦于以下问题:Python WebLabDeustoClient.logout方法的具体用法?Python WebLabDeustoClient.logout怎么用?Python WebLabDeustoClient.logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weblab.core.coordinator.clients.weblabdeusto.WebLabDeustoClient
的用法示例。
在下文中一共展示了WebLabDeustoClient.logout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_full_experiment_use
# 需要导入模块: from weblab.core.coordinator.clients.weblabdeusto import WebLabDeustoClient [as 别名]
# 或者: from weblab.core.coordinator.clients.weblabdeusto.WebLabDeustoClient import logout [as 别名]
def do_full_experiment_use():
"""
Uses the configured experiment trying to resemble the way a human would do it.
This method will block for a while.
:return:
"""
wc = WebLabDeustoClient(config.WEBLAB_BASE_URL)
sessionid = wc.login(config.LOGIN, config.PASSWORD)
if not sessionid: raise Exception("Wrong login")
# Reserve the flash dummy experiment.
experiment_id = ExperimentId(config.EXP_NAME, config.EXP_CATEGORY)
waiting = wc.reserve_experiment(sessionid, experiment_id, "{}", "{}", None)
# print "Reserve response: %r" % waiting
reservation_id = waiting.reservation_id
while True:
status = wc.get_reservation_status(reservation_id)
# print "Reservation status: %r" % status
if type(status) is WaitingReservation:
time.sleep(0.5)
elif type(status) is ConfirmedReservation:
break
elif type(status) is WaitingConfirmationReservation:
time.sleep(0.5)
else:
print "Unknown reservation status."
print "Experiment reserved."
global users_in
users_in += 1
# Send some commands.
for i in range(config.COMMANDS_PER_USER):
# What's commandstring actually for??
cmd = Command(config.COMMAND)
result = wc.send_command(reservation_id, cmd)
if not result.commandstring.startswith("Received command"):
raise Exception("Unrecognized command response")
# print "Command result: %r" % result
time.sleep(config.TIME_BETWEEN_COMMANDS)
users_in -= 1
result = wc.logout(sessionid)
print "Logout result: %r" % result
示例2: IntegrationNoConcurrencyTestCase
# 需要导入模块: from weblab.core.coordinator.clients.weblabdeusto import WebLabDeustoClient [as 别名]
# 或者: from weblab.core.coordinator.clients.weblabdeusto.WebLabDeustoClient import logout [as 别名]
class IntegrationNoConcurrencyTestCase(object):
def setUp(self):
self.global_config = load_dir(self.DEPLOYMENT_DIR)
self.process_handlers = []
for process in self.PROCESSES:
process_handler = self.global_config.load_process('myhost', process)
self.process_handlers.append(process_handler)
self.core_server = GLOBAL_REGISTRY[self.CORE_ADDRESS]
self.experiment_dummy1 = GLOBAL_REGISTRY[self.EXPERIMENT_DUMMY1]
self.experiment_dummy2 = GLOBAL_REGISTRY[self.EXPERIMENT_DUMMY2]
self.core_config = self.core_server.config
self.client = WebLabDeustoClient('http://localhost:%s/weblab/' % self.core_config[configuration_doc.CORE_FACADE_PORT])
def tearDown(self):
GLOBAL_REGISTRY.clear()
for process_handler in self.process_handlers:
process_handler.stop()
def test_simple_single_uses(self):
for _ in range(1):
self._single_use()
self._single_use()
self._single_use()
def _single_use(self, logout = True, plus_async_use = True):
"""
Will use an experiment.
@param logout If true, the user will be logged out after the use. Otherwise not.
@param plus_async_use If true, after using the experiment synchronously, it will use it
again using the asynchronous versions of the send_command and send_file requests.
"""
self._single_sync_use(logout)
if plus_async_use:
self._single_async_use(logout)
def _single_sync_use(self, logout = True):
session_id, reservation_id = self._get_reserved()
CONTENT = "content of the program FPGA"
response = self.client.send_file(reservation_id, ExperimentUtil.serialize(CONTENT), 'program')
self.assertEquals(response.commandstring, 'ack')
response = self.client.send_command(reservation_id, Command.Command("STATE"))
self.assertEquals(response.commandstring, 'STATE')
response = self.client.send_command(reservation_id, Command.Command("ChangeSwitch on 0"))
self.assertEquals(response.commandstring, "ChangeSwitch on 0")
if logout:
self.client.logout(session_id)
def _get_reserved(self):
session_id = self.client.login('intstudent1', 'password')
user_information = self.client.get_user_information(session_id)
self.assertEquals( 'intstudent1', user_information.login)
self.assertEquals( 'Name of integration test 1', user_information.full_name)
self.assertEquals( '[email protected]', user_information.email)
experiments = self.client.list_experiments(session_id)
self.assertEquals( 2, len(experiments))
dummy1_experiments = [ exp.experiment for exp in experiments if exp.experiment.name == 'dummy1' ]
self.assertEquals( len(dummy1_experiments), 1)
dummy1_experiment = dummy1_experiments[0]
status = self.client.reserve_experiment(session_id, dummy1_experiment.to_experiment_id(), "{}", "{}")
reservation_id = status.reservation_id
# wait until it is reserved
short_time = 0.1
# Time extended from 9.0 to 15.0 because at times the test failed, possibly for that reason.
times = 15.0 / short_time
while times > 0:
new_status = self.client.get_reservation_status(reservation_id)
if not isinstance(new_status, Reservation.WaitingConfirmationReservation) and not isinstance(new_status, Reservation.WaitingReservation):
break
times -= 1
time.sleep(short_time)
reservation = self.client.get_reservation_status(reservation_id)
self.assertTrue(
isinstance(reservation, Reservation.ConfirmedReservation),
"Reservation %s is not Confirmed, as expected by this time" % reservation
)
return session_id, reservation_id
def _single_async_use(self, logout = True):
session_id, reservation_id = self._get_reserved()
# send the program again, but asynchronously. Though this should work, it is not really very customary
# to send_file more than once in the same session. In fact, it is a feature which might get removed in
#.........这里部分代码省略.........
示例3: IntegrationMultipleUsersTestCase
# 需要导入模块: from weblab.core.coordinator.clients.weblabdeusto import WebLabDeustoClient [as 别名]
# 或者: from weblab.core.coordinator.clients.weblabdeusto.WebLabDeustoClient import logout [as 别名]
#.........这里部分代码省略.........
experiments2 = self.client.list_experiments(session_id2)
dummy_experiments2 = [ exp.experiment for exp in experiments2 if exp.experiment.name == 'dummy1' ]
self.assertEquals( len(dummy_experiments2), 1 )
experiments3 = self.client.list_experiments(session_id3)
dummy_experiments3 = [ exp.experiment for exp in experiments3 if exp.experiment.name == 'dummy1' ]
self.assertEquals( len(dummy_experiments3), 1 )
experiments4 = self.client.list_experiments(session_id4)
dummy_experiments4 = [ exp.experiment for exp in experiments4 if exp.experiment.name == 'dummy1' ]
self.assertEquals( len(dummy_experiments4), 1 )
experiments5 = self.client.list_experiments(session_id5)
dummy_experiments5 = [ exp.experiment for exp in experiments5 if exp.experiment.name == 'dummy1' ]
self.assertEquals( len(dummy_experiments5), 1 )
experiments6 = self.client.list_experiments(session_id6)
dummy_experiments6 = [ exp.experiment for exp in experiments6 if exp.experiment.name == 'dummy1' ]
self.assertEquals( len(dummy_experiments6), 1 )
# 3 users try to reserve the experiment
status1 = self.client.reserve_experiment(session_id1, dummy_experiments1[0].to_experiment_id(), "{}", "{}")
reservation_id1 = status1.reservation_id
status2 = self.client.reserve_experiment(session_id2, dummy_experiments2[0].to_experiment_id(), "{}", "{}")
reservation_id2 = status2.reservation_id
status3 = self.client.reserve_experiment(session_id3, dummy_experiments3[0].to_experiment_id(), "{}", "{}")
reservation_id3 = status3.reservation_id
# wait until it is reserved
short_time = 0.1
times = 10.0 / short_time
while times > 0:
time.sleep(short_time)
new_status = self.client.get_reservation_status(reservation_id1)
if not isinstance(new_status, Reservation.WaitingConfirmationReservation):
break
times -= 1
# first user got the device. The other two are in WaitingReservation
reservation1 = self.client.get_reservation_status(reservation_id1)
self.assertTrue(isinstance(reservation1, Reservation.ConfirmedReservation))
reservation2 = self.client.get_reservation_status(reservation_id2)
self.assertTrue(isinstance(reservation2, Reservation.WaitingReservation))
self.assertEquals( 0, reservation2.position)
reservation3 = self.client.get_reservation_status(reservation_id3)
self.assertTrue(isinstance(reservation3, Reservation.WaitingReservation))
self.assertEquals( 1, reservation3.position)
# Another user tries to reserve the experiment. He goes to the WaitingReservation, position 2
status4 = self.client.reserve_experiment(session_id4, dummy_experiments4[0].to_experiment_id(), "{}", "{}")
reservation_id4 = status4.reservation_id
reservation4 = self.client.get_reservation_status(reservation_id4)
self.assertTrue(isinstance( reservation4, Reservation.WaitingReservation))
self.assertEquals( 2, reservation4.position)
# The state of other users does not change
reservation1 = self.client.get_reservation_status(reservation_id1)
self.assertTrue(isinstance( reservation1, Reservation.ConfirmedReservation))
reservation2 = self.client.get_reservation_status(reservation_id2)
self.assertTrue(isinstance( reservation2, Reservation.WaitingReservation))
self.assertEquals( 0, reservation2.position)
reservation3 = self.client.get_reservation_status(reservation_id3)
self.assertTrue(isinstance(reservation3, Reservation.WaitingReservation))
self.assertEquals( 1, reservation3.position )
# The user number 2 frees the experiment
self.client.finished_experiment(reservation_id2)
# Whenever he tries to do poll or send_command, he receives an exception
try:
time.sleep(1)
self.client.poll(reservation_id2)
self.client.poll(reservation_id2)
self.client.poll(reservation_id2)
except Exception as e:
pass # All right :-)
self.assertTrue("does not have any experiment" in repr(e))
else:
self.fail("Expected exception when polling")
# send a program
CONTENT = "content of the program DUMMY1"
self.client.send_file(reservation_id1, ExperimentUtil.serialize(CONTENT), 'program')
# We need to wait for the programming to finish.
response = self.client.send_command(reservation_id1, Command.Command("STATE"))
self.assertEquals("STATE", response.commandstring)
self.client.logout(session_id1)