def test_workflow_default_artifact_name_form_filled_incorrect(self):
        """formset test - INVALID"""

        # get object
        artifacttype_id = Artifacttype.objects.get(
            artifacttype_name='artifacttype_1').artifacttype_id
        artfactstatus_id = Artifactstatus.objects.get(
            artifactstatus_name='10_needs_analysis').artifactstatus_id
        artfactpriority_id = Artifactpriority.objects.get(
            artifactpriority_name='10_low').artifactpriority_id

        # create form
        form = WorkflowDefaultArtifactAttributesFormSet(
            data={
                'form-TOTAL_FORMS': '2',
                'form-INITIAL_FORMS': '0',
                'form-0-artifacttype': artifacttype_id,
                'form-0-artifact_default_name': 'default_name_1',
                'form-0-artifact_default_status': artfactstatus_id,
                'form-0-artifact_default_priority': artfactpriority_id,
                'form-1-artifacttype': -1,
                'form-1-artifact_default_name': 'default_name_2',
                'form-1-artifact_default_status': artfactstatus_id,
                'form-1-artifact_default_priority': artfactpriority_id,
            })
        # compare
        self.assertFalse(form.is_valid())
    def test_workflow_default_artifact_name_form_empty(self):
        """formset test - INVALID"""

        # get object
        form = WorkflowDefaultArtifactAttributesFormSet(data={})
        # compare
        self.assertFalse(form.is_valid())
Exemple #3
0
    def post(self, request, *args, **kwargs):
        # parse forms
        form = self.form_class(request.POST)
        artifacttypes_formset = WorkflowDefaultArtifactAttributesFormSet(
            request.POST, prefix='artifact'
        )
        tasknames_formset = WorkflowDefaultTasknameAttributesFormSet(
            request.POST, prefix='taskname'
        )

        if (
            not tasknames_formset.has_changed()
            and not artifacttypes_formset.has_changed()
        ):
            form.errors[
                'General'
            ] = ': You need to configure a taskname or artifacttype.'

        # check default form and custom artifacttypes_formset
        if (
            form.is_valid()
            and artifacttypes_formset.is_valid()
            and tasknames_formset.is_valid()
        ):
            workflow = form.save(commit=False)
            workflow.workflow_created_by_user_id = request.user
            workflow.workflow_modified_by_user_id = request.user
            workflow.save()
            form.save_m2m()

            # create WorkflowDefaultArtifactAttributes mapping for every sub-form
            for artifacttypes_form in artifacttypes_formset:
                if artifacttypes_form.is_valid() and artifacttypes_form.has_changed():
                    workflow_artifacttype = artifacttypes_form.save(commit=False)
                    workflow_artifacttype.workflow = workflow
                    workflow_artifacttype.save()

            # create WorkflowDefaultTasknameAttributes for every sub-form
            for tasknames_form in tasknames_formset:
                if tasknames_form.is_valid() and tasknames_form.has_changed():
                    workflow_taskname = tasknames_form.save(commit=False)
                    workflow_taskname.workflow = workflow
                    workflow_taskname.save()

            workflow.logger(str(request.user), " WORKFLOW_ADD_EXECUTED")
            messages.success(request, 'Workflow added')
            return redirect(reverse('workflow_detail', args=(workflow.workflow_id,)))
        else:
            return render(
                request,
                self.template_name,
                {
                    'form': form,
                    'title': 'Add',
                    'artifacttypes_formset': artifacttypes_formset,
                    'tasknames_formset': tasknames_formset,
                },
            )
Exemple #4
0
    def post(self, request, *args, **kwargs):
        workflow = self.get_object()

        # parse forms
        form = self.form_class(request.POST, instance=workflow)
        # filter artifacttypes based on workflow
        artifacttypes_formset = WorkflowDefaultArtifactAttributesFormSet(
            request.POST, prefix='artifact'
        )
        tasknames_formset = WorkflowDefaultTasknameAttributesFormSet(
            request.POST, prefix='taskname'
        )

        # check default form and custom artifacttypes_formset
        if (
            form.is_valid()
            and artifacttypes_formset.is_valid()
            and tasknames_formset.is_valid()
        ):
            workflow = form.save(commit=False)
            workflow.workflow_modified_by_user_id = request.user
            workflow.save()
            form.save_m2m()

            # create WorkflowDefaultArtifactname mapping for every sub-form
            for artifacttypes_form in artifacttypes_formset:
                if artifacttypes_form.is_valid() and artifacttypes_form.has_changed():
                    workflow_artifacttype = artifacttypes_form.save(commit=False)
                    workflow_artifacttype.workflow = workflow
                    workflow_artifacttype.save()

            # create WorkflowDefaultTasknameAttributes for every sub-form
            for tasknames_form in tasknames_formset:
                if tasknames_form.is_valid() and tasknames_form.has_changed():
                    workflow_taskname = tasknames_form.save(commit=False)
                    workflow_taskname.workflow = workflow
                    workflow_taskname.save()

            workflow.logger(str(request.user), " WORKFLOW_EDIT_EXECUTED")
            messages.success(request, 'Workflow edited')
            return redirect(reverse('workflow_detail', args=(workflow.workflow_id,)))
        else:
            return render(
                request,
                self.template_name,
                {
                    'form': form,
                    'title': 'Edit',
                    'artifacttypes_formset': artifacttypes_formset,
                    'tasknames_formset': tasknames_formset,
                },
            )
Exemple #5
0
    def get(self, request, *args, **kwargs):
        workflow = self.get_object()
        form = self.form_class(instance=workflow)

        artifacttypes_formset = WorkflowDefaultArtifactAttributesFormSet(
            queryset=WorkflowDefaultArtifactAttributes.objects.filter(
                workflow=workflow
            ),
            prefix='artifact',
        )
        tasknames_formset = WorkflowDefaultTasknameAttributesFormSet(
            queryset=WorkflowDefaultTasknameAttributes.objects.filter(
                workflow=workflow
            ),
            prefix='taskname',
        )

        workflow.logger(str(request.user), " TAG_EDIT_ENTERED")
        return render(
            request,
            self.template_name,
            {
                'form': form,
                'title': 'Edit',
                'artifacttypes_formset': artifacttypes_formset,
                'tasknames_formset': tasknames_formset,
            },
        )
Exemple #6
0
    def get(self, request, *args, **kwargs):
        form = self.form_class()

        # create custom WorkflowDefaultArtifactAttributesFormSet to add multiple artifacttypes to workflow
        artifacttypes_formset = WorkflowDefaultArtifactAttributesFormSet(
            queryset=WorkflowDefaultArtifactAttributes.objects.none(),
            prefix='artifact')

        tasknames_formset = WorkflowDefaultTasknameAttributesFormSet(
            queryset=WorkflowDefaultTasknameAttributes.objects.none(),
            prefix='taskname',
        )

        debug_logger(str(request.user), " WORKFLOW_ADD_ENTERED")
        return render(
            request, self.template_name, {
                'form': form,
                'title': 'Add',
                'artifacttypes_formset': artifacttypes_formset,
                'tasknames_formset': tasknames_formset
            })