aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content
diff options
context:
space:
mode:
Diffstat (limited to 'pydis_site/apps/content')
-rw-r--r--pydis_site/apps/content/tests/test_utils.py40
-rw-r--r--pydis_site/apps/content/tests/test_views.py10
-rw-r--r--pydis_site/apps/content/utils.py38
-rw-r--r--pydis_site/apps/content/views/article_category.py1
4 files changed, 1 insertions, 88 deletions
diff --git a/pydis_site/apps/content/tests/test_utils.py b/pydis_site/apps/content/tests/test_utils.py
index 85f1139a..26b2bba9 100644
--- a/pydis_site/apps/content/tests/test_utils.py
+++ b/pydis_site/apps/content/tests/test_utils.py
@@ -146,43 +146,3 @@ class TestGetArticle(TestCase):
"""Check does this raise Http404 when category don't exist."""
with self.assertRaises(Http404):
utils.get_article(["invalid", "some-guide"])
-
-
-class GetGitHubInformationTests(TestCase):
- @patch("pydis_site.apps.content.utils.requests.get")
- @patch("pydis_site.apps.content.utils.COMMITS_URL", "foobar")
- def test_call_get_github_information_requests_get(self, requests_get_mock):
- """Check does this call requests.get function with proper URL."""
- utils.get_github_information(["foo"])
- requests_get_mock.assert_called_once_with("foobar")
-
- @patch("pydis_site.apps.content.utils.requests.get")
- def test_github_status_code_200_response(self, requests_get_mock):
- """Check does this return provided modified date and contributors."""
- requests_get_mock.return_value = MagicMock(status_code=200)
- requests_get_mock.return_value.json.return_value = [{
- "commit": {
- "committer": {
- "date": datetime(2020, 10, 1).isoformat(),
- "name": "foobar",
- }
- },
- "committer": {
- "html_url": "abc1234"
- }
- }]
- result = utils.get_github_information(["foo"])
- self.assertEqual(result, {
- "last_modified": datetime(2020, 10, 1).strftime("%dth %B %Y"),
- "contributors": {"foobar": "abc1234"}
- })
-
- @patch("pydis_site.apps.content.utils.requests.get")
- def test_github_other_status_code_response(self, requests_get_mock):
- """Check does this return provided modified date and contributors."""
- requests_get_mock.return_value = MagicMock(status_code=404)
- result = utils.get_github_information(["foo"])
- self.assertEqual(result, {
- "last_modified": "N/A",
- "contributors": {}
- })
diff --git a/pydis_site/apps/content/tests/test_views.py b/pydis_site/apps/content/tests/test_views.py
index 98b99b83..55bfb8ea 100644
--- a/pydis_site/apps/content/tests/test_views.py
+++ b/pydis_site/apps/content/tests/test_views.py
@@ -30,8 +30,7 @@ class TestArticleOrCategoryView(TestCase):
@override_settings(ARTICLES_PATH=BASE_PATH)
@patch("pydis_site.apps.content.views.article_category.utils.get_article")
@patch("pydis_site.apps.content.views.article_category.utils.get_category")
- @patch("pydis_site.apps.content.views.article_category.utils.get_github_information")
- def test_article_return_code_200(self, gh_info_mock, get_category_mock, get_article_mock):
+ def test_article_return_code_200(self, get_category_mock, get_article_mock):
get_article_mock.return_value = {"guide": "test", "metadata": {}}
url = reverse("content:article_category", args=["test2"])
@@ -39,7 +38,6 @@ class TestArticleOrCategoryView(TestCase):
self.assertEqual(response.status_code, 200)
get_category_mock.assert_not_called()
get_article_mock.assert_called_once()
- gh_info_mock.assert_called_once()
@patch("pydis_site.apps.content.views.article_category.utils.get_article")
@patch("pydis_site.apps.content.views.article_category.utils.get_category")
@@ -99,11 +97,9 @@ class TestArticleOrCategoryView(TestCase):
@patch("pydis_site.apps.content.views.article_category.utils.get_article")
@patch("pydis_site.apps.content.views.article_category.utils.get_category")
- @patch("pydis_site.apps.content.views.article_category.utils.get_github_information")
@override_settings(ARTICLES_PATH=BASE_PATH)
def test_valid_category_article_code_200(
self,
- gh_info_mock,
get_category_mock,
get_article_mock
):
@@ -115,15 +111,12 @@ class TestArticleOrCategoryView(TestCase):
self.assertEqual(response.status_code, 200)
get_article_mock.assert_called_once()
self.assertEqual(get_category_mock.call_count, 2)
- gh_info_mock.assert_called_once()
@patch("pydis_site.apps.content.views.article_category.utils.get_article")
@patch("pydis_site.apps.content.views.article_category.utils.get_category")
- @patch("pydis_site.apps.content.views.article_category.utils.get_github_information")
@override_settings(ARTICLES_PATH=BASE_PATH)
def test_invalid_category_article_code_404(
self,
- gh_info_mock,
get_category_mock,
get_article_mock
):
@@ -135,7 +128,6 @@ class TestArticleOrCategoryView(TestCase):
self.assertEqual(response.status_code, 404)
get_article_mock.assert_not_called()
get_category_mock.assert_not_called()
- gh_info_mock.assert_not_called()
@override_settings(ARTICLES_PATH=BASE_PATH)
def test_article_category_template_names(self):
diff --git a/pydis_site/apps/content/utils.py b/pydis_site/apps/content/utils.py
index a89db83c..305d26b5 100644
--- a/pydis_site/apps/content/utils.py
+++ b/pydis_site/apps/content/utils.py
@@ -1,16 +1,11 @@
import os
from typing import Dict, List, Optional, Union
-import requests
import yaml
-from dateutil import parser
from django.conf import settings
from django.http import Http404
from markdown2 import markdown
-COMMITS_URL = "https://api.github.com/repos/{owner}/{name}/commits?path={path}&sha={branch}"
-BASE_ARTICLES_LOCATION = "pydis_site/apps/content/resources/content/"
-
def get_category(path: List[str]) -> Dict[str, str]:
"""Load category information by name from _info.yml."""
@@ -77,36 +72,3 @@ def get_article(path: List[str]) -> Dict[str, Union[str, Dict]]:
)
return {"article": str(html), "metadata": html.metadata}
-
-
-def get_github_information(
- path: List[str]
-) -> Dict[str, Union[List[str], str]]:
- """Get article last modified date and contributors from GitHub."""
- result = requests.get(
- COMMITS_URL.format(
- owner=settings.SITE_REPOSITORY_OWNER,
- name=settings.SITE_REPOSITORY_NAME,
- branch=settings.SITE_REPOSITORY_BRANCH,
- path=(
- f"{BASE_ARTICLES_LOCATION}{'/'.join(path[:-1])}"
- f"{'/' if len(path) > 1 else ''}{path[-1]}.md"
- )
- )
- )
-
- if result.status_code == 200 and len(result.json()):
- data = result.json()
- return {
- "last_modified": parser.isoparse(
- data[0]["commit"]["committer"]["date"]
- ).strftime("%dth %B %Y"),
- "contributors": {
- c["commit"]["committer"]["name"]: c["committer"]["html_url"] for c in data
- }
- }
- else:
- return {
- "last_modified": "N/A",
- "contributors": {}
- }
diff --git a/pydis_site/apps/content/views/article_category.py b/pydis_site/apps/content/views/article_category.py
index 0c22b5e8..51b1def2 100644
--- a/pydis_site/apps/content/views/article_category.py
+++ b/pydis_site/apps/content/views/article_category.py
@@ -54,7 +54,6 @@ class ArticleOrCategoryView(TemplateView):
article_result["metadata"].get("relevant_link_values", "").split(",")
) if link != "" and value != ""
}
- context["github_data"] = utils.get_github_information(location)
else:
raise Http404