예제 #1
0
def test():
    django.setup()
    feature = Feature.objects.get(pk=1)
    generate_feature_plain_text = FeatureFileGenerator.generate_feature(feature)
    workspace = WorkSpace.objects.get(pk=2)
    feature = Feature.objects.first()
    FeatureFileGenerator.save_feature_file(feature,workspace)
    return generate_feature_plain_text
예제 #2
0
파일: views.py 프로젝트: danbao/todpy
def update_feature(request, feature_id):
    if request.method != 'POST':
        return HttpResponse("only post allowed")
    # elif: feature locked should early return
    else:
        json_data = request.body
        updater = StepDtoPostUpdater()
        result = updater.update(json_data)
        workspace = WorkSpace.objects.get(pk=result.workspace)
        FeatureFileGenerator.update_feature_file(result, workspace, json_data)
        return HttpResponse(request.body)
예제 #3
0
파일: views.py 프로젝트: danbao/todpy
def save_feature(request):
    if request.method != 'POST':
        return HttpResponse("only post allowed")
    # elif: feature locked should early return
    else:
        try:
            json_data = request.body
            saver = StepDtoPostSaver()
            result = saver.save(json_data)
            item_id = result.id
            workspace = WorkSpaceGenerater.gen_workspace('web')
            FeatureFileGenerator.save_feature_file(result, workspace, json_data)
            result.update_workspace(workspace)
            return HttpResponse(item_id);
        except exceptions:
            return HttpResponse(content='error', content_type=None, status=500, reason='save error')
예제 #4
0
def test():
    django.setup()
    feature_id = 1
    feature = Feature.objects.filter(id=feature_id).first()
    workspace = WorkSpace.objects.get(pk=feature.workspace)
    workspace_path = workspace.getFolderPath()
    dict = Step.getStepByFolder(workspace_path)
    file_path = FeatureFileGenerator.get_workspace_entrance(workspace)
    feature = lettuce.Feature.from_file(file_path)
    feature_dto = FeatureDto(feature.name, feature.description)
    scenarios = []
    for sce in feature.scenarios:
        s_dto = ScenarioDto('id_missing', sce.name)
        for s_item in sce.steps:
            co_func, patten, result = match_definision(s_item, dict)
            action_type, varlist_tuple, variables = extract_func_info(co_func, s_item, result)
            step_dto = StepDto()
            func_code = co_func.func_code
            step_dto.fill(func_code.co_filename, func_code.co_firstlineno, func_code.co_argcount,
                          varlist_tuple, func_code.co_name, co_func.func_name, action_type, variables, patten,
                          'id_no_use')
            s_dto.steps.append(step_dto)
        scenarios.append(s_dto)
    feature_dto.fill_scenarios(scenarios)
    return json.dumps((feature_dto), cls=DataEncoder)
