def form_example(): err = None genResult = None message = "" source = None gen = None if request.method == 'POST': try: source = request.form.get('source') alias = request.form.get('generator') generatorId = Generators.generatorIdForAlias(alias) outputType = request.form.get(generatorId + '-output') gen = Generators.get(generatorId) if gen is None: raise Exception("invalid generator %s", generatorId) genResult = gen.generate(alias, source, outputType, useCached=True) if not genResult.isValid(): raise Exception("could not generate %s for %s", outputType, generatorId) except Exception as ex: err = ex return index(err=err, message=message, source=source, gen=gen, genResult=genResult)
def testExamples(self): for gen in Generators.generators(): for alias in gen.aliases: txt = Example.get(alias) if debug: print(txt) assert not "no example for" in txt
def testGenerateResult(self): ''' test provoked error ''' genid = Generators.generatorIdForAlias("plantuml") gen = Generators.get(genid) # provoke an error result = gen.generate('unknownalias', 'garbage input', "png") json = result.asJson('http://www.doe.com') print(json) # there is an image version of the error assert os.path.isfile(result.path) # which needs to be remove to make the test reproducible os.remove(result.path) assert "error" in json
def testGetGenerator(self): generators = ["graphviz", "mscgen", "plantuml"] for generator in generators: gen = Generators.get(generator) assert gen is not None info = gen.getHtmlInfo() if debug: print(info)
def index(err=None, gen='dot', source="", message="", genResult=None): """ render index page with the given parameters""" return render_template('index.html', gen=gen, gens=Generators.generators(), err=err, message=message, source=source, genResult=genResult)
def renderForWikiExtension(): """ endpoint for diagrams extension""" generator = request.form.get('generator') source = request.form.get('source') types = request.form.get('types') gen = Generators.get(generator) ip = request.remote_addr result = gen.generate('dot', source, 'png') json = result.asJson(request.base_url) return json
def testGenerators(self): if debug: print("outputDirectory is: %s" % (Generator.getOutputDirectory())) for gen in Generators.generators(): gen.debug = debug for alias in gen.aliases: txt = Example.get(alias) result = gen.generate(alias, txt, "png") valid = result.isValid() if not valid: print(result.errMsg()) assert valid
def renderForWikiExtension(): """ endpoint for diagrams extension""" generator=getParam('generator') source=getParam('source') targetFormat=getParam('types') if targetFormat is None or targetFormat=="None": targetFormat="png" gen=Generators.get(generator) # use for DOS attack prevention ip=request.remote_addr result=gen.generate('dot',source,targetFormat) # force SSL json=result.asJson(request.base_url.replace('http:','https:')) return json
def check(generator): gen = Generators.get(generator) if gen is not None: return gen.getHtmlInfo() else: return "%s is not a valid generator" % generator
def testGeneratorForAlias(self): for gen in Generators.generators(): gen.debug = debug for alias in gen.aliases: genid = Generators.generatorIdForAlias(alias) assert genid == gen.id
def testGeneratorVersion(self): for gen in Generators.generators(): gen.debug = debug version = gen.getVersion() if debug: print(version)
def testGeneratorCheck(self): for gen in Generators.generators(): gen.debug = debug gen.check()