def setUpTestData(cls): cls.ClientNote = ClientNoteFactory._meta.model cls.user = UserFactory(password=PASSWORD) cls.note = ClientNoteFactory(operator=cls.user) cls.uri = reverse("rolodex:client_note_edit", kwargs={"pk": cls.note.pk}) cls.other_user_note = ClientNoteFactory() cls.other_user_uri = reverse("rolodex:client_note_edit", kwargs={"pk": cls.other_user_note.pk})
def test_view_uri_exists_at_desired_location(self): self.ClientNote.objects.all().delete() note = ClientNoteFactory(operator=self.user) uri = reverse("rolodex:ajax_delete_client_note", kwargs={"pk": note.pk}) self.assertEqual(len(self.ClientNote.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.ClientNote.objects.all()), 0)
def test_crud_finding(self): # Create note = ClientNoteFactory(note="Client note") # Read self.assertEqual(note.note, "Client note") self.assertEqual(note.pk, note.id) self.assertQuerysetEqual( self.ClientNote.objects.all(), [f"<ClientNote: {note.client}: {note.timestamp} - Client note>"], ) # Update note.note = "Updated note" note.save() self.assertQuerysetEqual( self.ClientNote.objects.all(), [f"<ClientNote: {note.client}: {note.timestamp} - Updated note>"], ) # Delete note.delete() assert not self.ClientNote.objects.all().exists()
def test_view_requires_login(self): note = ClientNoteFactory() uri = reverse("rolodex:ajax_delete_client_note", kwargs={"pk": note.pk}) response = self.client.post(uri) self.assertEqual(response.status_code, 302)
def setUpTestData(cls): cls.note = ClientNoteFactory() cls.note_dict = cls.note.__dict__