Fakultas Ilmu Komputer UI

Commit 5cdf8517 authored by Azhar Rais's avatar Azhar Rais
Browse files

[RED] Test forum home page pagination using given format (#123)

parent 4baf6312
Pipeline #59975 failed with stages
in 11 minutes and 37 seconds
......@@ -203,15 +203,26 @@ class ForumHomePageTest(TestCase):
self.assertIn("User Test", request.content.decode())
def test_forum_home_pagination(self):
for i in range(11):
pagination_html = lambda page: '<li class="page-item"><a class="page-link" href="?page={}">{}</a></li>' \
.format(page, page)
for i in range(51):
num = str(i)
Discussion.objects.create(title="Discussion " + num, description="Description " + num,
user=self.USER_CONTRIBUTOR)
request = self.client.get(FORUM_BASE_URL)
if Discussion.objects.all().count() <= 10:
self.assertIn("Page 1 of 1", request.content.decode())
else:
self.assertIn("Page 1 of 2", request.content.decode())
page_counter = Discussion.objects.all().count()
content = request.content.decode()
if page_counter == 5:
self.assertIn(pagination_html(1), content)
self.assertNotIn(pagination_html(2), content)
elif page_counter == 15:
self.assertIn(pagination_html(1), content)
self.assertIn(pagination_html(2), content)
elif page_counter == 51:
self.assertIn(pagination_html(1), content)
self.assertIn(pagination_html(2), content)
self.assertIn('<li class="page-item disabled"><a class="page-link" href="">...</a></li>', content)
self.assertIn(pagination_html(6), content)
class ForumCreateDiscussionPageTest(TestCase):
......
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