Skip to content

Commit

Permalink
ticket 541: better python specing == 3.11, better block testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Philion committed Mar 15, 2024
1 parent 2bf86ba commit 8ea5f90
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cog_scn.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async def unblock(self, ctx:discord.ApplicationContext, username:str):
log.debug(f"unblocking {username}")
user = self.redmine.user_mgr.find(username)
if user:
self.redmine.unblock_user(user)
self.redmine.user_mgr.unblock(user)
await ctx.respond(f"Unblocked user: {user.login}")
else:
log.debug("trying to unblock unknown user '{username}', ignoring")
Expand Down
14 changes: 13 additions & 1 deletion test_cog_scn.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ async def test_block_user(self):
# call block
ctx = self.build_context()
await self.cog.block(ctx, self.user.login)
self.redmine.user_mgr.reindex_teams()

# confirmed blocked
self.assertTrue(self.redmine.user_mgr.is_blocked(self.user))
Expand All @@ -122,6 +121,19 @@ async def test_block_user(self):
self.redmine.remove_ticket(ticket.id)


async def test_unblock_user(self):
# call block
ctx = self.build_context()
await self.cog.block(ctx, self.user.login)

# confirmed blocked
self.assertTrue(self.redmine.user_mgr.is_blocked(self.user))

# unblock
await self.cog.unblock(ctx, self.user.login)
self.assertFalse(self.redmine.user_mgr.is_blocked(self.user))


async def test_locked_during_sync_ticket(self):
"""
Unhandled exception in internal background task 'sync_all_threads'.
Expand Down
1 change: 1 addition & 0 deletions test_redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_blocked_create_ticket(self):
# create ticket for blocked
ticket = self.create_test_ticket()
self.assertIsNotNone(ticket)
log.info(f"ticket: {ticket}")
self.assertEqual("Reject", ticket.status.name)

# remove the ticket and unbluck the user
Expand Down
2 changes: 1 addition & 1 deletion tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def create(self, user: User, message: Message) -> Ticket:
"content_type": a.content_type,
})

log.debug(f"### data: {data}")
#log.debug(f"POST data: {data}")
response = self.session.post(ISSUES_RESOURCE, json.dumps(data), user.login)

# check status
Expand Down
18 changes: 11 additions & 7 deletions users.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,11 @@ def is_user_in_team(self, user: User, teamname:str) -> bool:
return False

team = self.get_team_by_name(teamname)
return self.is_user_in(user, team)

if team:

def is_user_in(self, user: User, team:Team) -> bool:
if user and team:
for team_user in team.users:
if team_user.id == user.id:
return True
Expand Down Expand Up @@ -456,16 +459,17 @@ def unblock(self, user) -> None:


def join_team(self, user: User, teamname:str) -> None:
# look up user ID
#user = self.find_user(username)
#if user is None:
# raise RedmineException(f"Unknown user name: {username}", "[n/a]")

# map teamname to team
team = self.get_team_by_name(teamname)
if team.id is None:
if team is None:
raise RedmineException(f"Unknown team name: {teamname}", "[n/a]")

# calling POST when the user is already in the team results in a
# 422 Unprocessable Entity error, so checking first.
# Expected behavior is idempotent: if already in the team, return as expected (no exception)
if self.is_user_in(user, team):
return # already done

# POST to /group/ID/users.json
data = {
"user_id": user.id
Expand Down

0 comments on commit 8ea5f90

Please sign in to comment.