예제 #5
0
def test():
    django.setup()
    all_steps = '''{
        "feature": {
            "feature_name": "first feature name",
            "feature_description": "I want to test this first test case for fun",
            "feature_id": "new",
            "scenarios": [
                {
                    "scenario_name": "first scenario",
                    "scenario_id": "new",
                    "steps": [
                        {
                            "new": {
                                "action_type": "Given",
                                "co_firstlineno": 8,
                                "co_name": "i_open_browser",
                                "step_name": "I open web browser",
                                "co_argcount": 1,
                                "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                "co_varnames": [
                                    "step"
                                ],
                                "co_variables":{},
                                "description":"I open web browser"
                            }
                        },
                        {
                            "new": {
                                "action_type": "Then",
                                "co_firstlineno": 13,
                                "co_name": "i_open_page",
                                "step_name": "I open page '([^']*)'",
                                "co_argcount": 2,
                                "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                "co_varnames": [
                                    "step",
                                    "url"
                                ],
                                "co_variables": {"url":"http://cn.bing.com/"},
                                "description": "I open page 'http://cn.bing.com/'"
                            }
                        },
                        {
                            "new": {
                                "action_type": "When",
                                "co_firstlineno": 14,
                                "co_name": "i_click_element_with_text",
                                "step_name": "I click element with text '([^']*)'",
                                "co_argcount": 2,
                                "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_click.py",
                                "co_varnames": [
                                    "step",
                                    "text",
                                    "element"
                                ],
                                "co_variables":{"text":"button"},
                                "description":"I click element with text 'button'"
                            }
                        },
                        {
                            "new": {
                                "action_type": "Then",
                                "co_firstlineno": 18,
                                "co_name": "i_close_browser",
                                "step_name": "I close web browser",
                                "co_argcount": 1,
                                "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                "co_varnames": [
                                    "step"
                                ],
                                "co_variables":{},
                                "description":"I close web browser"
                            }
                        }
                    ]
                },
                {
                    "scenario_name": "second scenario",
                    "scenario_id": "new",
                    "steps": [
                        {
                            "new": {
                                "action_type": "When",
                                "co_firstlineno": 8,
                                "co_name": "i_open_browser",
                                "step_name": "I open web browser",
                                "co_argcount": 1,
                                "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                "co_varnames": [
                                    "step"
                                ],
                                "co_variables":{},
                                "description":"I open web browser"
                            }
                        },
                        {
                            "new": {
                                "action_type": "Then",
                                "co_firstlineno": 13,
                                "co_name": "i_open_page",
                                "step_name": "I open page '([^']*)'",
                                "co_argcount": 2,
                                "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                "co_varnames": [
                                    "step",
                                    "url"
                                ],
                                "co_variables": {"url":"http://www.baidu.com"},
                                "description": "I open page 'http://www.baidu.com/'"
                            }
                        }
                    ]
                }
            ]
        }
    }'''
    workspace = WorkSpaceGenerater.gen_workspace('web')
    saver = StepDtoPostSaver()
    result = saver.save(all_steps)
    result.update_workspace(workspace)
    FeatureFileGenerator.save_feature_file(result, workspace, all_steps)
    # print result
    return result
예제 #6
0
파일: models.py 프로젝트: danbao/todpy
 def generate_feature(self):
     return FeatureFileGenerator.generate_feature(self)
     return plain_text
