diff options
| author | 2021-03-14 23:49:00 +0100 | |
|---|---|---|
| committer | 2021-03-15 00:39:58 +0100 | |
| commit | f9a5c68a4f5400f6963f0795071110ebdc4eebbc (patch) | |
| tree | e8534db8528370145a42f3e6340daf6f3de6a8cb /pydis_site/apps/home/tests | |
| parent | Create migration for doc package name validator. (diff) | |
| parent | Dockerfile optimisations (diff) | |
Merge branch 'main' into doc-validator
Diffstat (limited to 'pydis_site/apps/home/tests')
| -rw-r--r-- | pydis_site/apps/home/tests/mock_github_api_response.json | 4 | ||||
| -rw-r--r-- | pydis_site/apps/home/tests/test_repodata_helpers.py | 42 | ||||
| -rw-r--r-- | pydis_site/apps/home/tests/test_views.py | 8 |
3 files changed, 45 insertions, 9 deletions
diff --git a/pydis_site/apps/home/tests/mock_github_api_response.json b/pydis_site/apps/home/tests/mock_github_api_response.json index 35604a85..ddbffed8 100644 --- a/pydis_site/apps/home/tests/mock_github_api_response.json +++ b/pydis_site/apps/home/tests/mock_github_api_response.json @@ -28,14 +28,14 @@ "forks_count": 31 }, { - "full_name": "python-discord/flake8-annotations", + "full_name": "python-discord/metricity", "description": "test", "stargazers_count": 97, "language": "Python", "forks_count": 31 }, { - "full_name": "python-discord/seasonalbot", + "full_name": "python-discord/sir-lancebot", "description": "test", "stargazers_count": 97, "language": "Python", diff --git a/pydis_site/apps/home/tests/test_repodata_helpers.py b/pydis_site/apps/home/tests/test_repodata_helpers.py index 77b1a68d..5634bc9b 100644 --- a/pydis_site/apps/home/tests/test_repodata_helpers.py +++ b/pydis_site/apps/home/tests/test_repodata_helpers.py @@ -123,10 +123,38 @@ class TestRepositoryMetadataHelpers(TestCase): mock_get.return_value.json.return_value = ['garbage'] metadata = self.home_view._get_repo_data() - self.assertEquals(len(metadata), len(self.home_view.repos)) - for item in metadata: - with self.subTest(item=item): - self.assertEqual(item.description, "Not available.") - self.assertEqual(item.forks, 999) - self.assertEqual(item.stargazers, 999) - self.assertEqual(item.language, "Python") + self.assertEquals(len(metadata), 0) + + def test_cleans_up_stale_metadata(self): + """Tests that we clean up stale metadata when we start the HomeView.""" + repo_data = RepositoryMetadata( + repo_name="python-discord/INVALID", + description="testrepo", + forks=42, + stargazers=42, + language="English", + last_updated=timezone.now() - timedelta(seconds=HomeView.repository_cache_ttl + 1), + ) + repo_data.save() + self.home_view.__init__() + cached_repos = RepositoryMetadata.objects.all() + cached_names = [repo.repo_name for repo in cached_repos] + + self.assertNotIn("python-discord/INVALID", cached_names) + + def test_dont_clean_up_unstale_metadata(self): + """Tests that we don't clean up good metadata when we start the HomeView.""" + repo_data = RepositoryMetadata( + repo_name="python-discord/site", + description="testrepo", + forks=42, + stargazers=42, + language="English", + last_updated=timezone.now() - timedelta(seconds=HomeView.repository_cache_ttl + 1), + ) + repo_data.save() + self.home_view.__init__() + cached_repos = RepositoryMetadata.objects.all() + cached_names = [repo.repo_name for repo in cached_repos] + + self.assertIn("python-discord/site", cached_names) diff --git a/pydis_site/apps/home/tests/test_views.py b/pydis_site/apps/home/tests/test_views.py index 572317a7..40c80205 100644 --- a/pydis_site/apps/home/tests/test_views.py +++ b/pydis_site/apps/home/tests/test_views.py @@ -203,6 +203,14 @@ class TestIndexReturns200(TestCase): self.assertEqual(resp.status_code, 200) +class TestTimelineReturns200(TestCase): + def test_timeline_returns_200(self): + """Check that the timeline page returns a HTTP 200 response.""" + url = reverse('timeline') + resp = self.client.get(url) + self.assertEqual(resp.status_code, 200) + + class TestLoginCancelledReturns302(TestCase): def test_login_cancelled_returns_302(self): """Check that the login cancelled redirect returns a HTTP 302 response.""" |