示例#1
0
 def process_testcase(self, testcaseclass, update=False, name=None):
     update = update or self.force
     TC = models.TestCases
     impl = "{}.{}".format(testcaseclass.__module__, testcaseclass.__name__)
     name = name or impl.replace("testcases.", "")
     # Don't import submodules that start with underscores.
     if "._" in impl:
         return
     exists = TC.select().where(TC.name == name).exists()
     if exists and not update:
         return TC.select().where(TC.name == name).get()
     doc = inspect.cleandoc(testcaseclass.__doc__ or impl)
     if not doc:
         doc = name
     kwargs = {}
     doctree = docutils_core.publish_doctree(doc)
     parts = get_rendered_sections(doctree)
     for section_id, colname in (("purpose", "purpose"), ("pass-criteria",
                                                          "passcriteria"),
                                 ("start-condition", "startcondition"),
                                 ("end-condition", "endcondition"),
                                 ("procedure", "procedure")):
         kwargs[colname] = parts.get(section_id)
     # handle non-template simple docstrings. They are assumed to be the
     # purpose.
     if not kwargs["purpose"]:
         kwargs["purpose"] = plain_doc(doc)
     kwargs["purpose_search"] = fn.to_tsvector(kwargs.get("purpose"))
     if exists:
         q = TC.update(**kwargs).where(TC.name == name)
         q.execute()
     else:
         kwargs["name"] = name
         kwargs["testimplementation"] = impl
         return TC.create(**kwargs)
示例#2
0
def import_probes(product, probes):
    data = []
    for probe in probes:
        definition = probe.definition
        description = definition["description"]

        data.append({
            "product":
            product,
            "name":
            probe.name,
            "type":
            probe.type,
            "description":
            description,
            "definition":
            definition,
            "index":
            fn.to_tsvector("english", " ".join([probe.name, description])),
        })

    with db.atomic():
        for batch in chunked(data, 100):
            (Probes.insert_many(batch).on_conflict(
                conflict_target=[Probes.product, Probes.name],
                update={
                    Probes.description: EXCLUDED.description,
                    Probes.definition: EXCLUDED.definition,
                    Probes.index: EXCLUDED.index,
                },
            ).execute())
    log("Imported {n:,} probes for {product}".format(n=len(probes),
                                                     product=product))
示例#3
0
 def add_article(self, date, section, title, fly, desc, id, origin, content,
                 images, summary):
     try:
         a = Article(edition=date,
                     section=section,
                     title=title,
                     fly=fly,
                     rubric=desc,
                     name=id,
                     origin=origin,
                     content=content,
                     imgs=images,
                     summary=summary,
                     tsv=fn.to_tsvector(content))
         a.save()
     except Exception as e:
         print('insert article error ', e)
示例#4
0
 def process_testsuite(self, suiteclass, update=False, name=None, doc=None):
     update = update or self.force
     MODEL = models.TestSuites
     impl = "{}.{}".format(suiteclass.__module__, suiteclass.__name__)
     name = name or impl.replace("testcases.", "")
     if "._" in impl:
         return
     exists = MODEL.select().where(MODEL.name == name).exists()
     if exists and not update:
         return MODEL.select().where(MODEL.name == name).get()
     kwargs = {}
     doc = inspect.cleandoc(doc or suiteclass.__doc__ or name)
     kwargs["purpose"] = plain_doc(doc)
     kwargs["search_purpose"] = fn.to_tsvector(doc)
     kwargs["suiteimplementation"] = impl
     if exists:
         q = MODEL.update(**kwargs).where(MODEL.name == name)
         q.execute()
     else:
         kwargs["name"] = name
         return MODEL.create(**kwargs)
示例#5
0
 def process_scenario(self, scenarioclass, update=False):
     update = update or self.force
     MODEL = models.Scenario
     impl = "{}.{}".format(scenarioclass.__module__, scenarioclass.__name__)
     if "._" in impl:
         return
     exists = MODEL.select().where(MODEL.implementation == impl).exists()
     if exists and not update:
         return
     doc = inspect.cleandoc(scenarioclass.__doc__ or impl)
     # Don't import classes that don't have documentation.
     if not doc:
         return
     kwargs = {}
     kwargs["name"] = impl.replace("testcases.", "")
     kwargs["purpose"] = plain_doc(doc)
     kwargs["purpose_search"] = fn.to_tsvector(doc)
     if exists:
         q = MODEL.update(**kwargs).where(MODEL.implementation == impl)
         q.execute()
     else:
         kwargs["implementation"] = impl
         MODEL.create(**kwargs)
示例#6
0
def ts_match(field, query, regconfig='spanish'):
    return Expression(fn.to_tsvector(regconfig, field), OP.TS_MATCH, fn.plainto_tsquery(regconfig, query))
示例#7
0
def ts_rank(field, query, regconfig='spanish'):
    # return Expression(fn.to_tsvector(regconfig, field), OP.TS_MATCH, fn.plainto_tsquery(regconfig, query))
    return Expression(fn.ts_rank_cd(fn.to_tsvector(regconfig, field), fn.plainto_tsquery(regconfig, query)))