def run(self): log.info("Starting module '%s'..." % self.name) try: __import__(self.fullname) except: import sys, traceback trace = "".join(map(lambda trace: " " + trace, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))) self.root.errors.append("In module '%s':\n%s" % (self.fullname, trace)) raise log.ok("Module '%s' finished." % self.name) return True
def run(self): log.info("Starting module '%s'..." % self.name) try: __import__(self.fullname) except: import sys, traceback trace = "".join( map( lambda trace: " " + trace, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))) self.root.errors.append("In module '%s':\n%s" % (self.fullname, trace)) raise log.ok("Module '%s' finished." % self.name) return True
def run(self): import sys, traceback result = True log.info("Starting group '%s'..." % self.name) try: __import__(self.fullname) except: log.error( "Error occurred during initialization of package '%s'." % self.fullname, False) raise for module in self.modules: if not module.exists: if not self.ignore_non_existent: self.root.errors.append( "In group '%s':\n Module '%s' does not exist." % (self.name, module.fullname)) log.error("Module '%s' does not exist." % module.fullname) else: log.error("Module '%s' does not exist." % module.fullname, False) continue try: result = module.run() and result except: result = False if isinstance(module, Group): log.error("Group '%s' failed." % module.name, False) else: log.error("Module '%s' failed." % module.name, False) if not self.ignore_failed: raise else: log.message("".join( traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))) log.ok("Group '%s' finished." % self.name) return result
def run(host, config, port=None, http=False): from os.path import dirname, normpath, join from plamee.config import ConfigParser, Group Net.connect(host=host, port=port, http=http) dir = dirname(__file__) parser = ConfigParser(config) root = Group("plamee", dir=normpath(join(dir, "../../../"))) prnt = root prnt.ignore_failed = True chld = Group("cakestory", prnt) prnt.modules.append(chld) prnt = chld prnt.ignore_failed = True chld = Group("test", prnt) prnt.modules.append(chld) try: chld.parse(parser) except: log.error(sys.exc_value.message, False) __exit() result = False try: result = chld.run() except: log.error("Group 'test' failed.", False) log.message("".join( traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))) log.info("All tests finished.") if not result: __exit(root.errors) else: log.ok("All tests successfully passed.")
def run(host, config, port=None, http=False) : from os.path import dirname, normpath, join from plamee.config import ConfigParser, Group Net.connect(host=host, port=port, http=http) dir = dirname(__file__) parser = ConfigParser(config) root = Group("plamee", dir=normpath(join(dir, "../../../"))) prnt = root prnt.ignore_failed = True chld = Group("cakestory", prnt) prnt.modules.append(chld) prnt = chld prnt.ignore_failed = True chld = Group("test", prnt) prnt.modules.append(chld) try: chld.parse(parser) except: log.error(sys.exc_value.message, False) __exit() result = False try: result = chld.run() except: log.error("Group 'test' failed.", False) log.message("".join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))) log.info("All tests finished.") if not result: __exit(root.errors) else: log.ok("All tests successfully passed.")
def run(self): import sys, traceback result = True log.info("Starting group '%s'..." % self.name) try: __import__(self.fullname) except: log.error("Error occurred during initialization of package '%s'." % self.fullname, False) raise for module in self.modules: if not module.exists: if not self.ignore_non_existent: self.root.errors.append("In group '%s':\n Module '%s' does not exist." % (self.name, module.fullname)) log.error("Module '%s' does not exist." % module.fullname) else: log.error("Module '%s' does not exist." % module.fullname, False) continue try: result = module.run() and result except: result = False if isinstance(module, Group): log.error("Group '%s' failed." % module.name, False) else: log.error("Module '%s' failed." % module.name, False) if not self.ignore_failed: raise else: log.message("".join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))) log.ok("Group '%s' finished." % self.name) return result
def login(self): # Get login form log.debug("Facebook: Fetching login form...") response = FacebookRequest(self, FacebookContext.FACEBOOK_HOST, FacebookContext.FACEBOOK_LOGIN_URL).evaluate() log.debug("Facebook: Parsing login form...") # Find JS cookies js_datr = re.search("\"_js_datr\",\\s*\"(.*?)\"", response.response) js_gate = re.search("\"_js_reg_fb_gate\",\\s*\"(.*?)\"", response.response) js_ref = re.search("\"_js_reg_fb_ref\",\\s*\"(.*?)\"", response.response) if js_datr is not None: self.set_cookie("_js_datr", js_datr.group(1)) if js_gate is not None: self.set_cookie("_js_reg_fb_gate", js_gate.group(1)) if js_ref is not None: self.set_cookie("_js_reg_fb_ref", js_ref.group(1)) # Parse login form form = utils.html.get_tag(response, "form", {"id": "login_form"}) data = _FBLoginFormParser.parse(form) data["email"] = self.user data["pass"] = self.password url = utils.html.get_tag_attr(form, "action") # Try to sign in log.debug("Facebook: Trying to sign in as \"%s\" via %s..." % (data["email"], FacebookContext.FACEBOOK_HOST + url)) response = FacebookRequest(self, FacebookContext.FACEBOOK_HOST, url, data).evaluate() # If redirect - OK if response.status == 302: log.ok("Facebook: Signed in as \"%s\"" % data["email"]) self.logged = True else: raise RuntimeError("Facebook sign-in failed.")
return json.loads(config) def get_config(): config = get_local_config() if config is None: config = get_defs_config() if config is None: raise RuntimeError("Cannot found A/B-test config.") return config config = get_config() if len(config.keys()) > 0: log.ok("A/B tests found: %s." % ", ".join(config.keys())) else: raise RuntimeError("No A/B tests found.") if len(config.keys()) > 1: raise RuntimeError( "Cannot proccess more than 1 test at once but defs contain %d values: %s." % (len(config.keys()), ", ".join(config.keys()))) ab_test_name = None for ab_test_name in config: config = config[ab_test_name] break log.ok("Selected A/B test: %s." % ab_test_name)
return json.loads(config) def get_config(): config = get_local_config() if config is None: config = get_defs_config() if config is None: raise RuntimeError("Cannot found A/B-test config.") return config config = get_config() if len(config.keys()) > 0: log.ok("A/B tests found: %s." % ", ".join(config.keys())) else: raise RuntimeError("No A/B tests found.") if len(config.keys()) > 1: raise RuntimeError("Cannot proccess more than 1 test at once but defs contain %d values: %s." % (len(config.keys()), ", ".join(config.keys()))) ab_test_name = None for ab_test_name in config: config = config[ab_test_name] break log.ok("Selected A/B test: %s." % ab_test_name) #threshold = config["threshold"] #if threshold > 1.0: