本文整理汇总了Python中microgear.client.create函数的典型用法代码示例。如果您正苦于以下问题:Python create函数的具体用法?Python create怎么用?Python create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCode7Case5
def testCode7Case5(self):
"""publish invalid topic - no slash"""
try:
print("run helper...")
code = str(61)
args = ['python', 'helper.py', code]
p = subprocess.Popen(args, cwd=(helper_dir))
time.sleep(connect_worst_timeout)
self.invalidTopic = "firstTopic"
client.create(self.gearkey, self.gearsecret, self.appid)
client.on_connect = MagicMock()
client.connect()
time.sleep(connect_timeout)
self.assertTrue(client.on_connect.called)
self.connected = True
self.assertEqual(client.on_connect.call_count, 1)
client.publish(self.invalidTopic, self.message)
time.sleep(message_timeout)
receiver_file = open(os.path.join(os.getcwd(),"receiver.txt"), "r")
received_message = receiver_file.read()
receiver_file.close()
if(received_message == self.message):
self.received = True
self.assertFalse(self.received)
self.assertTrue(client.on_connect.call_count > 1)
p.kill()
except Exception as e:
p.kill()
raise Exception(e.args)
示例2: connectTo
def connectTo():
gearkey = "qnlgzsPUUxYeyQP"
gearsecret = "1euJPvxybllEPQZzq2u9wpRJXDbjM7"
appid = "testNo3"
client.create(gearkey, gearsecret, appid, {'debugmode': "True"})
def on_connected():
print("connect")
def on_closed():
print("close")
def on_rejected():
print("reject")
def on_error():
print("error")
def on_message():
print("message")
def on_present():
print("present")
def on_absent():
print("absent")
client.on_connect = on_connected
client.on_error = on_error
client.on_present = on_present
client.on_absent = on_absent
client.on_rejected = on_rejected
client.on_closed = on_closed
client.on_message = on_message
logs = LogCapture()
client.connect()
print(logs)
logs.check(('root', 'DEBUG', 'Check stored token.'))
示例3: testCode5Case2
def testCode5Case2(self):
"""subscribe same topic twice"""
try:
print('Code5Case2')
print("run helper...")
code = str(51)
args = ['python', 'helper.py', code]
p = subprocess.Popen(args, cwd=(helper_dir))
time.sleep(connect_worst_timeout)
client.create(self.gearkey, self.gearsecret, self.appid)
client.subscribe(self.topic)
client.subscribe(self.topic)
client.on_connect = MagicMock()
client.on_message = MagicMock()
client.connect()
time.sleep(connect_timeout)
self.assertTrue(client.on_connect.called)
self.connected = True
self.assertEqual(client.on_connect.call_count, 1)
time.sleep(message_timeout)
self.assertTrue(client.on_message.called)
client.on_message.assert_called_with(self.expectedTopic, self.expectedMessage)
p.kill()
#if fails due to assertion error
except Exception as e:
p.kill()
raise Exception(e.args)
示例4: testCode8Case2
def testCode8Case2(self):
"""resettoken when have microgear.cache while microgear is offline"""
self.assertTrue(os.path.isfile(os.path.join(os.getcwd()+"/microgear.cache")))
self.assertIsNone(microgear.gearkey)
self.assertIsNone(microgear.gearsecret)
self.assertIsNone(microgear.appid)
client.create(self.gearkey, self.gearsecret, self.appid)
client.on_connect = MagicMock()
client.resettoken()
self.assertFalse(os.path.isfile(os.path.join(os.getcwd()+"/microgear.cache")))
client.connect()
time.sleep(connect_timeout)
self.assertTrue(client.on_connect.called)
self.assertEqual(client.on_connect.call_count, 1)
self.assertTrue(os.path.isfile(os.path.join(os.getcwd()+"/microgear.cache")))
# def main():
# pass
# #suite = unittest.TestSuite()
# #suite.addTest(TestChat("testCode4Case2"))
# #runner = unittest.TextTestRunner()
# #runner.run(suite)
# print(os.path.join(os.getcwd(),"microgear.cache"))
# unittest.main()
# if __name__ == '__main__':
# main()
示例5: testCode5Case6x2
def testCode5Case6x2(self):
"""subscribe invalid topic - no slash"""
try:
print('Code5Case6x2')
print("run helper...")
code = str(53)
args = ['python', 'helper.py', code]
p = subprocess.Popen(args, cwd=(helper_dir))
time.sleep(connect_worst_timeout)
self.topic = "firstTopic"
client.create(self.gearkey, self.gearsecret, self.appid)
client.subscribe(self.topic)
client.on_connect = MagicMock()
client.on_message = MagicMock()
client.connect()
time.sleep(connect_timeout)
self.assertTrue(client.on_connect.called)
self.connected = True
self.assertEqual(client.on_connect.call_count, 1)
time.sleep(message_timeout)
self.assertFalse(client.on_message.called)
p.kill()
#if fails due to assertion error
except Exception as e:
p.kill()
raise Exception(e.args)
示例6: testCreateNetPieLabel
def testCreateNetPieLabel():
gearkey, gearsecret, appid = testCreateNetPie1();
client.create(gearkey, gearsecret, appid, {'label' : "Microgear Python"})
client.setname('logg')
client.connect()
print("Sleep for 90 seconds")
time.sleep(90)
示例7: testCreateNetPieScopeName
def testCreateNetPieScopeName():
gearkey, gearsecret, appid = testCreateNetPie1();
client.create(gearkey, gearsecret, appid, {'debugmode' : True, 'scope' : "name:logger"})
client.setname('logg')
client.connect()
print("Sleep for 90 seconds")
time.sleep(90)
示例8: testCode6Case1
def testCode6Case1(self):
"""unsubscribe the subscribed topic"""
print('Code6Case1')
try:
print("run helper...")
code = str(51)
args = ['python', 'helper.py', code]
p = subprocess.Popen(args, cwd=(helper_dir))
time.sleep(connect_worst_timeout)
client.create(self.gearkey, self.gearsecret, self.appid)
client.on_connect = MagicMock()
client.on_message = MagicMock()
client.connect()
time.sleep(connect_timeout)
self.assertTrue(client.on_connect.called)
self.connected = True
self.assertEqual(client.on_connect.call_count, 1)
client.subscribe(self.topic)
time.sleep(message_timeout)
self.assertTrue(client.on_message.called)
client.unsubscribe(self.topic)
client.on_message.reset_mock()
self.assertFalse(client.on_message.called)
time.sleep(message_timeout)
self.assertFalse(client.on_message.called)
p.kill()
#if fails due to assertion error
except Exception as e:
p.kill()
raise Exception(e.args)
示例9: testCode6Case2
def testCode6Case2(self):
"""unsubscribe the topic before subscribe"""
print('Code6Case2')
print(microgear.gearkey)
try:
print("run helper...")
code = str(51)
args = ['python', 'helper.py', code]
p = subprocess.Popen(args, cwd=(helper_dir))
time.sleep(connect_worst_timeout)
print(microgear.gearkey)
client.create(self.gearkey, self.gearsecret, self.appid)
client.on_connect = MagicMock()
client.on_message = MagicMock()
client.connect()
time.sleep(connect_timeout)
self.assertTrue(client.on_connect.called)
self.connected = True
self.assertEqual(client.on_connect.call_count, 1)
self.assertFalse(client.on_message.called)
client.unsubscribe(self.topic)
self.assertFalse(client.on_message.called)
client.subscribe(self.topic)
time.sleep(message_timeout)
self.assertTrue(client.on_message.called)
client.on_message.assert_called_with(self.expectedTopic, self.expectedMessage)
p.kill()
except Exception as e:
p.kill()
raise Exception(e.args)
示例10: test
def test():
gearkey = "qnlgzsPUUxYeyQP"
gearsecret = "1euJPvxybllEPQZzq2u9wpRJXDbjM7"
appid = "testNo3"
if(os.path.isfile("microgear.cache")):
f = open((os.getcwd() + "/microgear.cache"), 'r')
print(f.readlines())
f.close()
else:
print("yes1")
client.create(gearkey, gearsecret, appid, {'debugmode': "True", 'scope': "chat:receiver"})
client.setname("sender")
if(os.path.isfile("microgear.cache")):
f = open((os.getcwd() + "/microgear.cache"), 'r')
print(f.readlines())
f.close()
else:
print("yes2")
client.connect()
f = open((os.getcwd() + "/microgear.cache"), 'r')
print(f.readlines())
f.close()
client.resettoken()
if(os.path.isfile("microgear.cache")):
f = open((os.getcwd() + "/microgear.cache"), 'r')
print(f.readlines())
f.close()
else:
print("yes3")
示例11: testCode4Case2
def testCode4Case2(self):
"""chat with other microgear in same appid"""
try:
print('Code4Case2')
print("run helper...")
code = str(31)
args = ['python', 'helper.py', code]
p = subprocess.Popen(args, cwd=(helper_dir))
time.sleep(connect_worst_timeout)
print("run main...")
client.create(self.gearkey, self.gearsecret, self.appid)
client.setalias(self.gearname)
client.on_connect = MagicMock()
client.connect()
time.sleep(connect_timeout)
self.assertTrue(client.on_connect.called)
self.connected = True
client.chat(self.helperGearname, self.message)
time.sleep(message_timeout)
r_file = open(receiver_file, "r")
received_message = r_file.read()
r_file.close()
if(received_message == self.message):
self.received = True
self.assertTrue(self.received)
p.kill()
#if fails due to assertion error
except Exception as e:
print("fail")
raise Exception(e.args)
示例12: testAlias
def testAlias():
gearkey = "qnlgzsPUUxYeyQP"
gearsecret = "1euJPvxybllEPQZzq2u9wpRJXDbjM7"
appid = "testNo3"
client.create(gearkey, gearsecret, appid, {'debugmode': "True", 'alias': "Python"})
client.connect()
while True:
pass
示例13: testConnectWillBlockFalse
def testConnectWillBlockFalse(self):
self.connected = False
def on_connected():
self.connected = True
client.on_connect = on_connected
client.create(self.gearkey, self.gearsecret, self.appid, {'debugmode': "True"})
client.connect(False)
timeout = time.time() + 30.0
if(time.time() > timeout or self.connected):
self.assertTrue(self.connected)
示例14: testCreateNetPieConnection
def testCreateNetPieConnection():
gearkey, gearsecret, appid = testCreateNetPie1();
client.create(gearkey, gearsecret, appid, {'debugmode' : False})
def on_connection():
print "I am connected"
client.on_connect = on_connection
print(client.on_connect == 0)
client.connect()
print("Sleep for 100 seconds")
time.sleep(100)
示例15: testCreateNetPieScopeChat
def testCreateNetPieScopeChat():
gearkey, gearsecret, appid = testCreateNetPie1();
client.create(gearkey, gearsecret, appid, {'debugmode' : True, 'scope' : "chat:java ja"})
client.setname('Python ja')
client.connect()
def receive_message(topic, message):
print topic + " " + message
while(True):
client.chat('Html ka', "Hello html")
time.sleep(3)
client.on_message = receive_message