예제 #1
0
    def test_contact_name_form_filled(self):
        """ test minimum form requirements / INVALID """

        # get object
        form = ContactForm(data = {'contact_name': 'contact_1'})
        # compare
        self.assertFalse(form.is_valid())
예제 #2
0
    def test_contact_form_empty(self):
        """ test minimum form requirements / INVALID """

        # get object
        form = ContactForm(data = {})
        # compare
        self.assertFalse(form.is_valid())
예제 #3
0
    def test_contact_name_proper_chars(self):
        """ test for max length """

        # get object
        form = ContactForm(data = {
            'contact_name': 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
            'contact_email': '*****@*****.**'
        })
        # compare
        self.assertTrue(form.is_valid())
예제 #4
0
    def test_contact_email_form_filled(self):
        """ test minimum form requirements / VALID """

        # get object
        form = ContactForm(data = {
            'contact_name': 'contact_1',
            'contact_email': '*****@*****.**',
        })
        # compare
        self.assertTrue(form.is_valid())
예제 #5
0
    def test_contact_email_too_many_chars(self):
        """ test for max length """

        # get object
        form = ContactForm(data = {
            'contact_name': 'contact_1',
            'contact_email': 'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'
        })
        # compare
        self.assertFalse(form.is_valid())
예제 #6
0
    def test_contact_note_form_filled(self):
        """ test additional form content """

        # get object
        form = ContactForm(data = {
            'contact_name': 'contact_1',
            'contact_email': '*****@*****.**',
            'contact_email': 'lorem ipsum',
        })
        # compare
        self.assertTrue(form.is_valid())
예제 #7
0
    def test_contact_name_too_many_chars(self):
        """test for max length"""

        # get object
        form = ContactForm(
            data={
                'contact_name': 'c' * 101,
                'contact_email': '*****@*****.**',
            }
        )
        # compare
        self.assertFalse(form.is_valid())
예제 #8
0
    def test_contact_name_form_label(self):
        """ test form label """

        # get object
        form = ContactForm()
        # compare
        self.assertEqual(form.fields['contact_name'].label, 'Contact name (*)')
예제 #9
0
    def test_contact_email_form_label(self):
        """ test form label """

        # get object
        form = ContactForm()
        # compare
        self.assertEquals(form.fields['contact_email'].label, 'Contact email (*)')
예제 #10
0
    def test_contact_phone_form_label(self):
        """ test form label """

        # get object
        form = ContactForm()
        # compare
        self.assertEquals(form.fields['contact_phone'].label, 'Contact phone')
예제 #11
0
def contacts_add_popup(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            contact = form.save(commit=False)
            contact.save()
            contact.logger(str(request.user), " CONTACT_ADD_POPUP_EXECUTED")
            messages.success(request, 'Contact added')
            return HttpResponse('<script type="text/javascript">window.close();</script>')
    else:
        form = ContactForm()
        debug_logger(str(request.user), " CONTACT_ADD_POPUP_ENTERED")
    return render(request, 'dfirtrack_main/contact/contacts_add_popup.html', {'form': form})
예제 #12
0
def contacts_add(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            contact = form.save(commit=False)
            contact.save()
            contact.logger(str(request.user), " CONTACT_ADD_EXECUTED")
            messages.success(request, 'Contact added')
            return redirect('/contacts')
    else:
        form = ContactForm()
        debug_logger(str(request.user), " CONTACT_ADD_ENTERED")
    return render(request, 'dfirtrack_main/contact/contacts_add.html', {'form': form})
예제 #13
0
def contacts_edit(request, pk):
    contact = get_object_or_404(Contact, pk=pk)
    if request.method == 'POST':
        form = ContactForm(request.POST, instance=contact)
        if form.is_valid():
            contact = form.save(commit=False)
            contact.save()
            contact.logger(str(request.user), " CONTACT_EDIT_EXECUTED")
            messages.success(request, 'Contact edited')
            return redirect('/contacts')
    else:
        form = ContactForm(instance=contact)
        contact.logger(str(request.user), " CONTACT_EDIT_ENTERED")
    return render(request, 'dfirtrack_main/contact/contacts_edit.html', {'form': form})