Пример #1
0
def testcaserun_addbug(request, testcaserun_id):

    testcaserun = TestCaseRun.objects.get(pk=testcaserun_id)
    add_bug_form = forms.AddBugForm(request.POST)

    from django.utils.importlib import import_module

    backend_name = getattr(settings, "ISSUE_BACKEND", None)
    issues = import_module(backend_name)

    if add_bug_form.is_valid():
        bugs = []
        for bug_id in add_bug_form.cleaned_data['bugs']:
            try:
                bugs.append(testcaserun.bugs.get_or_create(**issues.Backend.fetch_bug(bug_id))[0])
            except (issues.IssueError, issues.IssueServerError) as e:
                return failed(message="Issue server error meessage: %s" %e)


        log = history.History(request.user, testcaserun.parent)
        log.add_objects(created=bugs, prefix_object=testcaserun)
        log.save()
        return success(message="Issue(s) created.",
                       data=dict(testcaserun=testcaserun.id,
                                 created_bugs=map(lambda x: { "alias" : x.alias,
                                                              "name": x.name,
                                                              "status" : x.status,
                                                              "resolution": x.resolution },
                                                  bugs),
                                 all_bugs=list(testcaserun.bugs.values_list('alias', flat=True))))

    return failed(message="Validation error",
                  data=add_bug_form.errors_list())
Пример #2
0
def testcaserun_addbug(request, testcaserun_id):

    testcaserun = TestCaseRun.objects.get(pk=testcaserun_id)
    add_bug_form = forms.AddBugForm(request.POST)

    if add_bug_form.is_valid():
        from backends.bugs import Bugzilla, IssueError, IssueServerError
        bugs = []
        for bug_id in add_bug_form.cleaned_data['bugs']:
            try:
                bugs.append(testcaserun.bugs.get_or_create(**Bugzilla.fetch_bug(bug_id))[0])
            except (IssueError, IssueServerError) as e:
                return failed(message="Issue server error meessage: %s" %e)


        log = history.History(request.user, testcaserun.parent)
        log.add_objects(created=bugs, prefix_object=testcaserun)
        log.save()
        return success(message="Issue(s) created.",
                       data=dict(testcaserun=testcaserun.id,
                                 created_bugs=map(lambda x: { "alias" : x.alias,
                                                              "name": x.name,
                                                              "status" : x.status,
                                                              "resolution": x.resolution },
                                                  bugs),
                                 all_bugs=list(testcaserun.bugs.values_list('alias', flat=True))))

    return failed(message="Validation error",
                  data=add_bug_form.errors_list())
Пример #3
0
    def execute(self):
        queryset_is_valid, queryset = self.validate_queryset()
        if not queryset_is_valid:
            return failed(message='Check items you want run throught the action')

        form_is_valid, form = self.validate_form()
        if not form_is_valid:
            return failed(message=form.error_message(), data=form.errors_list())

        return self.run_action(self.data, queryset, form)
Пример #4
0
def actions(request, app_label=None, action_name=None, **kwargs):
    allactions = find_actions('qualitio.%s' % app_label)
    for action_class in allactions:
        action = action_class(data=request.POST, request=request)
        if action.name == action_name:
            return action.execute()
    return failed(message="Wrong request")
Пример #5
0
def testrun_valid(request, testrun_id=0):
    if testrun_id:
        testrun = TestRun.objects.get(pk=str(testrun_id))
        testrun_form = forms.TestRunForm(request.POST, instance=testrun, prefix="testrun")

        connected_test_cases_form = forms.ConnectedTestCases(request.POST, instance=testrun,
                                                             prefix="connected_test_cases")
    else:
        testrun_form = forms.TestRunForm(request.POST)
        connected_test_cases_form = forms.ConnectedTestCases(request.POST,
                                                             prefix="connected_test_cases")

    available_test_cases_form = forms.AvailableTestCases(request.POST,
                                                         prefix="available_test_cases")

    if testrun_form.is_valid() and\
            connected_test_cases_form.is_valid() and\
            available_test_cases_form.is_valid():

        testrun = testrun_form.save()
        connected_test_cases_form.save()

        to_run = filter(lambda x: x['action'], available_test_cases_form.cleaned_data)
        to_run = map(lambda x: x['id'], to_run)

        # TODO: slow, greate mass run method
        for test_case in to_run:
            TestCaseRun.run(test_case, testrun)

        return success(message='testrun directory saved',
                       data={"parent_id": getattr(testrun.parent, "id", 0),
                             "current_id": testrun.id})
    else:
        return failed(message="Validation errors",
                      data=testrun_form.errors_list())
