def test_unsuspend(app): admin_id = app.admin_id user = create_user('TemporaryNuisance') user_id = user.id user_command_service.suspend_account(user_id, admin_id, 'Annoying') reason = 'User showed penitence. Drop the ban.' user_before = user_service.find_user(user_id) assert user_before.suspended events_before = event_service.get_events_for_user(user_before.id) assert len(events_before) == 1 # -------------------------------- # user_command_service.unsuspend_account(user_id, admin_id, reason) # -------------------------------- # user_after = user_service.find_user(user_id) assert not user_after.suspended events_after = event_service.get_events_for_user(user_after.id) assert len(events_after) == 2 unsuspended_event = events_after[1] assert unsuspended_event.event_type == 'user-unsuspended' assert unsuspended_event.data == { 'initiator_id': str(admin_id), 'reason': reason, }
def test_suspend(app): admin_id = app.admin_id user = create_user('Cheater') user_id = user.id reason = 'User has been caught cheating.' user_before = user_service.find_user(user_id) assert not user_before.suspended events_before = event_service.get_events_for_user(user_before.id) assert len(events_before) == 0 # -------------------------------- # user_command_service.suspend_account(user_id, admin_id, reason) # -------------------------------- # user_after = user_service.find_user(user_id) assert user_after.suspended events_after = event_service.get_events_for_user(user_after.id) assert len(events_after) == 1 suspended_event = events_after[0] assert suspended_event.event_type == 'user-suspended' assert suspended_event.data == { 'initiator_id': str(admin_id), 'reason': reason, }
def test_unsuspend(self): user_command_service.suspend_account(self.user.id, ADMIN_ID, 'Annoying') reason = 'User showed penitence. Drop the ban.' user_before = user_service.find_user(self.user.id) assert user_before.suspended events_before = event_service.get_events_for_user(user_before.id) assert len(events_before) == 1 # -------------------------------- # user_command_service.unsuspend_account(self.user.id, ADMIN_ID, reason) # -------------------------------- # user_after = user_service.find_user(self.user.id) assert not user_after.suspended events_after = event_service.get_events_for_user(user_after.id) assert len(events_after) == 2 unsuspended_event = events_after[1] assert unsuspended_event.event_type == 'user-unsuspended' assert unsuspended_event.data == { 'initiator_id': str(ADMIN_ID), 'reason': reason, }
def test_suspend(self): reason = 'User has been caught cheating.' user_before = user_service.find_user(self.user.id) assert not user_before.suspended events_before = event_service.get_events_for_user(user_before.id) assert len(events_before) == 0 # -------------------------------- # user_command_service.suspend_account(self.user.id, ADMIN_ID, reason) # -------------------------------- # user_after = user_service.find_user(self.user.id) assert user_after.suspended events_after = event_service.get_events_for_user(user_after.id) assert len(events_after) == 1 suspended_event = events_after[0] assert suspended_event.event_type == 'user-suspended' assert suspended_event.data == { 'initiator_id': str(ADMIN_ID), 'reason': reason, }
def validate_user_id(ctx, param, user_id): user = user_service.find_user(user_id) if not user: raise click.BadParameter('Unknown user ID "{}".'.format(user_id)) return user
def validate_user_id(ctx, param, user_id: UserID) -> User: user = user_service.find_user(user_id) if not user: raise click.BadParameter(f'Unknown user ID "{user_id}".') return user
def validate_user_id(ctx, param, user_id: UserID) -> User: try: user_id = UUID(user_id) except ValueError as e: raise click.BadParameter(f'Invalid user ID "{user_id}": {e}') user = user_service.find_user(user_id) if not user: raise click.BadParameter(f'Unknown user ID "{user_id}".') return user