Skip to content

Commit

Permalink
Merge pull request #356 from ajib6ept/add-test-leaderboard
Browse files Browse the repository at this point in the history
[#347] add test for the leaderboard
  • Loading branch information
sgmdlt authored Oct 16, 2023
2 parents 0ecbe44 + 02c538a commit d8341bc
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contributors/fixtures/repositories.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"html_url": "https://github.com/mintough57/scriptaculous",
"is_tracked": true,
"owner": 1,
"organization": null,
"organization": 1,
"project": null,
"full_name": "mintough57/scriptaculous",
"is_visible": true,
Expand Down
3 changes: 3 additions & 0 deletions contributors/tests/test_contributors_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestContributorDetailView(TestCase):
"contributors",
"labels",
"repositories",
"organizations",
]

def setUp(self):
Expand Down Expand Up @@ -55,6 +56,7 @@ class TestContributorIssuesView(TestCase):
"issues",
"labels",
"repositories",
"organizations",
]

def setUp(self):
Expand Down Expand Up @@ -85,6 +87,7 @@ class TestContributorPrView(TestCase):
"contributors",
"labels",
"repositories",
"organizations",
]

def setUp(self):
Expand Down
1 change: 1 addition & 0 deletions contributors/tests/test_issue_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TestIssuesListViewTestCase(TestCase):
"issues",
"labels",
"repositories",
"organizations",
]

def setUp(self):
Expand Down
100 changes: 100 additions & 0 deletions contributors/tests/test_leaderboard_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from http import HTTPStatus

from django.test import Client, TestCase
from django.urls import reverse

SEARCH_FORM_CONTEXT_NAME = "form_org"
SEARCH_PARAM_ORG_EXISTS = { # noqa: WPS407
"search": "",
"organizations": "hexlet",
}
SEARCH_PARAM_ORG_NOT_EXISTS = { # noqa: WPS407
"search": "",
"organizations": "123456",
}

OBJECTS_KEY = 'contributor_list'


class TestContributorLeaderboardViews(TestCase):
"""Test the functional leaderboard."""

fixtures = [
"organizations",
"repositories",
"contributions",
"issues",
"contributors",
"contributionlabel",
"labels",
]

def setUp(self):
"""Create a test database."""
self.client: Client = Client()

def test_contributor_leaderboard_commits_view(self):
response = self.client.get(
reverse("contributors:leaderboard_commits"),
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertIn(SEARCH_FORM_CONTEXT_NAME, response.context)

def test_contributor_leaderboard_commits_methods(self):
response = self.client.get(
reverse("contributors:leaderboard_commits"),
SEARCH_PARAM_ORG_NOT_EXISTS,
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertEqual(len(response.context[OBJECTS_KEY]), 0)

response = self.client.get(
reverse("contributors:leaderboard_commits"),
SEARCH_PARAM_ORG_EXISTS,
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertNotEqual(len(response.context[OBJECTS_KEY]), 0)

def test_contributor_leaderboard_prs_view(self):
response = self.client.get(
reverse("contributors:leaderboard_prs"),
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertIn(SEARCH_FORM_CONTEXT_NAME, response.context)

def test_contributor_leaderboard_prs_methods(self):
response = self.client.get(
reverse("contributors:leaderboard_prs"),
SEARCH_PARAM_ORG_NOT_EXISTS,
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertEqual(len(response.context[OBJECTS_KEY]), 0)

response = self.client.get(
reverse("contributors:leaderboard_prs"),
SEARCH_PARAM_ORG_EXISTS,
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertNotEqual(len(response.context[OBJECTS_KEY]), 0)

def test_contributor_leaderboard_issues_view(self):
response = self.client.get(
reverse("contributors:leaderboard_issues"),
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertIn(SEARCH_FORM_CONTEXT_NAME, response.context)

def test_contributor_leaderboard_issues_methods(self):
response = self.client.get(
reverse("contributors:leaderboard_issues"),
SEARCH_PARAM_ORG_NOT_EXISTS,
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertEqual(len(response.context[OBJECTS_KEY]), 0)

response = self.client.get(
reverse("contributors:leaderboard_issues"),
SEARCH_PARAM_ORG_EXISTS,
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertNotEqual(len(response.context[OBJECTS_KEY]), 0)
2 changes: 1 addition & 1 deletion contributors/tests/test_repository_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class TestProjectRepositoryListTestCase(TestCase):
"""Test the methods for the repository's details view."""

fixtures = ["contributors", "labels", "repositories"]
fixtures = ["contributors", "labels", "repositories", "organizations"]

def setUp(self):
"""Create a test database."""
Expand Down

0 comments on commit d8341bc

Please sign in to comment.