Fakultas Ilmu Komputer UI

Commit d6cb9864 authored by Rahmania Astrid Mochtar's avatar Rahmania Astrid Mochtar
Browse files

Handle and implement automated comment

parent adfd97f1
......@@ -19,5 +19,14 @@
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
{% endfor %}
</table>
{% if items|length == 0 %}
<h5>yey, waktunya berlibur</h5>
{% elif items|length < 5 %}
<h5>sibuk tapi santai</h5>
{% else %}
<h5>oh tidak</h5>
{% endif %}
</body>
</html>
\ No newline at end of file
......@@ -19,6 +19,12 @@ class HomePageTest(TestCase):
csrf_regex = r'<input[^>]+csrfmiddlewaretoken[^>]+>'
return re.sub(csrf_regex, '', html_code)
@staticmethod
def create_items(num):
for i in range(1, num+1):
text = 'itemey ' + str(i)
Item.objects.create(text=text)
def test_home_page_returns_correct_html(self):
request = HttpRequest()
response = home_page(request)
......@@ -55,19 +61,60 @@ class HomePageTest(TestCase):
self.assertEqual(Item.objects.count(), 0)
def test_home_page_displays_all_list_items(self):
Item.objects.create(text='itemey 1')
Item.objects.create(text='itemey 2')
self.create_items(2)
# Item.objects.create(text='itemey 1')
# Item.objects.create(text='itemey 2')
request = HttpRequest()
response = home_page(request)
self.assertIn(
'itemey 1',
self.remove_csrf(response.content.decode())
response.content.decode()
)
self.assertIn(
'itemey 2',
self.remove_csrf(response.content.decode())
response.content.decode()
)
def test_automated_comment_if_list_empty(self):
request = HttpRequest()
response = home_page(request)
self.assertIn(
'yey, waktunya berlibur',
response.content.decode()
)
def test_automated_comment_if_list_less_than_5(self):
self.create_items(4)
# Item.objects.create(text='itemey 1')
# Item.objects.create(text='itemey 2')
# Item.objects.create(text='itemey 3')
# Item.objects.create(text='itemey 4')
request = HttpRequest()
response = home_page(request)
self.assertIn(
'sibuk tapi santai',
response.content.decode()
)
def test_automated_comment_if_list_5_or_more(self):
self.create_items(5)
# Item.objects.create(text='itemey 1')
# Item.objects.create(text='itemey 2')
# Item.objects.create(text='itemey 3')
# Item.objects.create(text='itemey 4')
# Item.objects.create(text='itemey 5')
request = HttpRequest()
response = home_page(request)
self.assertIn(
'oh tidak',
response.content.decode()
)
......
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