Ejemplo n.º 1
0
    def test_recommendation_name_too_many_chars(self):
        """test for max length"""

        # get object
        form = RecommendationForm(data={'recommendation_name': 'r' * 31})
        # compare
        self.assertFalse(form.is_valid())
Ejemplo n.º 2
0
    def test_recommendation_form_empty(self):
        """ test minimum form requirements / INVALID """

        # get object
        form = RecommendationForm(data={})
        # compare
        self.assertFalse(form.is_valid())
Ejemplo n.º 3
0
    def test_recommendation_name_form_filled(self):
        """ test minimum form requirements / VALID """

        # get object
        form = RecommendationForm(data = {'recommendation_name': 'recommendation_1'})
        # compare
        self.assertTrue(form.is_valid())
Ejemplo n.º 4
0
    def test_recommendation_name_proper_chars(self):
        """test for max length"""

        # get object
        form = RecommendationForm(data={'recommendation_name': 'r' * 30})
        # compare
        self.assertTrue(form.is_valid())
Ejemplo n.º 5
0
    def test_recommendation_note_form_filled(self):
        """ test additional form content """

        # get object
        form = RecommendationForm(data = {
            'recommendation_name': 'recommendation_1',
            'recommendation_note': 'lorem ipsum',
        })
        # compare
        self.assertTrue(form.is_valid())
Ejemplo n.º 6
0
    def test_recommendation_name_form_label(self):
        """ test form label """

        # get object
        form = RecommendationForm()
        # compare
        self.assertEqual(form.fields['recommendation_name'].label, 'Recommendation name (*)')
Ejemplo n.º 7
0
def recommendations_add(request):
    if request.method == 'POST':
        form = RecommendationForm(request.POST)
        if form.is_valid():
            recommendation = form.save(commit=False)
            recommendation.save()
            recommendation.logger(str(request.user),
                                  " RECOMMENDATION_ADD_EXECUTED")
            messages.success(request, 'Recommendation added')
            return redirect('/recommendations')
    else:
        form = RecommendationForm()
        debug_logger(str(request.user), " RECOMMENDATION_ADD_ENTERED")
    return render(request,
                  'dfirtrack_main/recommendation/recommendations_add.html',
                  {'form': form})
Ejemplo n.º 8
0
def recommendations_edit(request, pk):
    recommendation = get_object_or_404(Recommendation, pk=pk)
    if request.method == 'POST':
        form = RecommendationForm(request.POST, instance=recommendation)
        if form.is_valid():
            recommendation = form.save(commit=False)
            recommendation.save()
            recommendation.logger(str(request.user),
                                  " RECOMMENDATION_EDIT_EXECUTED")
            messages.success(request, 'Recommendation edited')
            return redirect('/recommendations')
    else:
        form = RecommendationForm(instance=recommendation)
        recommendation.logger(str(request.user),
                              " RECOMMENDATION_EDIT_ENTERED")
    return render(request,
                  'dfirtrack_main/recommendation/recommendations_edit.html',
                  {'form': form})
Ejemplo n.º 9
0
def recommendations_add_popup(request):
    if request.method == 'POST':
        form = RecommendationForm(request.POST)
        if form.is_valid():
            recommendation = form.save(commit=False)
            recommendation.save()
            recommendation.logger(str(request.user),
                                  " RECOMMENDATION_ADD_POPUP_EXECUTED")
            messages.success(request, 'Recommendation added')
            return HttpResponse(
                '<script type="text/javascript">window.close();</script>')
    else:
        form = RecommendationForm()
        debug_logger(str(request.user), " RECOMMENDATION_ADD_POPUP_ENTERED")
    return render(
        request,
        'dfirtrack_main/recommendation/recommendations_add_popup.html',
        {'form': form})