Fakultas Ilmu Komputer UI

Commit 1ad44617 authored by arif teguh wangi's avatar arif teguh wangi
Browse files

[#48] Material: User Review (Create)( fix code smell)

parent 93893654
......@@ -334,18 +334,18 @@ class DetailMateriTest(TestCase):
def test_category_models_can_create_new_object(self):
test = Category.objects.create(
id="1", name="medis", description="kategori medis")
countData = Category.objects.all().count()
self.assertEqual(1, countData)
self.assertNotEqual(0, countData)
count = Category.objects.all().count()
self.assertEqual(1, count)
self.assertNotEqual(0, count)
self.assertEqual(test.__str__(), "medis")
self.assertNotEqual(test.__str__(), "saul")
def test_comment_models_can_create_new_object(self):
test = Comment.objects.create(
username="saul", profile="121212", comment="232323")
countData = Comment.objects.all().count()
self.assertEqual(1, countData)
self.assertNotEqual(0, countData)
count = Comment.objects.all().count()
self.assertEqual(1, count)
self.assertNotEqual(0, count)
self.assertEqual(test.__str__(), "saul")
self.assertNotEqual(test.__str__(), "userlain")
......@@ -543,9 +543,9 @@ class DetailMateriTest(TestCase):
def test_review_models_can_create_new_object(self):
test = Review.objects.create(
username="saul", profile="121212", review="232323")
countData = Review.objects.all().count()
self.assertEqual(1, countData)
self.assertNotEqual(0, countData)
count = Review.objects.all().count()
self.assertEqual(1, count)
self.assertNotEqual(0, count)
self.assertEqual(test.__str__(), "saul")
self.assertNotEqual(test.__str__(), "userlain")
......@@ -590,14 +590,14 @@ class DetailMateriTest(TestCase):
def test_detail_materi_contains_review_count(self):
url = self.url
self.client.login(**self.contributor_credential)
review = "This is new review by Contributor"
response = self.client.get(url)
self.assertContains(response, "Review (0)")
self.client.post(
url, {"review": "This is new review by Contributor"})
url, {"review": review })
self.client.post(
url, {"review": "This is new review by Contributor"})
url, {"review": review})
response = self.client.get(url)
self.assertContains(response, "Review (2)")
......
......@@ -137,9 +137,9 @@ class DetailMateri(TemplateView):
def post(self, request, *args, **kwargs):
commentText = request.POST.get("comment", None)
reviewText = request.POST.get("review", None)
if ((commentText == None or commentText == "" )and (reviewText == None or reviewText == "")):
comment_text = request.POST.get("comment", None)
review_text = request.POST.get("review", None)
if ((comment_text == None or comment_text == "" )and (review_text == None or review_text == "")):
context = self.get_context_data(*args, **kwargs)
context["error_message"] = "Anda belum menuliskan komentar"
context["materi_data"] = get_object_or_404(Materi, pk=kwargs["pk"])
......@@ -152,14 +152,14 @@ class DetailMateri(TemplateView):
materi = get_object_or_404(Materi, pk=kwargs["pk"])
user_obj = request.user if request.user.is_authenticated else None
if user_obj:
if (commentText != None ):
if (comment_text != None ):
comment = Comment.objects.create(
comment=commentText, username=DetailMateriService.get_user_name(request), materi=materi, user=user_obj
comment=comment_text, username=DetailMateriService.get_user_name(request), materi=materi, user=user_obj
)
comment.save()
elif (reviewText != None):
elif (review_text != None):
review = Review.objects.create(
review=reviewText, username=DetailMateriService.get_user_name(request), materi=materi, user=user_obj
review=review_text, username=DetailMateriService.get_user_name(request), materi=materi, user=user_obj
)
review.save()
return HttpResponseRedirect(request.path)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment