Skip to content

Conversation

@codehobbyist06
Copy link
Contributor

plugins/ban.py: Update to handle new cases

Updates ban.py handling some more cases

tests/ban_test.py: Add new mocks

Adds new mocks to get 100% test coverage
for ban.py

setup.cfg: Remove ban.py from omit

Removes ban.py from the omit section

Fixes #610

Reviewers Checklist

  • Appropriate logging is done.
  • Appropriate error responses.
  • Handle every possible exception.
  • Make sure there is a docstring in the command functions. Hint: Lookout for
    botcmd and re_botcmd decorators.
  • See that 100% coverage is there.
  • See to it that mocking is not done where it is not necessary.

plugins/ban.py: Update to handle new cases

Updates ban.py handling some more cases

tests/ban_test.py: Add new mocks

Adds new mocks to get 100% test coverage
for ban.py

setup.cfg: Remove ban.py from omit

Removes ban.py from the omit section

Fixes coala#610
Copy link
Member

@nakuldx nakuldx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, just few changes mentioned below :)

Also, the issue is not a bug, so ideally this PR should Close the issue and not Fix.

sinner = sinner[1:]

joined_rooms = self.bot_config.ROOMS_TO_JOIN
self.log.info(joined_rooms)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is required.


r = requests.get('https://api.gitter.im/v1/rooms', headers=headers)
room_data = json.loads(r.text)
self.log.info(room_data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, I don't think this is required.

if room is not None:
url = 'https://api.gitter.im/v1/rooms/' + \
room['id'] + '/bans'
if room_data == []:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if room_data == []:
if not room_data:

url = 'https://api.gitter.im/v1/rooms/' + \
room['id'] + '/bans'
if room_data == []:
yield 'No rooms found:('
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
yield 'No rooms found:('
yield 'No rooms found :('

Comment on lines +44 to +45
self.log.info(rq.status_code)
self.log.info(rq.json())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to log everything. Also, looking at this will not be obvious to where the log came from. The log ideally should have all the information required to pin point itself to the source.

else:
self.log.info('Error ' + str(rq.status_code))
yield 'Error ' + str(rq.status_code) + \
': Something went wrong:( Pls try again!'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
': Something went wrong:( Pls try again!'
': Something went wrong. Please try again.'

banned_rooms.append(room['uri'])
else:
self.log.info('Error ' + str(rq.status_code))
yield 'Error ' + str(rq.status_code) + \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a rule, we don't use \. The alternative is to use parenthesis.

Comment on lines +89 to +92
else:
self.log.info('Error ' + str(rq.status_code))
yield 'Error ' + str(rq.status_code) + \
': Something went wrong:( Pls try again!'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add changes as mentioned above, not repeating them here to keep it simple.

': Something went wrong:( Pls try again!'

yield sinner + ' has been unbanned from: ' + ', '.join(unbanned_rooms)
yield sinner + ' has been unbanned from: ' + \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, avoid using \.

with testbot.assertLogs() as cm:
testbot.assertCommand('!ban @nvzard',
'Error 403: '
'Something went wrong:( Pls try again!')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust the tests accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ban command needs 100% branch test coverage

2 participants