aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2019-04-19 13:19:12 +0200
committerGravatar Leon Sandøy <[email protected]>2019-04-19 13:19:12 +0200
commit2e1bed546023758cfe540b0536244263f68fe67b (patch)
tree16a5478a1e88655b61f1cdd21067efb5bd27122d
parentAddressing all of volcyys review comments, and adding linting and full test c... (diff)
Added test cases to increase coverage for this PR to 100%
-rw-r--r--pydis_site/apps/main/admin.py3
-rw-r--r--pydis_site/apps/main/tests/test_repodata_helpers.py37
2 files changed, 37 insertions, 3 deletions
diff --git a/pydis_site/apps/main/admin.py b/pydis_site/apps/main/admin.py
deleted file mode 100644
index 4185d360..00000000
--- a/pydis_site/apps/main/admin.py
+++ /dev/null
@@ -1,3 +0,0 @@
-# from django.contrib import admin
-
-# Register your models here.
diff --git a/pydis_site/apps/main/tests/test_repodata_helpers.py b/pydis_site/apps/main/tests/test_repodata_helpers.py
index 66aaa3d6..040acb21 100644
--- a/pydis_site/apps/main/tests/test_repodata_helpers.py
+++ b/pydis_site/apps/main/tests/test_repodata_helpers.py
@@ -1,5 +1,8 @@
+from datetime import timedelta
+
from django.conf import settings
from django.test import TestCase
+from django.utils import timezone
from pydis_site.apps.main.models import RepositoryMetadata
from pydis_site.apps.main.views import HomeView
@@ -16,6 +19,40 @@ class TestRepositoryMetadataHelpers(TestCase):
self.assertIsInstance(metadata[0], RepositoryMetadata)
self.assertEquals(len(metadata), len(settings.HOMEPAGE_REPOS))
+ def test_returns_cached_metadata(self):
+ """Test if the _get_repo_data helper returns cached data when available."""
+
+ home_view = HomeView()
+ repo_data = RepositoryMetadata(
+ repo_name="python-discord/site",
+ description="testrepo",
+ forks=42,
+ stargazers=42,
+ language="English",
+ )
+ repo_data.save()
+ metadata = home_view._get_repo_data()
+
+ self.assertIsInstance(metadata[0], RepositoryMetadata)
+ print(metadata[0]) # Tests the __str__ in the model
+
+ def test_refresh_stale_metadata(self):
+ """Test if the _get_repo_data helper will refresh when the data is stale"""
+
+ home_view = HomeView()
+ repo_data = RepositoryMetadata(
+ repo_name="python-discord/site",
+ description="testrepo",
+ forks=42,
+ stargazers=42,
+ language="English",
+ last_updated=timezone.now() - timedelta(seconds=121), # Make the data 2 minutes old.
+ )
+ repo_data.save()
+ metadata = home_view._get_repo_data()
+
+ self.assertIsInstance(metadata[0], RepositoryMetadata)
+
def test_returns_api_data(self):
"""Tests if the _get_api_data helper returns what it should."""