Пример #1
0
    def test_company_form_empty(self):
        """ test minimum form requirements / INVALID """

        # get object
        form = CompanyForm(data={})
        # compare
        self.assertFalse(form.is_valid())
Пример #2
0
    def test_company_name_form_filled(self):
        """ test minimum form requirements / VALID """

        # get object
        form = CompanyForm(data={'company_name': 'company_1'})
        # compare
        self.assertTrue(form.is_valid())
Пример #3
0
    def test_company_name_proper_chars(self):
        """test for max length"""

        # get object
        form = CompanyForm(data={'company_name': 'c' * 50})
        # compare
        self.assertTrue(form.is_valid())
Пример #4
0
    def test_company_name_too_many_chars(self):
        """test for max length"""

        # get object
        form = CompanyForm(data={'company_name': 'c' * 51})
        # compare
        self.assertFalse(form.is_valid())
Пример #5
0
    def test_company_division_form_filled(self):
        """ test additional form content """

        # get foreign key object id
        division_id = Division.objects.get(division_name='division_1').division_id
        # get object
        form = CompanyForm(data = {
            'company_name': 'company_1',
            'division': division_id,
        })
        # compare
        self.assertTrue(form.is_valid())
Пример #6
0
    def test_company_note_form_label(self):
        """ test form label """

        # get object
        form = CompanyForm()
        # compare
        self.assertEquals(form.fields['company_note'].label, 'Company note')
Пример #7
0
    def test_company_division_form_label(self):
        """ test form label """

        # get object
        form = CompanyForm()
        # compare
        self.assertEquals(form.fields['division'].label, 'Division')
Пример #8
0
    def test_company_division_form_label(self):
        """ test form label """

        # get object
        form = CompanyForm()
        # compare
        self.assertEqual(form.fields['division'].label, 'Division')
        self.assertEqual(form.fields['division'].empty_label, 'Select division (optional)')
Пример #9
0
def companys_add(request):
    if request.method == 'POST':
        form = CompanyForm(request.POST)
        if form.is_valid():
            company = form.save(commit=False)
            company.save()
            company.logger(str(request.user), " COMPANY_ADD_EXECUTED")
            messages.success(request, 'Company added')
            return redirect('/companys')
    else:
        form = CompanyForm()
        debug_logger(str(request.user), " COMPANY_ADD_ENTERED")
    return render(request, 'dfirtrack_main/company/companys_add.html',
                  {'form': form})
Пример #10
0
def companys_edit(request, pk):
    company = get_object_or_404(Company, pk=pk)
    if request.method == 'POST':
        form = CompanyForm(request.POST, instance=company)
        if form.is_valid():
            company = form.save(commit=False)
            company.save()
            company.logger(str(request.user), " COMPANY_EDIT_EXECUTED")
            messages.success(request, 'Company edited')
            return redirect('/companys')
    else:
        form = CompanyForm(instance=company)
        company.logger(str(request.user), " COMPANY_EDIT_ENTERED")
    return render(request, 'dfirtrack_main/company/companys_edit.html',
                  {'form': form})
Пример #11
0
def companys_add_popup(request):
    if request.method == 'POST':
        form = CompanyForm(request.POST)
        if form.is_valid():
            company = form.save(commit=False)
            company.save()
            company.logger(str(request.user), " COMPANY_ADD_POPUP_EXECUTED")
            messages.success(request, 'Company added')
            return HttpResponse(
                '<script type="text/javascript">window.close();</script>')
    else:
        form = CompanyForm()
        debug_logger(str(request.user), " COMPANY_ADD_POPUP_ENTERED")
    return render(request, 'dfirtrack_main/company/companys_add_popup.html',
                  {'form': form})