예제 #7
0
def test():
    django.setup()
    all_steps = '''{
            "feature": {
                "feature_name": "test okcoin user reg form",
                "feature_description": "just for test",
                "feature_id": 1,
                "scenarios": [
                    {
                        "scenario_name": "first updated scenario",
                        "scenario_id": 1,
                        "steps": [
                            {
                                "1": {
                                    "action_type": "Given",
                                    "co_firstlineno": 8,
                                    "co_name": "i_open_browser",
                                    "step_name": "I open web browser",
                                    "co_argcount": 1,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                    "co_varnames": [
                                        "step"
                                    ],
                                    "co_variables":{},
                                    "description":"I open web browser"
                                }
                            },
                            {
                                "new": {
                                    "action_type": "When",
                                    "co_firstlineno": 13,
                                    "co_name": "i_open_page",
                                    "step_name": "I open page '([^']*)'",
                                    "co_argcount": 2,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                    "co_varnames": [
                                        "step",
                                        "url"
                                    ],
                                    "co_variables": {"url":"http://www.okcoin.com/"},
                                    "description": "I open page 'http://www.okcoin.com/'"
                                }
                            },
                            {
                                "3": {
                                    "action_type": "Then",
                                    "co_firstlineno": 14,
                                    "co_name": "i_click_element_with_text",
                                    "step_name": "I click element with text '([^']*)'",
                                    "co_argcount": 2,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_click.py",
                                    "co_varnames": [
                                        "step",
                                        "text",
                                        "element"
                                    ],
                                    "co_variables":{"text":"buy"},
                                    "description":"I click element with text 'Trade'"
                                }
                            },
                            {
                                "new": {
                                    "action_type": "Then",
                                    "co_firstlineno": 14,
                                    "co_name": "i_click_element_with_text",
                                    "step_name": "I click element with text '([^']*)'",
                                    "co_argcount": 2,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_click.py",
                                    "co_varnames": [
                                        "step",
                                        "text",
                                        "element"
                                    ],
                                    "co_variables":{"text":"Sign Up"},
                                    "description":"I click element with text 'Sign Up'"
                                }
                            },
                            {
                                "new": {
                                    "action_type": "Then",
                                    "co_firstlineno": 18,
                                    "co_name": "i_close_browser",
                                    "step_name": "I input '([^']*)' into textbox with id '([^']*)'",
                                    "co_argcount": 2,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_edit.py",
                                    "co_varnames": [
                                        "step",
                                        "text",
                                        "id"
                                    ],
                                    "co_variables":{},
                                    "description":"I input '*****@*****.**' into textbox with id 'regUserName'"
                                }
                            },
                            {
                                "new": {
                                    "action_type": "Then",
                                    "co_firstlineno": 18,
                                    "co_name": "i_close_browser",
                                    "step_name": "I input '([^']*)' into textbox with id '([^']*)'",
                                    "co_argcount": 2,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_edit.py",
                                    "co_varnames": [
                                        "step",
                                        "text",
                                        "id"
                                    ],
                                    "co_variables":{},
                                    "description":"I input '123456' into textbox with id 'regPassword'"
                                }
                            },
                            {
                                "new": {
                                    "action_type": "Then",
                                    "co_firstlineno": 18,
                                    "co_name": "i_close_browser",
                                    "step_name": "I input '([^']*)' into textbox with id '([^']*)'",
                                    "co_argcount": 2,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_edit.py",
                                    "co_varnames": [
                                        "step",
                                        "text",
                                        "id"
                                    ],
                                    "co_variables":{},
                                    "description":"I input '123456' into textbox with id 'regRePassword'"
                                }
                            },
                            {
                                "new": {
                                    "action_type": "Then",
                                    "co_firstlineno": 18,
                                    "co_name": "i_click_element_with_id",
                                    "step_name": "I click element with id '([^']*)'",
                                    "co_argcount": 2,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_click.py",
                                    "co_varnames": [
                                        "step",
                                        "id"
                                    ],
                                    "co_variables":{},
                                    "description":"I click element with id 'agree'"
                                }
                            },
                            {
                                "new": {
                                    "action_type": "Then",
                                    "co_firstlineno": 18,
                                    "co_name": "i_click_element_with_id",
                                    "step_name": "I click element with id '([^']*)'",
                                    "co_argcount": 2,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_click.py",
                                    "co_varnames": [
                                        "step",
                                        "id"
                                    ],
                                    "co_variables":{},
                                    "description":"I click element with id 'regBtn'"
                                }
                            },
                            {
                                "4": {
                                    "action_type": "Then",
                                    "co_firstlineno": 4,
                                    "co_name": "i_close_browser",
                                    "step_name": "I close web browser",
                                    "co_argcount": 1,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                    "co_varnames": [
                                        "step"
                                    ],
                                    "co_variables": {},
                                    "description": "I close web browser"
                                }
                            }
                        ]
                    },
                    {
                        "scenario_name": "second new created scenario",
                        "scenario_id": "new",
                        "steps": [
                            {
                                "new": {
                                    "action_type": "Given",
                                    "co_firstlineno": 8,
                                    "co_name": "i_open_browser",
                                    "step_name": "I open web browser",
                                    "co_argcount": 1,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                    "co_varnames": [
                                        "step"
                                    ],
                                    "co_variables":{},
                                    "description":"I open web browser"
                                }
                            },
                            {
                                "new": {
                                    "action_type": "When",
                                    "co_firstlineno": 13,
                                    "co_name": "i_open_page",
                                    "step_name": "I open page '([^']*)'",
                                    "co_argcount": 2,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                    "co_varnames": [
                                        "step",
                                        "url"
                                    ],
                                    "co_variables": {"url":"http://cn.bing.com/"},
                                    "description": "I open page 'http://cn.bing.com/'"
                                }
                            },
                            {
                                "new": {
                                    "action_type": "Then",
                                    "co_firstlineno": 4,
                                    "co_name": "i_close_browser",
                                    "step_name": "I close web browser",
                                    "co_argcount": 1,
                                    "co_file_name": "/Users/bob.zhu/project/todpy/libraries/web/action/features/web_browser.py",
                                    "co_varnames": [
                                        "step"
                                    ],
                                    "co_variables": {},
                                    "description": "I close web browser"
                                }
                            }
                        ]
                    }
                ]
            }
        }'''

    updater = StepDtoPostUpdater()
    result = updater.update(all_steps)
    workspace = WorkSpace.objects.get(pk=result.workspace)
    FeatureFileGenerator.update_feature_file(result, workspace, all_steps)
    return result