Пример #6
0
def testcase_valid(request, testcase_id=0, **kwargs):
    if testcase_id:
        testcase = TestCase.objects.get(pk=str(testcase_id))
        testcase_form = TestCaseForm(request.POST, instance=testcase)
        testcasesteps_form = TestCaseStepFormSet(request.POST, instance=testcase)
    else:
        testcase_form = TestCaseForm(request.POST)
        testcasesteps_form = TestCaseStepFormSet(request.POST)

    if testcase_form.is_valid() and testcasesteps_form.is_valid():
        testcase = testcase_form.save()
        testcasesteps_form.instance = testcase
        testcasesteps_form.save()

        log = history.History(request.user, testcase)
        log.add_form(testcase_form, is_new=(testcase_id == 0))
        log.add_formset(testcasesteps_form)
        log.save()
        return success(
            message="TestCase saved", data={"parent_id": getattr(testcase.parent, "id", 0), "current_id": testcase.id}
        )
    else:
        return failed(
            message="Validation errors: %s" % testcase_form.error_message(),
            data=testcase_form.errors_list() + testcasesteps_form._errors_list(),
        )
Пример #7
0
def report_valid(request, report_id=0, **kwargs):
    if report_id:
        report = Report.objects.get(pk=str(report_id))
        report_form = ReportForm(request.POST, instance=report)
        report_contextelement_formset = ContextElementFormset(request.POST, instance=report)
    else:
        report_form = ReportForm(request.POST)
        report_contextelement_formset = ContextElementFormset(request.POST)

    errors = {}

    if report_form.is_valid() and report_contextelement_formset.is_valid():
        validator = ReportValidator(report_form.cleaned_data['template'],
                                    report_contextelement_formset.context_queries())
        if validator.is_valid():
            report = report_form.save()
            report_contextelement_formset.instance = report
            report_contextelement_formset.save()
            # TODO: the history should be updated here I guess
            return success(message='report saved',
                           data={"parent_id": getattr(report.parent, "id", 0),
                                 "current_id": report.id,
                                 "link": report.link})
        else:
            errors.update(validator.errors)

    errors = report_form.errors_list(additional=errors.items())
    errors.extend(report_contextelement_formset._errors_list())
    return failed(message="Validation errors: %s" % report_form.error_message(),
                  data=errors)
Пример #8
0
def testrun_valid(request, testrun_id=0):
    if testrun_id:
        testrun = TestRun.objects.get(pk=str(testrun_id))
        testrun_form = forms.TestRunForm(request.POST, instance=testrun)

    else:
        testrun_form = forms.TestRunForm(request.POST)

    if testrun_form.is_valid():
        testrun = testrun_form.save()

        testcase_id_list = list(set(request.POST.getlist('connected_test_case')))
        testcases = store.TestCase.objects.filter(pk__in=testcase_id_list)

        created_testcases, deleted_testcases = testrun.testcase_setup(testcases)
        testrun.update_passrate()

        log = history.History(request.user, testrun)
        log.add_form(testrun_form)
        log.add_objects(created=created_testcases, deleted=deleted_testcases)
        log.save()

        return success(message='Test run saved',
                       data={"parent_id": getattr(testrun.parent, "id", 0),
                             "current_id": testrun.id})

    else:
        return failed(message="Validation errors: %s" % testrun_form.error_message(),
                      data=testrun_form.errors_list())
Пример #9
0
def testcaserun_setstatus(request, testcaserun_id):
    testcaserun = TestCaseRun.objects.get(pk=testcaserun_id)
    testcaserun_status_form = forms.TestCaseRunStatus(request.POST, instance=testcaserun)
    if testcaserun_status_form.is_valid():
        testcaserun = testcaserun_status_form.save()

        log = history.History(request.user, testcaserun.parent)
        log.add_form(testcaserun_status_form, capture=["status"], prefix=True)
        log.save()

        # TODO: move this to testrun? method. Chec also templatetags
        passrate_ratio = []
        testrun = testcaserun.parent
        testcaseruns_count = testrun.testcases.count()
        statuses = TestCaseRunStatus.objects.filter(testcaserun__parent=testrun).annotate(count=Count('testcaserun'))
        for status in statuses:
            passrate_ratio.append({
                "ratio": float(status.count) / float(testcaseruns_count) * 100,
                "name": status.name,
                "color": status.color,
                })

        return success(message=testcaserun.status.name,
                       data=dict(id=testcaserun.pk,
                                 name=testcaserun.status.name,
                                 color=testcaserun.status.color,
                                 passrate=testcaserun.parent.passrate,
                                 passrate_ratio=passrate_ratio))
    else:
        return failed(message=testcaserun.status.name,
                      data=testcaserun_status_form.errors_list())
