コード例 #1
0
 def setUpTestData(cls):
     cls.ProjectNote = ProjectNoteFactory._meta.model
     cls.user = UserFactory(password=PASSWORD)
     cls.note = ProjectNoteFactory(operator=cls.user)
     cls.uri = reverse("rolodex:project_note_edit", kwargs={"pk": cls.note.pk})
     cls.other_user_note = ProjectNoteFactory()
     cls.other_user_uri = reverse("rolodex:project_note_edit", kwargs={"pk": cls.other_user_note.pk})
コード例 #2
0
    def test_crud_finding(self):
        # Create
        note = ProjectNoteFactory(note="Project note")

        # Read
        self.assertEqual(note.note, "Project note")
        self.assertEqual(note.pk, note.id)
        self.assertQuerysetEqual(
            self.ProjectNote.objects.all(),
            [
                f"<ProjectNote: {note.project}: {note.timestamp} - Project note>"
            ],
        )

        # Update
        note.note = "Updated note"
        note.save()
        self.assertQuerysetEqual(
            self.ProjectNote.objects.all(),
            [
                f"<ProjectNote: {note.project}: {note.timestamp} - Updated note>"
            ],
        )

        # Delete
        note.delete()
        assert not self.ProjectNote.objects.all().exists()
コード例 #3
0
    def test_view_uri_exists_at_desired_location(self):
        self.ProjectNote.objects.all().delete()
        note = ProjectNoteFactory(operator=self.user)
        uri = reverse("rolodex:ajax_delete_project_note", kwargs={"pk": note.pk})

        self.assertEqual(len(self.ProjectNote.objects.all()), 1)

        response = self.client_auth.post(uri)
        self.assertEqual(response.status_code, 200)

        data = {"result": "success", "message": "Note successfully deleted!"}
        self.assertJSONEqual(force_str(response.content), data)

        self.assertEqual(len(self.ProjectNote.objects.all()), 0)
コード例 #4
0
    def test_view_requires_login(self):
        note = ProjectNoteFactory()
        uri = reverse("rolodex:ajax_delete_project_note", kwargs={"pk": note.pk})

        response = self.client.post(uri)
        self.assertEqual(response.status_code, 302)
コード例 #5
0
ファイル: test_forms.py プロジェクト: fancysauced/Ghostwriter
 def setUpTestData(cls):
     cls.note = ProjectNoteFactory()
     cls.note_dict = cls.note.__dict__