-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ban_test to have 100% coverage #669
base: master
Are you sure you want to change the base?
Conversation
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
There was a problem hiding this 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
.
@@ -22,6 +21,7 @@ def ban(self, msg, args): | |||
sinner = sinner[1:] | |||
|
|||
joined_rooms = self.bot_config.ROOMS_TO_JOIN | |||
self.log.info(joined_rooms) |
There was a problem hiding this comment.
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.
@@ -31,18 +31,27 @@ def ban(self, msg, args): | |||
|
|||
r = requests.get('https://api.gitter.im/v1/rooms', headers=headers) | |||
room_data = json.loads(r.text) | |||
self.log.info(room_data) |
There was a problem hiding this comment.
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 == []: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if room_data == []: | |
if not room_data: |
url = 'https://api.gitter.im/v1/rooms/' + \ | ||
room['id'] + '/bans' | ||
if room_data == []: | ||
yield 'No rooms found:(' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yield 'No rooms found:(' | |
yield 'No rooms found :(' |
self.log.info(rq.status_code) | ||
self.log.info(rq.json()) |
There was a problem hiding this comment.
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!' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
': Something went wrong:( Pls try again!' | |
': Something went wrong. Please try again.' |
if rq.status_code == 200: | ||
banned_rooms.append(room['uri']) | ||
else: | ||
self.log.info('Error ' + str(rq.status_code)) | ||
yield 'Error ' + str(rq.status_code) + \ |
There was a problem hiding this comment.
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.
else: | ||
self.log.info('Error ' + str(rq.status_code)) | ||
yield 'Error ' + str(rq.status_code) + \ | ||
': Something went wrong:( Pls try again!' |
There was a problem hiding this comment.
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.
|
||
yield sinner + ' has been unbanned from: ' + ', '.join(unbanned_rooms) | ||
yield sinner + ' has been unbanned from: ' + \ |
There was a problem hiding this comment.
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!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjust the tests accordingly.
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
botcmd
andre_botcmd
decorators.