Пример #10
0
def edit_valid(request, word_id=0, **kwargs):
    if word_id:
        word = Word.objects.get(pk=word_id)
        word_form = WordForm(request.POST, instance=word)
        representation_form_list = RepresentationFormsSet(request.POST, word=word)

    else:
        word_form = WordForm(request.POST)
        representation_form_list = RepresentationFormsSet(request.POST)

    if word_form.is_valid() and representation_form_list.is_valid():
        word = word_form.save()
        for language, representation_form in representation_form_list:
            representation = representation_form.save(commit=False)
            representation.word = word
            representation.language = language
            representation.save()

        return success(message='Word saved',
                       data={"id": word.pk,
                             "name": word.name})

    else:
        return failed(message="Validation errors: %s" % word_form.error_message(),
                      data=word_form.errors_list())
Пример #11
0
def report_valid(request, report_id=0):
    if report_id:
        report = Report.objects.get(pk=str(report_id))
        report_form = ReportForm(request.POST, instance=report)
        report_contextelement_formset = ContextElementFormset(request.POST, instance=report)
    else:
        report_form = ReportForm(request.POST)
        report_contextelement_formset = ContextElementFormset(request.POST)

    if report_form.is_valid() and report_contextelement_formset.is_valid():
        report = report_form.save()
        report_contextelement_formset.instance = report
        report_contextelement_formset.save()

        # log = history.History(request.user, report)
        # log.add_form(report_form)
        # log.add_objects(created=created_testcases, deleted=deleted_testcases)
        # log.save()

        return success(message='report saved',
                       data={"parent_id": getattr(report.parent, "id", 0),
                             "current_id": report.id,
                             "link": report.link})

    else:
        errors = report_form.errors_list()
        errors.extend(report_contextelement_formset._errors_list())
        return failed(message="Validation errors",
                      data=errors)
Пример #12
0
        def post(self, request):
            if request.REQUEST.has_key('new_user'):
                form = forms.NewUserForm(request.POST, prefix="user_form")
                if form.is_valid():
                    user = form.save(commit=False)
                    user.username = form.cleaned_data["email"]
                    user.set_password(form.cleaned_data["password1"])
                    user.save()
                    
                    models.OrganizationMember.objects.create(
                        user=user,
                        organization=request.organization,
                        role=models.OrganizationMember.INACTIVE
                    )

                    send_mail(
                        'Qualitio Project, User account created in %s organization'
                        % self.request.organization.name,
                        render_to_string('organizations/new_user.mail',
                                         {"organization": self.request.organization,
                                          "user": user,
                                          "password": form.cleaned_data["password1"]}),
                        'Qualitio Notifications <*****@*****.**>',
                        [user.email])
                    
                    return success(message="User created.")

            else:
                form = forms.NewMemberForm(request.POST, prefix="member_form")
                if form.is_valid():
                    email = form.cleaned_data.get('email')
                    try:
                        user = auth.User.objects.get(email=email)

                        send_mail(
                            'Qualitio Project, Invitation to %s organization'
                            % self.request.organization.name,
                            render_to_string('organizations/new_member.mail',
                                             {"organization": self.request.organization,
                                              "user": user}),
                            'Qualitio Notifications <*****@*****.**>',
                            [email])
                        
                        models.OrganizationMember.objects.create(
                            user=user,
                            organization=request.organization,
                            role=models.OrganizationMember.INACTIVE
                        )
                        return success(message="User added!", data={'created': True})
                    except auth.User.DoesNotExist:
                        return success(message="Does not exist, you need to create account!",
                                       data={'created': False,
                                             'email': email})

            return failed(message="Validation errors", data=form.errors_list())
