From e43d5f97bb27d13bb75f22edd8fd2e19e2d22f8d Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 19 Apr 2019 14:54:48 +0100 Subject: First testing attempt --- pydis_site/apps/home/tests/__init__.py | 0 .../apps/home/tests/test_wiki_templatetags.py | 39 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 pydis_site/apps/home/tests/__init__.py create mode 100644 pydis_site/apps/home/tests/test_wiki_templatetags.py (limited to 'pydis_site/apps/home/tests') diff --git a/pydis_site/apps/home/tests/__init__.py b/pydis_site/apps/home/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pydis_site/apps/home/tests/test_wiki_templatetags.py b/pydis_site/apps/home/tests/test_wiki_templatetags.py new file mode 100644 index 00000000..af85339f --- /dev/null +++ b/pydis_site/apps/home/tests/test_wiki_templatetags.py @@ -0,0 +1,39 @@ +from unittest.mock import Mock + +from django.test import TestCase +from django.template import Template +from wiki.models import URLPath as _URLPath + + +URLPath = Mock(_URLPath) + + +class TestURLPathFilter(TestCase): + TEMPLATE = Template( + """ + {% load wiki_extra %} + {{ obj|render_urlpath }} + """ + ) + + def test_str(self): + context = {"obj": "path"} + rendered = self.TEMPLATE.render(context) + + def test_str_empty(self): + context = {"obj": ""} + rendered = self.TEMPLATE.render(context) + + def test_urlpath(self): + url_path = URLPath() + url_path.path = None + + context = {"obj": url_path} + rendered = self.TEMPLATE.render(context) + + def test_urlpath_root(self): + url_path = URLPath() + url_path.path = "/path/" + + context = {"obj": url_path} + rendered = self.TEMPLATE.render(context) -- cgit v1.2.3 From 4664d705f2fcb3d152408cbf3915044d193d38dc Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 19 Apr 2019 15:20:06 +0100 Subject: Wiki requires notification plugin, so we're stuck with it --- .../apps/home/tests/test_wiki_templatetags.py | 24 ++++++++++++++-------- pydis_site/settings.py | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'pydis_site/apps/home/tests') diff --git a/pydis_site/apps/home/tests/test_wiki_templatetags.py b/pydis_site/apps/home/tests/test_wiki_templatetags.py index af85339f..5cd673bf 100644 --- a/pydis_site/apps/home/tests/test_wiki_templatetags.py +++ b/pydis_site/apps/home/tests/test_wiki_templatetags.py @@ -1,7 +1,7 @@ from unittest.mock import Mock from django.test import TestCase -from django.template import Template +from django.template import Template, Context from wiki.models import URLPath as _URLPath @@ -17,23 +17,31 @@ class TestURLPathFilter(TestCase): ) def test_str(self): - context = {"obj": "path"} - rendered = self.TEMPLATE.render(context) + context = {"obj": "/path/"} + rendered = self.TEMPLATE.render(Context(context)) + + self.assertEqual(rendered.strip(), "/path/") def test_str_empty(self): context = {"obj": ""} - rendered = self.TEMPLATE.render(context) + rendered = self.TEMPLATE.render(Context(context)) + + self.assertEqual(rendered.strip(), "/") def test_urlpath(self): url_path = URLPath() - url_path.path = None + url_path.path = "/path/" context = {"obj": url_path} - rendered = self.TEMPLATE.render(context) + rendered = self.TEMPLATE.render(Context(context)) + + self.assertEqual(rendered.strip(), "/path/") def test_urlpath_root(self): url_path = URLPath() - url_path.path = "/path/" + url_path.path = None context = {"obj": url_path} - rendered = self.TEMPLATE.render(context) + rendered = self.TEMPLATE.render(Context(context)) + + self.assertEqual(rendered.strip(), "/") diff --git a/pydis_site/settings.py b/pydis_site/settings.py index 0bd4957b..4ffb06a1 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -93,6 +93,7 @@ INSTALLED_APPS = [ 'wiki.plugins.images.apps.ImagesConfig', 'wiki.plugins.links.apps.LinksConfig', 'wiki.plugins.redlinks.apps.RedlinksConfig', + 'wiki.plugins.notifications.apps.NotificationsConfig', # Required for migrations ] MIDDLEWARE = [ -- cgit v1.2.3 From af7f04a21ca1a701a69e3b3c1e7b0f7c7bbb6b0b Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 19 Apr 2019 16:08:10 +0100 Subject: Tests for templatetags --- pydis_site/apps/home/templatetags/wiki_extra.py | 53 ++---- .../apps/home/tests/test_wiki_templatetags.py | 187 ++++++++++++++++++++- 2 files changed, 195 insertions(+), 45 deletions(-) (limited to 'pydis_site/apps/home/tests') diff --git a/pydis_site/apps/home/templatetags/wiki_extra.py b/pydis_site/apps/home/templatetags/wiki_extra.py index 16539ded..a6861fd9 100644 --- a/pydis_site/apps/home/templatetags/wiki_extra.py +++ b/pydis_site/apps/home/templatetags/wiki_extra.py @@ -1,12 +1,8 @@ -from typing import Union +from typing import Union, Dict, Type, Any from django import template -from django.forms import ( - BooleanField, BoundField, CharField, ChoiceField, ComboField, DateField, DateTimeField, DecimalField, DurationField, - EmailField, Field, FileField, FilePathField, FloatField, GenericIPAddressField, ImageField, IntegerField, - ModelChoiceField, ModelMultipleChoiceField, MultiValueField, MultipleChoiceField, NullBooleanField, RegexField, - SlugField, SplitDateTimeField, TimeField, TypedChoiceField, TypedMultipleChoiceField, URLField, UUIDField) -from django.template import Template, Context +from django.forms import BooleanField, BoundField, CharField, Field, ImageField, ModelChoiceField +from django.template import Context from django.template.loader import get_template from django.utils.safestring import mark_safe from wiki.editors.markitup import MarkItUpWidget @@ -16,38 +12,12 @@ from wiki.plugins.notifications.forms import SettingsModelChoiceField TEMPLATE_PATH = "wiki/forms/fields/{0}.html" -TEMPLATES = { +TEMPLATES: Dict[Type, str] = { BooleanField: TEMPLATE_PATH.format("boolean"), CharField: TEMPLATE_PATH.format("char"), - ChoiceField: TEMPLATE_PATH.format("in_place_render"), - TypedChoiceField: TEMPLATE_PATH.format("in_place_render"), - DateField: TEMPLATE_PATH.format("in_place_render"), - DateTimeField: TEMPLATE_PATH.format("in_place_render"), - DecimalField: TEMPLATE_PATH.format("in_place_render"), - DurationField: TEMPLATE_PATH.format("in_place_render"), - EmailField: TEMPLATE_PATH.format("in_place_render"), - FileField: TEMPLATE_PATH.format("in_place_render"), - FilePathField: TEMPLATE_PATH.format("in_place_render"), - FloatField: TEMPLATE_PATH.format("in_place_render"), ImageField: TEMPLATE_PATH.format("image"), - IntegerField: TEMPLATE_PATH.format("in_place_render"), - GenericIPAddressField: TEMPLATE_PATH.format("in_place_render"), - MultipleChoiceField: TEMPLATE_PATH.format("in_place_render"), - TypedMultipleChoiceField: TEMPLATE_PATH.format("in_place_render"), - NullBooleanField: TEMPLATE_PATH.format("in_place_render"), - RegexField: TEMPLATE_PATH.format("in_place_render"), - SlugField: TEMPLATE_PATH.format("in_place_render"), - TimeField: TEMPLATE_PATH.format("in_place_render"), - URLField: TEMPLATE_PATH.format("in_place_render"), - UUIDField: TEMPLATE_PATH.format("in_place_render"), - - ComboField: TEMPLATE_PATH.format("in_place_render"), - MultiValueField: TEMPLATE_PATH.format("in_place_render"), - SplitDateTimeField: TEMPLATE_PATH.format("in_place_render"), ModelChoiceField: TEMPLATE_PATH.format("model_choice"), - ModelMultipleChoiceField: TEMPLATE_PATH.format("in_place_render"), - SettingsModelChoiceField: TEMPLATE_PATH.format("model_choice"), WikiSlugField: TEMPLATE_PATH.format("wiki_slug_render"), } @@ -56,13 +26,17 @@ TEMPLATES = { register = template.Library() -def get_unbound_field(field: BoundField): +def get_unbound_field(field: BoundField) -> Field: while isinstance(field, BoundField): field = field.field return field +def render(template_path: str, context: Dict[str, Any]): + return mark_safe(get_template(template_path).render(context)) + + @register.simple_tag def render_field(field: Field, render_labels: bool = True): if isinstance(field, BoundField): @@ -73,16 +47,11 @@ def render_field(field: Field, render_labels: bool = True): if not isinstance(render_labels, bool): render_labels = True - template_path = TEMPLATES.get(unbound_field.__class__) + template_path = TEMPLATES.get(unbound_field.__class__, TEMPLATE_PATH.format("in_place_render")) is_markitup = isinstance(unbound_field.widget, MarkItUpWidget) - - if not template_path: - raise NotImplementedError(f"Unknown field type: {unbound_field.__class__}") - - template_obj: Template = get_template(template_path) context = {"field": field, "is_markitup": is_markitup, "render_labels": render_labels} - return mark_safe(template_obj.render(context)) + return render(template_path, context) @register.simple_tag(takes_context=True) diff --git a/pydis_site/apps/home/tests/test_wiki_templatetags.py b/pydis_site/apps/home/tests/test_wiki_templatetags.py index 5cd673bf..6399c0b6 100644 --- a/pydis_site/apps/home/tests/test_wiki_templatetags.py +++ b/pydis_site/apps/home/tests/test_wiki_templatetags.py @@ -1,9 +1,14 @@ -from unittest.mock import Mock +from unittest.mock import Mock, create_autospec +from django.forms import BooleanField, BoundField, CharField, ChoiceField, Field, Form, ImageField, ModelChoiceField +from django.template import Context, Template from django.test import TestCase -from django.template import Template, Context -from wiki.models import URLPath as _URLPath +from wiki.editors.markitup import MarkItUpWidget +from wiki.forms import WikiSlugField +from wiki.models import Article, URLPath as _URLPath +from wiki.plugins.notifications.forms import SettingsModelChoiceField +from pydis_site.apps.home.templatetags import wiki_extra URLPath = Mock(_URLPath) @@ -45,3 +50,179 @@ class TestURLPathFilter(TestCase): rendered = self.TEMPLATE.render(Context(context)) self.assertEqual(rendered.strip(), "/") + + +class TestRenderField(TestCase): + TEMPLATE = Template( + """ + {% load wiki_extra %} + {% render_field field %} + """ + ) + + TEMPLATE_NO_LABELS = Template( + """ + {% load wiki_extra %} + {% render_field field render_labels=False %} + """ + ) + + TEMPLATE_LABELS_NOT_BOOLEAN = Template( + """ + {% load wiki_extra %} + {% render_field field render_labels="" %} + """ + ) + + def test_bound_field(self): + unbound_field = Field() + field = BoundField(Form(), unbound_field, "field") + + context = Context({"field": field}) + self.TEMPLATE.render(context) + + def test_bound_field_no_labels(self): + unbound_field = Field() + field = BoundField(Form(), unbound_field, "field") + + context = Context({"field": field}) + self.TEMPLATE_NO_LABELS.render(context) + + def test_bound_field_labels_not_boolean(self): + unbound_field = Field() + field = BoundField(Form(), unbound_field, "field") + + context = Context({"field": field}) + self.TEMPLATE_LABELS_NOT_BOOLEAN.render(context) + + def test_unbound_field(self): + field = Field() + + context = Context({"field": field}) + self.TEMPLATE.render(context) + + def test_unbound_field_no_labels(self): + field = Field() + + context = Context({"field": field}) + self.TEMPLATE_NO_LABELS.render(context) + + def test_unbound_field_labels_not_boolean(self): + field = Field() + + context = Context({"field": field}) + self.TEMPLATE_LABELS_NOT_BOOLEAN.render(context) + + +class TestRenderFieldTypes(TestCase): + TEMPLATE = Template( + """ + {% load wiki_extra %} + {% render_field field %} + """ + ) + + @classmethod + def setUpClass(cls): + cls._wiki_extra_render = wiki_extra.render + wiki_extra.render = create_autospec(wiki_extra.render, return_value="") + + @classmethod + def tearDownClass(cls): + wiki_extra.render = cls._wiki_extra_render + del cls._wiki_extra_render + + def test_field_boolean(self): + field = BooleanField() + + context = Context({"field": field}) + self.TEMPLATE.render(context) + + template_path = "wiki/forms/fields/boolean.html" + context = {"field": field, "is_markitup": False, "render_labels": True} + + wiki_extra.render.assert_called_with(template_path, context) + + def test_field_char(self): + field = CharField() + field.widget = None + + context = Context({"field": field}) + self.TEMPLATE.render(context) + + template_path = "wiki/forms/fields/char.html" + context = {"field": field, "is_markitup": False, "render_labels": True} + + wiki_extra.render.assert_called_with(template_path, context) + + def test_field_char_markitup(self): + field = CharField() + field.widget = MarkItUpWidget() + + context = Context({"field": field}) + self.TEMPLATE.render(context) + + template_path = "wiki/forms/fields/char.html" + context = {"field": field, "is_markitup": True, "render_labels": True} + + wiki_extra.render.assert_called_with(template_path, context) + + def test_field_image(self): + field = ImageField() + + context = Context({"field": field}) + self.TEMPLATE.render(context) + + template_path = "wiki/forms/fields/image.html" + context = {"field": field, "is_markitup": False, "render_labels": True} + + wiki_extra.render.assert_called_with(template_path, context) + + def test_field_model_choice(self): + field = ModelChoiceField(Article.objects.all()) + + context = Context({"field": field}) + self.TEMPLATE.render(context) + + template_path = "wiki/forms/fields/model_choice.html" + context = {"field": field, "is_markitup": False, "render_labels": True} + + wiki_extra.render.assert_called_with(template_path, context) + + def test_field_settings_model_choice(self): + field = SettingsModelChoiceField(Article.objects.all()) + + context = Context({"field": field}) + self.TEMPLATE.render(context) + + template_path = "wiki/forms/fields/model_choice.html" + context = {"field": field, "is_markitup": False, "render_labels": True} + + wiki_extra.render.assert_called_with(template_path, context) + + def test_field_wiki_slug(self): + field = WikiSlugField() + + context = Context({"field": field}) + self.TEMPLATE.render(context) + + template_path = "wiki/forms/fields/wiki_slug_render.html" + context = {"field": field, "is_markitup": False, "render_labels": True} + + wiki_extra.render.assert_called_with(template_path, context) + + +class TestGetFieldOptions(TestCase): + TEMPLATE = Template( + """ + {% load wiki_extra %} + {% get_field_options field %} + """ + ) + + def test_get_field_options(self): + unbound_field = ChoiceField() + field = BoundField(Form(), unbound_field, "field") + + context = Context({"field": field}) + self.TEMPLATE.render(context) -- cgit v1.2.3 From 14e98f1e790c85e761c9ead44160ac1174f808d2 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 19 Apr 2019 17:59:55 +0100 Subject: Lint and update django-simple-bulma --- Pipfile | 2 +- Pipfile.lock | 77 +++++++++++----------- pydis_site/apps/home/templatetags/wiki_extra.py | 4 +- .../apps/home/tests/test_wiki_templatetags.py | 5 +- pydis_site/apps/home/urls.py | 2 +- pydis_site/settings.py | 8 +-- 6 files changed, 49 insertions(+), 49 deletions(-) (limited to 'pydis_site/apps/home/tests') diff --git a/Pipfile b/Pipfile index c6f210ab..d45db4d5 100644 --- a/Pipfile +++ b/Pipfile @@ -25,7 +25,7 @@ djangorestframework = "~=3.9.2" djangorestframework-bulk = "~=0.2.1" uwsgi = "~=2.0.18" psycopg2-binary = "~=2.8" -django-simple-bulma = ">=1.1.6,<2.0" +django-simple-bulma = ">=1.1.7,<2.0" django-crispy-bulma = ">=0.1.2,<2.0" wiki = "~=0.4.4" pygments = "~=2.3.1" diff --git a/Pipfile.lock b/Pipfile.lock index 777dbd38..071c3887 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d6bbf11476ca021d14ef03475ef6154b148d75a3ceada522194a56e80a27ccf1" + "sha256": "3e41d1f5aeff03b49de55ef5086b975ecb0f74341870622237e553e7a1190116" }, "pipfile-spec": 6, "requires": { @@ -101,18 +101,17 @@ }, "django-sekizai": { "hashes": [ - "sha256:39c5d16ad694aa78278ca84fdc7b9f953ebcf94e2fc95b68c875d02014303260", - "sha256:cbd48e7be29e8cc4108476b9420d7c391fc509a504bc20b60616b116ba6ea51e" + "sha256:642a3356fe92fe9b5ccc97f320b64edd2cfcb3b2fbb113e8a26dad9a1f3b5e14" ], - "version": "==0.10.0" + "version": "==1.0.0" }, "django-simple-bulma": { "hashes": [ - "sha256:420042e26dd4bc70b148fc721bd77a48130b62b3d91b977e56f8232a4cfac555", - "sha256:beb323aa1c51e5efee398b6e5a2b481b31a0be7505e3118d140c65349f637100" + "sha256:7dcc04a11b5a3aefb6ec57cb211c161df8421ea333638e03c9e7db87465fead2", + "sha256:f4bb4833c3272ec49e4901a53254de8e8d267da48b88f6f79af4c32f9f70c504" ], "index": "pypi", - "version": "==1.1.6" + "version": "==1.1.7" }, "djangorestframework": { "hashes": [ @@ -197,37 +196,37 @@ }, "psycopg2-binary": { "hashes": [ - "sha256:163d3ee445a0b4c0109877da9e46271aacf4e5e3d60ae7368669555c30f13e7c", - "sha256:1af0bfe7b0c13a0e613a27311fd4f9c5d024e8fc0f4b3d284e7df02a58a11fc0", - "sha256:2169c3a1bf52d5b30cc98625b5919a964c571a32e8646be20be6c7e3e82079de", - "sha256:218f079fa48e2ef812dc3d3ce6ec2f67ac56427ba4b038d5d6331f2cceb489c2", - "sha256:26a958930687e94c4c6c73c171e4d4783b82ae4e16aa3424e6bcd4529bceedf0", - "sha256:2c7c195aef3acdbc853942bc674844031a732890d2fee88a324298ed376b6c2b", - "sha256:2ecdbfed7004669472bfa27c8d51012c717c241c7154ae17e4c8f93024043525", - "sha256:345fc31b71a90ada1b51826537917b19a1af685a91c0f066787069c184d7d00f", - "sha256:378a06649503f548be5f1e9eec2e94cc1d6138250b82a08dcc6151bca8cec107", - "sha256:3f300bf2930e501dde09605de85cb2b84c2638e2c954be02a3c86f28176d3525", - "sha256:6c2f66c653ce8bbd7e789d0f7f92c3f9fea881b55226f0ae5ee550cce9e3cf0e", - "sha256:6fccbac2633831b877a8fbf865f7082d34895e82a015795a9f80f99a2efe2576", - "sha256:7a166f8ccb6888358d3e67795b057540ea7caa71ab9e089b0cb0097f01088965", - "sha256:8f6b84f887ec6fef6c1796779f8ec2603dc7e9ef52bc9269de719d4bcbdaebbb", - "sha256:92cf3ceb7bb90cf35b8bd993c640b15d4832ba0e142a3b9da5006ef217da595d", - "sha256:a20dfdf73f56da674926a3811929cff9fd23b9af90be9a6c36ac246a3486eef3", - "sha256:a84415df4689251556c961e4fe3b25d30e32f00faa8064ce0909458dbe0d67b2", - "sha256:ab1aa1cd50df3860f624c9713ee9e690eefd4e049d3a4d86577bab6e741e9616", - "sha256:abc9dcf85e75a8687f2a6d560c0c1a2593e8e34ba6f9ad6721f8212c5de179a2", - "sha256:c10454710a81a2f4b1ff4d1c83ac2cec63e0e55845a56324991514af5b1299d0", - "sha256:c38f80719e4dfae7a6311a4f091f07f4fb2fb5d602352015d5639f63f8fabb68", - "sha256:d75cf00605630b2cfefa5c62373c605dcda1cc0d607902847dbb8e8e9b67c1ce", - "sha256:dce15cb6ef604c9e38fdaa848f58f83153ade9f4aa5e4cf5812aa27163561750", - "sha256:e7e0db4311bb76bf3f6e0380f71912cfa6d0be7cc635e3772476050b0dabdabd", - "sha256:eac59cae78dfe3fbf7ece25c170d7a152f88df7643381aa5e7344c2028a8d8d4", - "sha256:ead7b3e1567bd14cacd44279c5e42cd19f54b9feed39180220253f4fbe3abd56", - "sha256:ed772a5e8e7e5dd6bede960a86940c17cf653c7f158dafa5d52e919b676f10ba", - "sha256:f2d73131acb94afa45de8b6b8a4bfb21bbe3736633d6478e53247f19dd8c299c" + "sha256:007ca0df127b1862fc010125bc4100b7a630efc6841047bd11afceadb4754611", + "sha256:03c49e02adf0b4d68f422fdbd98f7a7c547beb27e99a75ed02298f85cb48406a", + "sha256:0a1232cdd314e08848825edda06600455ad2a7adaa463ebfb12ece2d09f3370e", + "sha256:131c80d0958c89273d9720b9adf9df1d7600bb3120e16019a7389ab15b079af5", + "sha256:2de34cc3b775724623f86617d2601308083176a495f5b2efc2bbb0da154f483a", + "sha256:2eddc31500f73544a2a54123d4c4b249c3c711d31e64deddb0890982ea37397a", + "sha256:484f6c62bdc166ee0e5be3aa831120423bf399786d1f3b0304526c86180fbc0b", + "sha256:4c2d9369ed40b4a44a8ccd6bc3a7db6272b8314812d2d1091f95c4c836d92e06", + "sha256:70f570b5fa44413b9f30dbc053d17ef3ce6a4100147a10822f8662e58d473656", + "sha256:7a2b5b095f3bd733aab101c89c0e1a3f0dfb4ebdc26f6374805c086ffe29d5b2", + "sha256:804914a669186e2843c1f7fbe12b55aad1b36d40a28274abe6027deffad9433d", + "sha256:8520c03172da18345d012949a53617a963e0191ccb3c666f23276d5326af27b5", + "sha256:90da901fc33ea393fc644607e4a3916b509387e9339ec6ebc7bfded45b7a0ae9", + "sha256:a582416ad123291a82c300d1d872bdc4136d69ad0b41d57dc5ca3df7ef8e3088", + "sha256:ac8c5e20309f4989c296d62cac20ee456b69c41fd1bc03829e27de23b6fa9dd0", + "sha256:b2cf82f55a619879f8557fdaae5cec7a294fac815e0087c4f67026fdf5259844", + "sha256:b59d6f8cfca2983d8fdbe457bf95d2192f7b7efdb2b483bf5fa4e8981b04e8b2", + "sha256:be08168197021d669b9964bd87628fa88f910b1be31e7010901070f2540c05fd", + "sha256:be0f952f1c365061041bad16e27e224e29615d4eb1fb5b7e7760a1d3d12b90b6", + "sha256:c1c9a33e46d7c12b9c96cf2d4349d783e3127163fd96254dcd44663cf0a1d438", + "sha256:d18c89957ac57dd2a2724ecfe9a759912d776f96ecabba23acb9ecbf5c731035", + "sha256:d7e7b0ff21f39433c50397e60bf0995d078802c591ca3b8d99857ea18a7496ee", + "sha256:da0929b2bf0d1f365345e5eb940d8713c1d516312e010135b14402e2a3d2404d", + "sha256:de24a4962e361c512d3e528ded6c7480eab24c655b8ca1f0b761d3b3650d2f07", + "sha256:e45f93ff3f7dae2202248cf413a87aeb330821bf76998b3cf374eda2fc893dd7", + "sha256:f046aeae1f7a845041b8661bb7a52449202b6c5d3fb59eb4724e7ca088811904", + "sha256:f1dc2b7b2748084b890f5d05b65a47cd03188824890e9a60818721fd492249fb", + "sha256:fcbe7cf3a786572b73d2cd5f34ed452a5f5fac47c9c9d1e0642c457a148f9f88" ], "index": "pypi", - "version": "==2.8.1" + "version": "==2.8.2" }, "pygments": { "hashes": [ @@ -239,10 +238,10 @@ }, "pytz": { "hashes": [ - "sha256:32b0891edff07e28efe91284ed9c31e123d84bea3fd98e1f72be2508f43ef8d9", - "sha256:d5f05e487007e29e03409f9398d074e158d920d36eb82eaf66fb1136b0c5374c" + "sha256:303879e36b721603cc54604edcac9d20401bdbe31e1e4fdee5b9f98d5d31dfda", + "sha256:d747dd3d23d77ef44c6a3526e274af6efeb0a6f1afd5a69ba4d5be4098c8e141" ], - "version": "==2018.9" + "version": "==2019.1" }, "six": { "hashes": [ diff --git a/pydis_site/apps/home/templatetags/wiki_extra.py b/pydis_site/apps/home/templatetags/wiki_extra.py index a6861fd9..9847ef5a 100644 --- a/pydis_site/apps/home/templatetags/wiki_extra.py +++ b/pydis_site/apps/home/templatetags/wiki_extra.py @@ -1,4 +1,4 @@ -from typing import Union, Dict, Type, Any +from typing import Any, Dict, Type, Union from django import template from django.forms import BooleanField, BoundField, CharField, Field, ImageField, ModelChoiceField @@ -34,7 +34,7 @@ def get_unbound_field(field: BoundField) -> Field: def render(template_path: str, context: Dict[str, Any]): - return mark_safe(get_template(template_path).render(context)) + return mark_safe(get_template(template_path).render(context)) # noqa: S703 S308 @register.simple_tag diff --git a/pydis_site/apps/home/tests/test_wiki_templatetags.py b/pydis_site/apps/home/tests/test_wiki_templatetags.py index 6399c0b6..201d3df4 100644 --- a/pydis_site/apps/home/tests/test_wiki_templatetags.py +++ b/pydis_site/apps/home/tests/test_wiki_templatetags.py @@ -1,6 +1,9 @@ from unittest.mock import Mock, create_autospec -from django.forms import BooleanField, BoundField, CharField, ChoiceField, Field, Form, ImageField, ModelChoiceField +from django.forms import ( + BooleanField, BoundField, CharField, ChoiceField, Field, Form, ImageField, + ModelChoiceField +) from django.template import Context, Template from django.test import TestCase from wiki.editors.markitup import MarkItUpWidget diff --git a/pydis_site/apps/home/urls.py b/pydis_site/apps/home/urls.py index 34ceda40..6d144aaa 100644 --- a/pydis_site/apps/home/urls.py +++ b/pydis_site/apps/home/urls.py @@ -1,7 +1,7 @@ from django.conf import settings from django.conf.urls.static import static from django.contrib import admin -from django.urls import path, include +from django.urls import include, path from django.views.generic import TemplateView diff --git a/pydis_site/settings.py b/pydis_site/settings.py index 4ffb06a1..c4c8a535 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -14,10 +14,8 @@ import os import sys import environ - from django.contrib.messages import constants as messages - env = environ.Env( DEBUG=(bool, False) ) @@ -190,10 +188,10 @@ MEDIA_URL = '/media/' MEDIA_ROOT = env('MEDIA_ROOT', default='media') STATICFILES_FINDERS = [ - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', - 'django_simple_bulma.finders.SimpleBulmaFinder', + 'django_simple_bulma.finders.SimpleBulmaFinder', ] # django-hosts -- cgit v1.2.3 From 95f58097c5a00243786e4a84f74f89d67f84adf8 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 19 Apr 2019 18:25:40 +0100 Subject: Update Pipfile.lock and move home app tests --- Pipfile.lock | 38 +-------------------------- pydis_site/apps/home/tests.py | 16 ----------- pydis_site/apps/home/tests/test_app_basics.py | 16 +++++++++++ 3 files changed, 17 insertions(+), 53 deletions(-) delete mode 100644 pydis_site/apps/home/tests.py create mode 100644 pydis_site/apps/home/tests/test_app_basics.py (limited to 'pydis_site/apps/home/tests') diff --git a/Pipfile.lock b/Pipfile.lock index f076bb16..3d29dde8 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "3e41d1f5aeff03b49de55ef5086b975ecb0f74341870622237e553e7a1190116" + "sha256": "ae0a876a94064471b34aa7bfac7d64a589d43e1719690e043edacf3e30fb23fb" }, "pipfile-spec": 6, "requires": { @@ -196,34 +196,6 @@ }, "psycopg2-binary": { "hashes": [ - "sha256:163d3ee445a0b4c0109877da9e46271aacf4e5e3d60ae7368669555c30f13e7c", - "sha256:1af0bfe7b0c13a0e613a27311fd4f9c5d024e8fc0f4b3d284e7df02a58a11fc0", - "sha256:2169c3a1bf52d5b30cc98625b5919a964c571a32e8646be20be6c7e3e82079de", - "sha256:218f079fa48e2ef812dc3d3ce6ec2f67ac56427ba4b038d5d6331f2cceb489c2", - "sha256:26a958930687e94c4c6c73c171e4d4783b82ae4e16aa3424e6bcd4529bceedf0", - "sha256:2c7c195aef3acdbc853942bc674844031a732890d2fee88a324298ed376b6c2b", - "sha256:2ecdbfed7004669472bfa27c8d51012c717c241c7154ae17e4c8f93024043525", - "sha256:345fc31b71a90ada1b51826537917b19a1af685a91c0f066787069c184d7d00f", - "sha256:378a06649503f548be5f1e9eec2e94cc1d6138250b82a08dcc6151bca8cec107", - "sha256:3f300bf2930e501dde09605de85cb2b84c2638e2c954be02a3c86f28176d3525", - "sha256:6c2f66c653ce8bbd7e789d0f7f92c3f9fea881b55226f0ae5ee550cce9e3cf0e", - "sha256:6fccbac2633831b877a8fbf865f7082d34895e82a015795a9f80f99a2efe2576", - "sha256:7a166f8ccb6888358d3e67795b057540ea7caa71ab9e089b0cb0097f01088965", - "sha256:8f6b84f887ec6fef6c1796779f8ec2603dc7e9ef52bc9269de719d4bcbdaebbb", - "sha256:92cf3ceb7bb90cf35b8bd993c640b15d4832ba0e142a3b9da5006ef217da595d", - "sha256:a20dfdf73f56da674926a3811929cff9fd23b9af90be9a6c36ac246a3486eef3", - "sha256:a84415df4689251556c961e4fe3b25d30e32f00faa8064ce0909458dbe0d67b2", - "sha256:ab1aa1cd50df3860f624c9713ee9e690eefd4e049d3a4d86577bab6e741e9616", - "sha256:abc9dcf85e75a8687f2a6d560c0c1a2593e8e34ba6f9ad6721f8212c5de179a2", - "sha256:c10454710a81a2f4b1ff4d1c83ac2cec63e0e55845a56324991514af5b1299d0", - "sha256:c38f80719e4dfae7a6311a4f091f07f4fb2fb5d602352015d5639f63f8fabb68", - "sha256:d75cf00605630b2cfefa5c62373c605dcda1cc0d607902847dbb8e8e9b67c1ce", - "sha256:dce15cb6ef604c9e38fdaa848f58f83153ade9f4aa5e4cf5812aa27163561750", - "sha256:e7e0db4311bb76bf3f6e0380f71912cfa6d0be7cc635e3772476050b0dabdabd", - "sha256:eac59cae78dfe3fbf7ece25c170d7a152f88df7643381aa5e7344c2028a8d8d4", - "sha256:ead7b3e1567bd14cacd44279c5e42cd19f54b9feed39180220253f4fbe3abd56", - "sha256:ed772a5e8e7e5dd6bede960a86940c17cf653c7f158dafa5d52e919b676f10ba", - "sha256:f2d73131acb94afa45de8b6b8a4bfb21bbe3736633d6478e53247f19dd8c299c" "sha256:007ca0df127b1862fc010125bc4100b7a630efc6841047bd11afceadb4754611", "sha256:03c49e02adf0b4d68f422fdbd98f7a7c547beb27e99a75ed02298f85cb48406a", "sha256:0a1232cdd314e08848825edda06600455ad2a7adaa463ebfb12ece2d09f3370e", @@ -263,7 +235,6 @@ ], "index": "pypi", "version": "==2.3.1" - "version": "==2.8.1" }, "pytz": { "hashes": [ @@ -286,13 +257,6 @@ ], "version": "==12.5.0" }, - "uwsgi": { - "hashes": [ - "sha256:4972ac538800fb2d421027f49b4a1869b66048839507ccf0aa2fda792d99f583" - ], - "index": "pypi", - "version": "==2.0.18" - }, "webencodings": { "hashes": [ "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78", diff --git a/pydis_site/apps/home/tests.py b/pydis_site/apps/home/tests.py deleted file mode 100644 index 733ddaa3..00000000 --- a/pydis_site/apps/home/tests.py +++ /dev/null @@ -1,16 +0,0 @@ -from django.test import TestCase -from django_hosts.resolvers import reverse - -from pydis_site.apps.home.templatetags import extra_filters - - -class TestIndexReturns200(TestCase): - def test_index_returns_200(self): - url = reverse('home.index') - resp = self.client.get(url) - self.assertEqual(resp.status_code, 200) - - -class TestExtraFilterTemplateTags(TestCase): - def test_starts_with(self): - self.assertTrue(extra_filters.starts_with('foo', 'f')) diff --git a/pydis_site/apps/home/tests/test_app_basics.py b/pydis_site/apps/home/tests/test_app_basics.py new file mode 100644 index 00000000..733ddaa3 --- /dev/null +++ b/pydis_site/apps/home/tests/test_app_basics.py @@ -0,0 +1,16 @@ +from django.test import TestCase +from django_hosts.resolvers import reverse + +from pydis_site.apps.home.templatetags import extra_filters + + +class TestIndexReturns200(TestCase): + def test_index_returns_200(self): + url = reverse('home.index') + resp = self.client.get(url) + self.assertEqual(resp.status_code, 200) + + +class TestExtraFilterTemplateTags(TestCase): + def test_starts_with(self): + self.assertTrue(extra_filters.starts_with('foo', 'f')) -- cgit v1.2.3 From 383b3fd568b4b7ce0368e85854172e6f49860c15 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 20 Apr 2019 15:08:16 +0100 Subject: 100% coverage --- pydis_site/apps/home/tests/test_wiki_templatetags.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pydis_site/apps/home/tests') diff --git a/pydis_site/apps/home/tests/test_wiki_templatetags.py b/pydis_site/apps/home/tests/test_wiki_templatetags.py index 201d3df4..e1e2a02c 100644 --- a/pydis_site/apps/home/tests/test_wiki_templatetags.py +++ b/pydis_site/apps/home/tests/test_wiki_templatetags.py @@ -229,3 +229,10 @@ class TestGetFieldOptions(TestCase): context = Context({"field": field}) self.TEMPLATE.render(context) + + def test_get_field_options_value(self): + unbound_field = ChoiceField() + field = BoundField(Form(initial={"field": "Value"}), unbound_field, "field") + + context = Context({"field": field}) + self.TEMPLATE.render(context) -- cgit v1.2.3