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()
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")
def testChat(): gearkey = "ExhoyeQoTyJS5Ac" gearsecret = "gzDawaaHRe1KvQhepAw3WYuuGHjBsh" appid = "p107microgear" origin = "oriA" destination = "destX" client.create(gearkey , gearsecret, appid, {'debugmode': True}) bf = open(os.path.join(os.getcwd(),"microgear.cache"), "rb") print(bf) client.resettoken() af = open(os.path.join(os.getcwd(),"microgear.cache"), "rb") print(af)
def testCode8Case1(self): """resettoken when no microgear.cache pre-requisite: no microgear.cache file""" if(os.path.isfile(microgear_cache)): os.remove(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(microgear_cache))
def testCode8Case2(self): """resettoken when have microgear.cache while microgear is offline""" #pre-requisite: ensure there is microgear.cache self.assertIsNone(microgear.gearkey) self.assertIsNone(microgear.gearsecret) self.assertIsNone(microgear.appid) client.create(self.gearkey, self.gearsecret, self.appid, {'debugmode': True}) client.connect(False) self.assertTrue(os.path.isfile(microgear_cache)) #resettoken when have microgear.cache client.resettoken() time.sleep(4) #should delete microgear.cache self.assertFalse(os.path.isfile(microgear_cache))
def testCode8Case3(self): """resettoken twice""" self.assertIsNone(microgear.gearkey) self.assertIsNone(microgear.gearsecret) self.assertIsNone(microgear.appid) client.create(self.gearkey, self.gearsecret, self.appid, {'debugmode': True}) client.connect(False) self.assertTrue(os.path.isfile(microgear_cache)) client.resettoken() self.assertFalse(os.path.isfile(microgear_cache)) client.resettoken() self.assertFalse(os.path.isfile(microgear_cache)) client.on_connect = MagicMock() #should not affect connect 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(microgear_cache))
# appid = "testPythonHelper" client.create(gearkey,gearsecret,appid,{'debugmode': True}) def connection(): print("Now I am connected with netpie") def subscription(topic,message): print(topic+" "+message) # client.publish("mainPython","Hey guy."+str(int(time.time()))) # client.setalias("doraemon2") client.on_connect = connection client.on_message = subscription # client.subscribe("/firstTopic") print('resettoken') client.resettoken() client.resettoken() time.sleep(3) client.connect(False) # while(True): # client.chat("firstTopic","Hello world.") # print("pub") # time.sleep(3) # #need delay print("end") #os.remove(os.path.join(os.getcwd()+"/receiver.txt")) #print(os.path.join(os.getcwd())) #cache_file = open(os.path.join(os.getcwd()+"/microgear.cache"), "r").read() #print(cache_file) #cache_file.write("") #cache_file.close()
def helper(createx=[], setaliasx=[], chatx=[], publishx=[], subscribex=[]): print(createx, setaliasx,chatx,publishx,subscribex) message = "hello" received = False if(len(createx) > 0): print(microgear.gearkey) client.create(createx[0],createx[1],createx[2],{'debugmode': True}) def on_connected(): print("connect") def on_disconnected(): print("disconnected") def on_message(topic, message): print("message") time.sleep(2) ack = open(os.path.join(os.getcwd(),"../receiver.txt"), "w") print(ack) ack.write(message) ack.close() def on_present(gearkey): print("present") def on_absent(gearkey): print("absent") def on_warning(msg): print("reject") def on_info(msg): print("info") def on_error(msg): print("error") client.on_connect = on_connected client.on_disconnect = on_disconnected client.on_message = on_message client.on_present = on_present client.on_absent = on_absent client.on_warning = on_warning client.on_info = on_info client.on_error = on_error if(len(setaliasx) > 0): client.setalias(setaliasx[0]) if(len(subscribex) > 0): client.subscribe(subscribex[0]) client.resettoken() client.connect(False) if(len(chatx) > 0): while True: client.chat(chatx[0], message) print('chitchat') time.sleep(2) if(len(publishx) > 0) : while True: client.publish(publishx[0], message) print('pubpush') time.sleep(2) print("in helper file") print(os.path.join(os.getcwd(),"microgear.cache")) while True: pass