Пример #13
0
    def run_action(self, data, queryset, form=None):
        from django.db import transaction

        try:
            with transaction.commit_on_success():
                for obj in queryset.all():
                    obj.requirement = form.cleaned_data.get('requirement')
                    obj.modified_time = datetime.datetime.now()
                    obj.save()
        except Exception, error:
            return failed(message='"%s" fail: %s' % (obj.name, error.message))
Пример #14
0
def testcaserun_setstatus(request, testcaserun_id):
    testcaserun = TestCaseRun.objects.get(pk=testcaserun_id)
    testcaserun_status_form = forms.TestCaseRunStatus(request.POST, instance=testcaserun)
    if testcaserun_status_form.is_valid():
        testcaserun = testcaserun_status_form.save()
        return success(message=testcaserun.status.name,
                       data=dict(id=testcaserun.pk,
                                 name=testcaserun.status.name,
                                 color=testcaserun.status.color))
    else:
        return failed(message=testcaserun.status.name,
                      data=testcaserun_status_form.errors_list())
Пример #15
0
        def post(self, request):
            formset = forms.OrganizationUsersForm(
                request.POST,
                instance=self.request.organization
            )

            if formset.is_valid():
                formset.save()
                return success(message='Changes saved.')

            return failed(message="%s"
                          % formset.non_form_errors().as_text())
Пример #16
0
def testcaserun_removebug(request, testcaserun_id):
    testcaserun = TestCaseRun.objects.get(pk=testcaserun_id)
    bugs_formset = forms.BugFormSet(request.POST, instance=testcaserun)

    if bugs_formset.is_valid():
        bugs_formset.save()

        return success(message="Issue(s) removed",
                   data=dict(id=testcaserun.id,
                             all=map(lambda x: x.id, testcaserun.bugs.all())))

    return failed(message="Validation error",
                  data=bugs_formset.errors_list())
Пример #17
0
def available_testcases(request, requirement_id):
    search_testcases_form = SearchTestcasesForm(request.POST)
    if search_testcases_form.is_valid():
        search = request.POST["search"]
        testcases =  TestCase.objects.filter(Q(name__contains=search) | Q(path__contains=search))
        if testcases:
            return success(message="%s testcases found" % testcases.count(),
                           data=loader.render_to_string("requirements/_available_testcases.html",
                                                        { "testcases" : testcases }))
        return success(message="no testcases found")

    return failed(message="validation errors",
                  data=search_testcases_form.errors_list())
Пример #18
0
def directory_valid(request, directory_id=0):
    if directory_id:
        testcase_directory = TestCaseDirectory.objects.get(pk=directory_id)
        testcase_directory_form = TestCaseDirectoryForm(request.POST, instance=testcase_directory)
    else:
        testcase_directory_form = TestCaseDirectoryForm(request.POST)

    if testcase_directory_form.is_valid():
        testcase_directory = testcase_directory_form.save()
        return success(message='testcase directory saved',
                       data={"parent_id": getattr(testcase_directory.parent, "id", 0),
                              "current_id": testcase_directory.id})
    else:
        return failed(message="Validation errors: %s" % testcase_directory_form.error_message(),
                      data=testcase_directory_form.errors_list())
Пример #19
0
def valid(request, requirement_id=0):
    if requirement_id:
        requirement = Requirement.objects.get(pk=requirement_id)
        requirement_form = RequirementForm(request.POST, instance=requirement)
    else:
        requirement_form = RequirementForm(request.POST)

    if requirement_form.is_valid():
        requirement = requirement_form.save()
        return success(message='Requirement saved',
                       data={ "parent_id" : getattr(requirement.parent,"id", 0),
                              "current_id" : requirement.id })

    return failed(message="Validation errors %s" % requirement_form.error_message(),
                  data=requirement_form.errors_list())
Пример #20
0
def directory_valid(request, directory_id=0):
    if directory_id:
        testcase_directory = TestCaseDirectory.objects.get(pk=str(directory_id))
        testcase_directory_form = TestCaseDirectoryForm(request.POST, instance=testcase_directory)
    else:
        testcase_directory_form = TestCaseDirectoryForm(request.POST)
        
    if testcase_directory_form.is_valid():
        testcase_directory = testcase_directory_form.save()
        return success(message='testcase directory saved', 
                       data={ "parent_id" : getattr(testcase_directory.parent,"id", 0), 
                              "current_id" : testcase_directory.id })
    else:
        return failed(message="Validation errors", 
                      data=[(k, v[0]) for k, v in testcase_directory_form.errors.items()])
