| 1 | from django.contrib.auth.models import User |
| 2 | from django.template import Context |
| 3 | from django.template import Template |
| 4 | from django.test import TestCase |
| 5 | from django.test.utils import override_settings |
| 6 | |
| 7 | from organizations.models import Organization |
| 8 | |
| 9 | |
| 10 | @override_settings(USE_TZ=True) |
| 11 | class TestTagsAndFilters(TestCase): |
| 12 | |
| 13 | fixtures = ["users.json", "orgs.json"] |
| 14 | |
| 15 | def setUp(self): |
| 16 | self.kurt = User.objects.get(username="kurt") |
| 17 | self.dave = User.objects.get(username="dave") |
| 18 | self.nirvana = Organization.objects.get(name="Nirvana") |
| 19 | self.foo = Organization.objects.get(name="Foo Fighters") |
| 20 | self.context = {} |
| 21 | |
| 22 | def test_organization_users_tag(self): |
| 23 | self.context = {"organization": self.nirvana} |
| 24 | out = Template( |
| 25 | "{% load org_tags %}" "{% organization_users organization %}" |
| 26 | ).render(Context(self.context)) |
| 27 | self.assertIn("Kurt", out) |
| 28 | self.assertIn("Dave", out) |
| 29 | |
| 30 | def test_is_owner_org_filter(self): |
| 31 | self.context = {"organization": self.nirvana, "user": self.kurt} |
| 32 | out = Template( |
| 33 | "{% load org_tags %}" |
| 34 | "{% if organization|is_owner:user %}" |
| 35 | "Is Owner" |
| 36 | "{% endif %}" |
| 37 | ).render(Context(self.context)) |
| 38 | self.assertEqual(out, "Is Owner") |
| 39 | |
| 40 | def test_is_admin_org_filter(self): |
| 41 | self.context = {"organization": self.foo, "user": self.dave} |
| 42 | out = Template( |
| 43 | "{% load org_tags %}" |
| 44 | "{% if organization|is_admin:user %}" |
| 45 | "Is Admin" |
| 46 | "{% endif %}" |
| 47 | ).render(Context(self.context)) |
| 48 | self.assertEqual(out, "Is Admin") |
| 49 | |
| 50 | def test_is_not_admin_org_filter(self): |
| 51 | self.context = {"organization": self.nirvana, "user": self.dave} |
| 52 | out = Template( |
| 53 | "{% load org_tags %}" |
| 54 | "{% if not organization|is_admin:user %}" |
| 55 | "Is Not Admin" |
| 56 | "{% endif %}" |
| 57 | ).render(Context(self.context)) |
| 58 | self.assertEqual(out, "Is Not Admin") |