示例#1
0
    def test_note_form_empty(self):
        """ test minimum form requirements / INVALID """

        # get object
        form = NoteForm(data={})
        # compare
        self.assertFalse(form.is_valid())
示例#2
0
    def test_note_title_form_filled(self):
        """ test minimum form requirements / INVALID """

        # get object
        form = NoteForm(data={
            'note_title': 'note_1',
        })
        # compare
        self.assertFalse(form.is_valid())
示例#3
0
    def test_note_version_error(self):
        """ test custom field validation """

        # login testuser
        self.client.login(username='******',
                          password='******')
        # get user
        test_user = User.objects.get(username='******')
        # get object
        notestatus_1 = Notestatus.objects.get(notestatus_name='notestatus_1')
        # create object
        note_version_error = Note.objects.create(
            note_title='note_version_error',
            note_content='lorem ipsum',
            notestatus=notestatus_1,
            note_created_by_user_id=test_user,
            note_modified_by_user_id=test_user,
        )

        # get current note version
        note_version = Note.objects.get(
            note_title='note_version_error').note_version

        # create post data with current version
        data_dict = {
            'note_id': note_version_error.note_id,
            'note_title': 'note_version_error',
            'note_content': 'lorem ipsum updated via post',
            'note_version': note_version,
            'notestatus': notestatus_1.notestatus_id,
        }
        # a competing user post request with the same version precedes the form
        self.client.post('/note/' + str(note_version_error.note_id) + '/edit/',
                         data_dict)

        note_version_error.refresh_from_db()

        # create form data with meanwhile outdated version (id is required because of NoteForm.fields)
        form = NoteForm(data={
            'note_id': note_version_error.note_id,
            'note_title': 'note_version_error',
            'note_content': 'lorem impsum updated via form',
            'note_version': note_version,
            'notestatus': notestatus_1.notestatus_id,
        },
                        instance=note_version_error)
        # compare
        self.assertFalse(form.is_valid())
        self.assertInHTML("There is a newer version of this note.",
                          str(form.errors))
示例#4
0
    def test_note_title_too_many_chars(self):
        """ test for max length """

        # get object
        notestatus_1 = Notestatus.objects.get(notestatus_name='notestatus_1')
        # get object
        form = NoteForm(
            data={
                'note_title': 'n' * 251,
                'note_content': 'lorem impsum',
                'notestatus': notestatus_1.notestatus_id,
            })
        # compare
        self.assertFalse(form.is_valid())
示例#5
0
    def test_note_notestatus_form_filled(self):
        """ test minimum form requirements / VALID """

        # get object
        notestatus_1 = Notestatus.objects.get(notestatus_name='notestatus_1')
        # get object
        form = NoteForm(
            data={
                'note_title': 'note_1',
                'note_content': 'lorem impsum',
                'notestatus': notestatus_1.notestatus_id,
            })
        # compare
        self.assertTrue(form.is_valid())
示例#6
0
    def test_note_tag_form_label(self):
        """ test form label """

        # get object
        form = NoteForm()
        # compare
        self.assertEqual(form.fields['tag'].label, 'Tags')
示例#7
0
    def test_notestatus_form_label(self):
        """ test form label """

        # get object
        form = NoteForm()
        # compare
        self.assertEqual(form.fields['notestatus'].label, 'Notestatus (*)')
示例#8
0
    def test_note_case_form_label(self):
        """ test form label """

        # get object
        form = NoteForm()
        # compare
        self.assertEqual(form.fields['case'].label, 'Corresponding case')
示例#9
0
    def test_note_case_form_filled(self):
        """ test additional form content """

        # get objects
        case_1 = Case.objects.get(case_name='case_1')
        notestatus_1 = Notestatus.objects.get(notestatus_name='notestatus_1')
        # get object
        form = NoteForm(
            data={
                'note_title': 'note_1',
                'note_content': 'lorem impsum',
                'notestatus': notestatus_1.notestatus_id,
                'case': case_1.case_id,
            })
        # compare
        self.assertTrue(form.is_valid())
示例#10
0
    def test_note_tag_form_filled(self):
        """ test additional form content """

        # get objects
        tag_1 = Tag.objects.get(tag_name='tag_1')
        notestatus_1 = Notestatus.objects.get(notestatus_name='notestatus_1')
        # get object
        form = NoteForm(
            data={
                'note_title': 'note_1',
                'note_content': 'lorem impsum',
                'notestatus': notestatus_1.notestatus_id,
                'tag': [
                    tag_1.tag_id,
                ],
            })
        # compare
        self.assertTrue(form.is_valid())