Пример #21
0
def testcaserun_removebug(request, testcaserun_id):
    testcaserun = TestCaseRun.objects.get(pk=testcaserun_id)
    bugs_formset = forms.BugFormSet(request.POST, instance=testcaserun)

    if bugs_formset.is_valid():
        bugs_formset.save()

        log = history.History(request.user, testcaserun.parent)
        log.add_formset(bugs_formset, prefix=True)
        log.save()
        return success(message="Issue(s) deleted.",
                       data=dict(testcaserun=testcaserun.id,
                                 all_bugs=list(testcaserun.bugs.values_list('alias', flat=True))))

    return failed(message="Validation error",
                  data=bugs_formset.errors_list())
Пример #22
0
def valid(request, requirement_id=0):
    if requirement_id:
        requirement = Requirement.objects.get(pk=requirement_id)
        requirement_form = RequirementForm(request.POST, instance=requirement)
    else:
        requirement_form = RequirementForm(request.POST)

    if requirement_form.is_valid():
        requirement = requirement_form.save()
        return success(message='Requirment saved', 
                       data={ "parent_id" : getattr(requirement.parent,"id", 0), 
                              "current_id" : requirement.id })
    
    # TODO: move this functionality to helpers
    return failed(message="Validation errors %s" % " ".join([e for e in requirement_form.non_field_errors()]),
                  data=[(k, v[0]) for k, v in requirement_form.errors.items()])
Пример #23
0
def testcaserun_setstatus(request, testcaserun_id):
    testcaserun = TestCaseRun.objects.get(pk=testcaserun_id)
    testcaserun_status_form = forms.TestCaseRunStatus(request.POST, instance=testcaserun)
    if testcaserun_status_form.is_valid():
        testcaserun = testcaserun_status_form.save()

        log = history.History(request.user, testcaserun.parent)
        log.add_form(testcaserun_status_form, capture=["status"], prefix=True)
        log.save()
        return success(message=testcaserun.status.name,
                       data=dict(id=testcaserun.pk,
                                 name=testcaserun.status.name,
                                 color=testcaserun.status.color))
    else:
        return failed(message=testcaserun.status.name,
                      data=testcaserun_status_form.errors_list())
Пример #24
0
def testrun_notes_valid(request, testrun_id, **kwargs):
    testrun = TestRun.objects.get(pk=str(testrun_id))
    testrun_form = forms.TestRunNotesForm(request.POST, instance=testrun)

    if testrun_form.is_valid():
        testrun = testrun_form.save()

        log = history.History(request.user, testrun)
        log.add_form(testrun_form, is_new=(testrun_id == 0))
        log.save()

        return success(message='Test run notes saved',
                       data={"parent_id": getattr(testrun.parent, "id", 0),
                             "current_id": testrun.id})
    else:
        return failed(message="Validation errors: %s" % testrun_form.error_message(),
                      data=testrun_form.errors_list())
Пример #25
0
def testcase_valid(request, testcase_id):
    testcase = TestCase.objects.get(pk=str(testcase_id))
    testcase_form = TestCaseForm(request.POST, instance=testcase)
    testcasesteps_form = TestCaseStepFormSet(request.POST, instance=testcase)
    if testcase_form.is_valid() and testcasesteps_form.is_valid(): 
        testcase_form.save()
        testcasesteps_form.save()
        return success(message='TestCase saved', 
                       data={ "parent_id" : getattr(testcase.parent,"id", 0), 
                              "current_id" : testcase.id })
    else:
        formset_errors = []
        for i, error in filter(lambda x: x[1], list(enumerate(testcasesteps_form.errors))):
            for v, k in error.items():
                formset_errors.append(map(lambda x:(("testcasestep_set-%s-%s") % (i,v) ,x), k)[0])
        # print formset_errors
        return failed(message="Validation errors", 
                      data=[(k, v[0]) for k, v in testcase_form.errors.items()] + formset_errors)
Пример #26
0
def testcase_valid(request, testcase_id=0):
    if testcase_id:
        testcase = TestCase.objects.get(pk=str(testcase_id))
        testcase_form = TestCaseForm(request.POST, instance=testcase)
        testcasesteps_form = TestCaseStepFormSet(request.POST, instance=testcase)
    else:
        testcase_form = TestCaseForm(request.POST)
        testcasesteps_form = TestCaseStepFormSet(request.POST)

    if testcase_form.is_valid() and testcasesteps_form.is_valid():
        testcase = testcase_form.save()
        testcasesteps_form.instance = testcase
        testcasesteps_form.save()
        return success(message='TestCase saved',
                       data={"parent_id": getattr(testcase.parent, "id", 0),
                              "current_id": testcase.id})
    else:
        return failed(message="Validation errors: %s" % testcase_form.error_message(),
                      data=testcase_form.errors_list() + testcasesteps_form.errors_list())
