From 9ee0aed71778236917e5ef0738f991836a22445c Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Tue, 8 Sep 2020 17:19:05 +0530 Subject: Fix Tests --- yaksh/test_views.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 9cb454e..6b74096 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -22,6 +22,7 @@ from django.conf import settings from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files import File from django.contrib.messages import get_messages +from django.contrib.contenttypes.models import ContentType from celery.contrib.testing.worker import start_worker from django.test import SimpleTestCase @@ -6851,10 +6852,11 @@ class TestPost(TestCase): url = reverse('yaksh:course_forum', kwargs={ 'course_id': self.course.id }) + course_ct = ContentType.objects.get_for_model(self.course) post = Post.objects.create( title='post 1', description='post 1 description', - course=self.course, + target_ct=course_ct, target_id=self.course.id, creator=self.student ) response = self.client.get(url) @@ -6879,9 +6881,11 @@ class TestPost(TestCase): } response = self.client.post(url, data) # This shouldn't be 302. Check where does it redirects. + course_ct = ContentType.objects.get_for_model(self.course) result = Post.objects.filter(title='Post 1', creator=self.student, - course=self.course) + target_ct=course_ct, + target_id=self.course.id) self.assertTrue(result.exists()) def test_new_post_invalid_post_data(self): @@ -6914,24 +6918,12 @@ class TestPost(TestCase): self.assertEquals(response.status_code, 200) self.assertFalse(Post.objects.exists()) - def test_contains_form(self): - self.client.login( - username=self.student.username, - password=self.student_plaintext_pass - ) - self.course.students.add(self.student) - url = reverse('yaksh:course_forum', kwargs={ - 'course_id': self.course.id - }) - response = self.client.get(url) - form = response.context.get('form') - self.assertIsInstance(form, PostForm) - def test_open_created_post_denies_anonymous_user(self): + course_ct = ContentType.objects.get_for_model(self.course) post = Post.objects.create( title='post 1', description='post 1 description', - course=self.course, + target_ct=course_ct, target_id=self.course.id, creator=self.student ) url = reverse('yaksh:post_comments', kwargs={ @@ -6970,23 +6962,22 @@ class TestPost(TestCase): password=self.user_plaintext_pass ) self.course.students.add(self.user) + course_ct = ContentType.objects.get_for_model(self.course) post = Post.objects.create( title='post 1', description='post 1 description', - course=self.course, - creator=self.user + target_ct=course_ct, target_id=self.course.id, + creator=self.student ) url = reverse('yaksh:hide_post', kwargs={ 'course_id': self.course.id, 'uuid': post.uid }) response = self.client.get(url, follow=True) - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 404) def tearDown(self): self.client.logout() - self.user.delete() - self.course.delete() self.mod_group.delete() @@ -7037,10 +7028,11 @@ class TestPostComment(TestCase): enrollment="Enroll Request", creator=self.user ) + course_ct = ContentType.objects.get_for_model(self.course) self.post = Post.objects.create( title='post 1', description='post 1 description', - course=self.course, + target_ct=course_ct, target_id=self.course.id, creator=self.student ) @@ -7204,12 +7196,10 @@ class TestPostComment(TestCase): 'uuid': comment.uid }) response = self.client.get(url) - self.assertEquals(response.status_code, 302) + self.assertEquals(response.status_code, 404) def tearDown(self): self.client.logout() - self.user.delete() - self.course.delete() self.mod_group.delete() -- cgit