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
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')
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