From 020854c3d0eb42edfdb2d231577e500424d8f397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20M=C3=A9ndez?= Date: Mon, 5 Feb 2024 18:30:59 -0600 Subject: [PATCH 1/3] Removed no longer used test_utils folder + files --- generic_links/test_utils/__init__.py | 0 generic_links/test_utils/test_app/__init__.py | 0 generic_links/test_utils/test_app/admin.py | 2 -- generic_links/test_utils/test_app/apps.py | 7 ------- generic_links/test_utils/test_app/migrations/__init__.py | 0 generic_links/test_utils/test_app/models.py | 2 -- 6 files changed, 11 deletions(-) delete mode 100644 generic_links/test_utils/__init__.py delete mode 100644 generic_links/test_utils/test_app/__init__.py delete mode 100644 generic_links/test_utils/test_app/admin.py delete mode 100644 generic_links/test_utils/test_app/apps.py delete mode 100644 generic_links/test_utils/test_app/migrations/__init__.py delete mode 100644 generic_links/test_utils/test_app/models.py diff --git a/generic_links/test_utils/__init__.py b/generic_links/test_utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/generic_links/test_utils/test_app/__init__.py b/generic_links/test_utils/test_app/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/generic_links/test_utils/test_app/admin.py b/generic_links/test_utils/test_app/admin.py deleted file mode 100644 index 0ee0dba..0000000 --- a/generic_links/test_utils/test_app/admin.py +++ /dev/null @@ -1,2 +0,0 @@ -# Put your models admin models here -from __future__ import annotations diff --git a/generic_links/test_utils/test_app/apps.py b/generic_links/test_utils/test_app/apps.py deleted file mode 100644 index acd4058..0000000 --- a/generic_links/test_utils/test_app/apps.py +++ /dev/null @@ -1,7 +0,0 @@ -from __future__ import annotations - -from django.apps import AppConfig - - -class TestAppConfig(AppConfig): - name = "test_app" diff --git a/generic_links/test_utils/test_app/migrations/__init__.py b/generic_links/test_utils/test_app/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/generic_links/test_utils/test_app/models.py b/generic_links/test_utils/test_app/models.py deleted file mode 100644 index c47adaa..0000000 --- a/generic_links/test_utils/test_app/models.py +++ /dev/null @@ -1,2 +0,0 @@ -# Put your test models here -from __future__ import annotations From f034899517e3c3b7afa3d8d5837d732cf25ce724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20M=C3=A9ndez?= Date: Mon, 5 Feb 2024 18:47:12 -0600 Subject: [PATCH 2/3] Added some dev dependencies to default environment --- pyproject.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index e27a808..df3e5e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,12 @@ include = [ "generic_links/", ] +[tool.hatch.envs.default] +dependencies = [ + "Django>=4.0", "ipython", "ipdb", "mypy", "typing-extensions", +] + + # Test environment [[tool.hatch.envs.test.matrix]] python = ["3.9", "3.10", "3.11"] From 86f88650f8428b32944a28407d5386da696cdad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20M=C3=A9ndez?= Date: Mon, 5 Feb 2024 19:47:28 -0600 Subject: [PATCH 3/3] Added test case for template tag get_links_for --- tests/test_templatetags.py | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/test_templatetags.py diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py new file mode 100644 index 0000000..03cb81f --- /dev/null +++ b/tests/test_templatetags.py @@ -0,0 +1,63 @@ +from django.contrib.auth.models import User +from django.contrib.contenttypes.models import ContentType +from django.template import Context +from django.template import Template +from django.test import TestCase + +from generic_links.models import GenericLink + + +class TemplateTagTestCase(TestCase): + """ + Test case for the template tag `get_links_for ` in the `generic_links_tags.py` file. + """ + + def setUp(self): + content_type = ContentType.objects.get_for_model(User) + + self.user1 = User.objects.create(username="test_user") + + self.link1 = GenericLink.objects.create( + url="https://example.com/path/to/this-thing/", + content_type=content_type, + object_id=self.user1.id, + ) + + self.link2 = GenericLink.objects.create( + url="https://example.com/path/to/other-thing/", + content_type=content_type, + object_id=self.user1.id, + ) + + self.user2 = User.objects.create(username="test_user2") + + self.link3 = GenericLink.objects.create( + url="https://example.com/foobar/", + content_type=content_type, + object_id=self.user2.id, + ) + + def test_get_links_for(self): + """ + Test the `get_links_for` template tag. + """ + + template_string = """ + {% load generic_links_tags %} + {% get_links_for my_obj as links_qs %} + {% for link in links_qs %} + {{ link.url }} + {% endfor %} + """ + + template = Template(template_string) + + rendered_string = template.render(Context({"my_obj": self.user1})) + + self.assertIn(self.link1.url, rendered_string) + self.assertIn(self.link2.url, rendered_string) + self.assertNotIn(self.link3.url, rendered_string) + + rendered_string2 = template.render(Context({"my_obj": self.user2})) + + self.assertEqual(self.link3.url, rendered_string2.strip())