def test_disconnect(self): speedify.connect_closest() state = speedify.show_state() self.assertEqual(state, State.CONNECTED) speedify.disconnect() state = speedify.show_state() self.assertEqual(state, speedify.State.LOGGED_IN)
def test_bad_country(self): #logging.disable(logging.ERROR); logging.info("Testing error handling, ignore next few errors") state = speedify.show_state() self.assertEqual(state, State.LOGGED_IN) logging.debug("connecting to bad country") with self.assertRaises(SpeedifyAPIError): speedify.connect_country("pp") logging.debug("after connecting to bad country") state = speedify.show_state() self.assertEqual(state, State.LOGGED_IN) logging.info("Done testing error handling")
def confirm_state_speedify(state=State.LOGGED_IN): "Confirms with a True|False whether speedify is in state you pass in" desc = speedify.show_state() if state == desc: return True else: logging.error("confirmStateSpeedify Failed command results: " + str(desc)) return False
def test_connect_country(self): serverinfo = speedify.connect_country("sg") state = speedify.show_state() self.assertEqual(state, State.CONNECTED) self.assertIn("tag", serverinfo) self.assertIn("country", serverinfo) self.assertEqual(serverinfo["country"], "sg") new_serverinfo = speedify.show_currentserver() self.assertEqual(new_serverinfo["country"], "sg")
def test_connect(self): serverinfo = speedify.connect_closest() state = speedify.show_state() self.assertEqual(state, State.CONNECTED) self.assertIn("tag", serverinfo) self.assertIn("country", serverinfo)
import sys sys.path.append('../') import speedify from speedify import State, SpeedifyError, Priority ''' This sample connects to the closest server and configures some speedify settings ''' if (len(sys.argv) > 2): user = sys.argv[1] password = sys.argv[2] state = speedify.show_state() print("Speedify's state is " + str(state)) if (state == State.LOGGED_OUT): try: speedify.login(user, password) except Exception: print("Error could not login!") sys.exit(1) try: if (speedify.show_state() != State.LOGGED_IN): # get to LOGGED_IN state speedify.disconnect() state = speedify.show_state() print("Speedify's state is " + str(state)) except SpeedifyError: pass try:
def main(): if len(sys.argv) > 1: #arguments specified on command line attributes = [] for arg in sys.argv: if arg in possible_attributes: attributes.append( arg ) else: logging.info("Need to pass in list of attributes to test") logging.info("Possible attributes: " + str(possible_attributes)) sys.exit(1) logging.info("Testing with attributes: " + str(attributes)) rounds = math.pow(2, len(attributes)) # find the fastest server connect = speedify.connect_closest() # pull its name so we can connect directly from now on and no risk Getting # a different server server = connect["tag"] logging.info("Testing using server: " + server) # best results yet best_download = -1 best_download_attributes = [] best_upload = -1 best_upload_attributes = [] failed = False i = 0 logging.info("== START ==") while i < rounds : logging.info ("Loop: " + str(i)) attributecount = 0 atval = False # list of True|Falses same length as the list of attributes to be tested current_attributes = [] # builds a logical table, first attribute alternates, second switches every # two, third attribute, every 4, so that every possible combination gets tried and tested for x in attributes : attributecount = attributecount + 1 demonin = math.pow(2,attributecount) atval = True if i % demonin < (demonin / 2) else False current_attributes.append(atval) set_all_attr(attributes, current_attributes) print_all_attr(attributes,current_attributes) i = i + 1 speedify.connect(server) state = speedify.show_state() if state != State.CONNECTED: time.time() logging.error("Did not connect!") failed = True; break trcattempts = 0 trc = False while trcattempts < 30: # lets make sure internet is working before proceeding # typically takes a dozen times through this loop before # we start seeing it really work. think that's just windows. try: if speedifyutil.using_speedify(): trc = True break except FileNotFoundError: sys.exit(1) trcattempts = trcattempts +1 # internet can take a bit, give it some time time.sleep(0.2) if not trc: logging.warning("Speedify not providing internet!") continue speedresult = speedify.speedtest() if (speedresult["status"] != "complete"): logging.warning("Speedtest did not complete!") else: for result in speedresult["connectionResults"]: if result["adapterID"] == "speedify": down = int(result["downloadBps"]) up = int(result["uploadBps"]) logging.info("download speed - " + str(sizeof_fmt(down)) + "bps") if down > best_download: logging.info(" best download yet!") best_download = down best_download_attributes = list(current_attributes) logging.info("upload speed - " + str(sizeof_fmt(up)) + "bps") if up > best_upload: logging.info(" best upload yet!") best_upload = up best_upload_attributes = list(current_attributes) speedify.disconnect() if not failed: logging.info("== DONE ==") logging.info("best download : " + str(sizeof_fmt(best_download)) + "bps") print_all_attr(attributes,best_download_attributes) logging.info("best upload : " + str(sizeof_fmt(best_upload)) + "bps") print_all_attr(attributes,best_upload_attributes) logging.info("Applying best download values") set_all_attr(attributes,best_download_attributes ) else: logging.error("== FAILED ==") sys.exit(1)