示例#1
0
def factory(model, **kwargs):
    """
    Creates a factory boy factory class
    """

    ns = {'Meta': type('Meta', (), {'model': model})}

    # Handle explicitly declared values
    for k, v in kwargs:
        ns[k] = explicit_declaration(model, k, v)

    # Create mommy instance to help with automatic value generation
    mommy = Mommy(model)

    # Create implicit declarations
    for field in model._meta.fields:
        if not requires_declaration(model, field.name, ns):
            continue
        ns[field.name] = implicit_declaration(model, field.name, ns, mommy)

    return type(model.__name__ + 'Factory', (BoogieFactory, ), ns)
示例#2
0
def exist_a_project(step):
    for project_hashes in step.hashes:
        mom = Mommy(Project, False)
        project = mom.make_one(name=project_hashes.get('name'))
示例#3
0
def exist_a_news(step):
    for news_hashes in step.hashes:
        mom = Mommy(News, False)
        news = mom.make_one(title=news_hashes.get('title'),
                            summary=news_hashes.get('summary'))
示例#4
0
def exist_a_tool(step):
    for tool_hashes in step.hashes:
        mom = Mommy(Tool, False)
        tool = mom.make_one(name=tool_hashes.get('name'),
                            highlight=tool_hashes.get('highlight'))