Skip to content

Commit

Permalink
Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
berk76 committed Mar 14, 2024
1 parent c1ddd06 commit 90dfd1a
Showing 1 changed file with 55 additions and 10 deletions.
65 changes: 55 additions & 10 deletions svjis/articles/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ def test_admin_user(self):
# Article for Board
response = self.client.get(reverse('article', kwargs={'pk': self.article_for_board.pk}))
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse('article', kwargs={'pk': self.article_for_board.pk}))
self.assertEqual(response.status_code, 200)

# Main page
response = self.client.get(reverse('main'))
Expand All @@ -145,14 +143,6 @@ def test_admin_user(self):
self.assertEqual(res_tray_menu[3]['description'], 'Redaction')
self.assertEqual(res_tray_menu[4]['description'], 'Administration')

# Top Articles
res_top = response.context['top_articles']
self.assertEqual(len(res_top), 2)
self.assertEqual(res_top[0]['article_id'], self.article_for_board.pk)
self.assertEqual(res_top[0]['total'], 2)
self.assertEqual(res_top[1]['article_id'], self.article_for_all.pk)
self.assertEqual(res_top[1]['total'], 1)

# List of Articles
res_articles = response.context['article_list']
self.assertEqual(len(res_articles), 3)
Expand Down Expand Up @@ -295,3 +285,58 @@ def test_anonymous_user(self):
res_articles = response.context['article_list']
self.assertEqual(len(res_articles), 1)
self.assertEqual(res_articles[0].header, 'For All')


def test_top_articles(self):
# Login board user
logged_in = self.client.login(username='jiri', password=users['jiri']['password'])
self.assertEqual(logged_in, True)

# Article for all
response = self.client.get(reverse('article', kwargs={'pk': self.article_for_all.pk}))
self.assertEqual(response.status_code, 200)

# Article for Board
response = self.client.get(reverse('article', kwargs={'pk': self.article_for_board.pk}))
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse('article', kwargs={'pk': self.article_for_board.pk}))
self.assertEqual(response.status_code, 200)

# Main page
response = self.client.get(reverse('main'))
self.assertEqual(response.status_code, 200)

# Top Articles
res_top = response.context['top_articles']
self.assertEqual(len(res_top), 2)
self.assertEqual(res_top[0]['article_id'], self.article_for_board.pk)
self.assertEqual(res_top[0]['total'], 2)
self.assertEqual(res_top[1]['article_id'], self.article_for_all.pk)
self.assertEqual(res_top[1]['total'], 1)

# Login owner user
logged_in = self.client.login(username='petr', password=users['petr']['password'])
self.assertEqual(logged_in, True)

# Main page
response = self.client.get(reverse('main'))
self.assertEqual(response.status_code, 200)

# Top Articles
res_top = response.context['top_articles']
self.assertEqual(len(res_top), 1)
self.assertEqual(res_top[0]['article_id'], self.article_for_all.pk)
self.assertEqual(res_top[0]['total'], 1)

# Logout user
self.client.logout()

# Main page
response = self.client.get(reverse('main'))
self.assertEqual(response.status_code, 200)

# Top Articles
res_top = response.context['top_articles']
self.assertEqual(len(res_top), 1)
self.assertEqual(res_top[0]['article_id'], self.article_for_all.pk)
self.assertEqual(res_top[0]['total'], 1)

0 comments on commit 90dfd1a

Please sign in to comment.