Skip to content

Commit

Permalink
Switched to using equality for role comparison checks. (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
carltongibson authored Nov 19, 2024
1 parent 5468ac0 commit 80090e5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Version numbers correspond to git tags. Please use the compare view on GitHub
for full details. Until we're further along, I will just note the highlights
here:

24.8
====

* Switched to using equality for role comparison checks.

This is an internal change, preparatory for future work.

24.7
====

Expand Down
2 changes: 1 addition & 1 deletion src/neapolitan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ class BookmarkView(CRUDView):
Let's go! 🚀
"""

__version__ = "24.7"
__version__ = "24.8"
6 changes: 3 additions & 3 deletions src/neapolitan/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def detail(self, request, *args, **kwargs):
def show_form(self, request, *args, **kwargs):
"""GET handler for the create and update form views."""

if self.role is Role.UPDATE:
if self.role == Role.UPDATE:
self.object = self.get_object()
form = self.get_form(instance=self.object)
context = self.get_context_data(form=form)
Expand All @@ -194,7 +194,7 @@ def show_form(self, request, *args, **kwargs):
def process_form(self, request, *args, **kwargs):
"""POST handler for the create and update form views."""

if self.role is Role.UPDATE:
if self.role == Role.UPDATE:
self.object = self.get_object()
form = self.get_form(
data=request.POST,
Expand Down Expand Up @@ -295,7 +295,7 @@ def get_success_url(self):
"'%s' must define 'model' or override 'get_success_url()'"
% self.__class__.__name__
)
if self.role is Role.DELETE:
if self.role == Role.DELETE:
success_url = reverse(f"{self.url_base}-list")
else:
success_url = reverse(
Expand Down
20 changes: 19 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_rendering_list_only_role(self):

for lookup in ['View', 'Edit', 'Delete']:
self.assertNotContains(response, f'>{lookup}</a>')

def test_url_ordering_for_slug_path_converters(self):
# Ensures correct ordering of URL patterns when using str-based path converters
# https://github.com/carltongibson/neapolitan/issues/64
Expand All @@ -301,6 +301,24 @@ class BookmarkCRUDView(CRUDView):
# Assert that the generated URL paths match the expected order
self.assertEqual(url_paths, expected_paths)

def test_role_equality(self):
"""
Role instances should be equal to themselves but not to other Role
instances.
Follows directly from Enum base class, but is preparatory to custom
roles.
"""
# Basic examples:
self.assertEqual(Role.LIST, Role.LIST)
self.assertNotEqual(Role.LIST, Role.DETAIL)

# Exhaustive check:
for role in Role:
self.assertEqual(role, role)
for other_role in (r for r in Role if r != role):
self.assertNotEqual(role, other_role)


class MktemplateCommandTest(TestCase):
def test_mktemplate_command(self):
Expand Down

0 comments on commit 80090e5

Please sign in to comment.