Пример #27
0
def directory_valid(request, directory_id=0, **kwargs):
    # TODO: should we think about permissions for valid views?
    if directory_id:
        reportdirectory = ReportDirectory.objects.get(pk=directory_id)
        reportdirectory_form = ReportDirectoryForm(request.POST,
                                                   instance=reportdirectory)
    else:
        reportdirectory_form = ReportDirectoryForm(request.POST)


    if reportdirectory_form.is_valid():
        reportdirectory = reportdirectory_form.save()

        return success(message='report directory saved',
                       data={"parent_id": getattr(reportdirectory.parent, "id", 0),
                             "current_id": reportdirectory.id})
    else:
        return failed(message="Validation errors: %s" % reportdirectory_form.error_message(),
                      data=reportdirectory_form.errors_list())
Пример #28
0
        def post(self, request, *args, **kwargs):
            project = models.Project.objects.get(pk=kwargs['pk'])
            form = forms.ProjectForm(request.POST,
                                     instance=project,
                                     prefix='general',
                                     organization=request.organization)

            store_testcase = forms.ProjectTestCaseStatusFormSet(request.POST,
                                                                instance=project,
                                                                prefix='store_testcase_status')

            execute_testrun = forms.ProjectTestRunStatusFormSet(request.POST,
                                                                instance=project,
                                                                prefix='execute_testrun_status')

            execute_testcaserun = forms.ProjectTestCaseRunStatusFormSet(request.POST,
                                                                        instance=project,
                                                                        prefix='execute_testcaserun_status')

            glossary_language = forms.ProjectGlossaryLanguageFormSet(request.POST,
                                                                     instance=project,
                                                                     prefix='glossary_language')


            if form.is_valid() and\
                    store_testcase.is_valid() and\
                    execute_testrun.is_valid() and\
                    execute_testcaserun.is_valid() and\
                    glossary_language.is_valid():

                form.save()
                store_testcase.save()
                execute_testrun.save()
                execute_testcaserun.save()
                glossary_language.save()
                return success(message='Changes saved.')

            return failed(message="Validation errors: %s" % form.error_message(),
                          data=form.errors_list() +\
                              store_testcase._errors_list() +\
                              execute_testrun._errors_list() +\
                              execute_testcaserun._errors_list() +\
                              glossary_language._errors_list())
Пример #29
0
def valid(request, requirement_id=0, **kwargs):
    if requirement_id:
        requirement = Requirement.objects.get(pk=requirement_id)
        requirement_form = RequirementForm(request.POST, instance=requirement)
    else:
        requirement_form = RequirementForm(request.POST)

    if requirement_form.is_valid():
        requirement = requirement_form.save()

        log = history.History(request.user, requirement)
        log.add_form(requirement_form, is_new=(requirement_id == 0))
        log.save()
        return success(message='Requirement saved',
                       data={"parent_id": getattr(requirement.parent,"id", 0),
                             "current_id": requirement.id })

    return failed(message="Validation errors: %s" % requirement_form.error_message(),
                  data=requirement_form.errors_list())
Пример #30
0
def directory_valid(request, directory_id=0):
    # TODO: should we think about permissions for valid views?
    if directory_id:
        testrun_directory = TestRunDirectory.objects.get(pk=str(directory_id))
        testrun_directory_form = forms.TestRunDirectoryForm(request.POST,
                                                            instance=testrun_directory)
    else:
        testrun_directory_form = forms.TestRunDirectoryForm(request.POST)

    if testrun_directory_form.is_valid():
        testrun_directory = testrun_directory_form.save()

        log = history.History(request.user, testrun_directory)
        log.add_form(testrun_directory_form)
        log.save()

        return success(message='testrun directory saved',
                       data={"parent_id": getattr(testrun_directory.parent, "id", 0),
                             "current_id": testrun_directory.id})
    else:
        return failed(message="Validation errors: %s" % testrun_directory_form.error_message(),
                      data=testrun_directory_form.errors_list())