Skip to content

Commit

Permalink
Rename a method to be more greppable
Browse files Browse the repository at this point in the history
  • Loading branch information
seanh committed Nov 26, 2024
1 parent 60f1f9c commit 354286a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions h/services/group_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, db, user_fetcher, publish):
self.user_fetcher = user_fetcher
self.publish = publish

def get(self, group, user) -> GroupMembership | None:
def get_membership(self, group, user) -> GroupMembership | None:
"""Return `user`'s existing membership in `group`, if any."""
return self.db.scalar(
select(GroupMembership)
Expand Down Expand Up @@ -71,7 +71,7 @@ def member_join(self, group, userid):
"""Add `userid` to the member list of `group`."""
user = self.user_fetcher(userid)

existing_membership = self.get(group, user)
existing_membership = self.get_membership(group, user)

if existing_membership:
# The user is already a member of the group.
Expand All @@ -90,7 +90,7 @@ def member_leave(self, group, userid):
"""Remove `userid` from the member list of `group`."""
user = self.user_fetcher(userid)

membership = self.get(group, user)
membership = self.get_membership(group, user)

if not membership:
return
Expand Down
2 changes: 1 addition & 1 deletion h/traversal/group_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_user() -> User | None:
if not group:
raise HTTPNotFound(f"Group not found: {pubid}")

membership = group_members_service.get(group, user)
membership = group_members_service.get_membership(group, user)

if not membership and request.method != "POST":
raise HTTPNotFound(f"Membership not found: ({pubid}, {userid})")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/h/services/group_members_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from h.services.group_members import GroupMembersService, group_members_factory


class TestGet:
class TestGetMembership:
def test_it(self, group_members_service, factories, db_session):
group = factories.Group.build()
user = factories.User.build()
membership = GroupMembership(group=group, user=user)
db_session.add(membership)

result = group_members_service.get(group, user)
result = group_members_service.get_membership(group, user)

assert result == membership

Expand All @@ -25,7 +25,7 @@ def test_it_when_theres_no_matching_membership(
group = factories.Group()
user = factories.User()

result = group_members_service.get(group, user)
result = group_members_service.get_membership(group, user)

assert result is None

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/h/traversal/group_membership_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def test_it(

group_service.fetch.assert_called_once_with(sentinel.pubid)
user_service.fetch.assert_called_once_with(sentinel.userid)
group_members_service.get.assert_called_once_with(
group_members_service.get_membership.assert_called_once_with(
group_service.fetch.return_value, user_service.fetch.return_value
)
assert isinstance(context, GroupMembershipContext)
assert context.group == group_service.fetch.return_value
assert context.user == user_service.fetch.return_value
assert context.membership == group_members_service.get.return_value
assert context.membership == group_members_service.get_membership.return_value

def test_when_no_matching_group(self, group_service, pyramid_request):
group_service.fetch.return_value = None
Expand All @@ -47,7 +47,7 @@ def test_when_invalid_userid(self, user_service, pyramid_request):
group_membership_api_factory(pyramid_request)

def test_when_no_matching_membership(self, group_members_service, pyramid_request):
group_members_service.get.return_value = None
group_members_service.get_membership.return_value = None

with pytest.raises(
HTTPNotFound,
Expand Down

0 comments on commit 354286a

Please sign in to comment.