Fix ban_test to have 100% coverage#669
Open
codehobbyist06 wants to merge 1 commit intocoala:masterfrom
Open
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
nakuldx
suggested changes
Jun 13, 2021
| sinner = sinner[1:] | ||
|
|
||
| joined_rooms = self.bot_config.ROOMS_TO_JOIN | ||
| self.log.info(joined_rooms) |
Member
There was a problem hiding this comment.
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) |
Member
There was a problem hiding this comment.
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 == []: |
Member
There was a problem hiding this comment.
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:(' |
Member
There was a problem hiding this comment.
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()) |
Member
There was a problem hiding this comment.
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!' |
Member
There was a problem hiding this comment.
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) + \ |
Member
There was a problem hiding this comment.
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!' |
Member
There was a problem hiding this comment.
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: ' + \ |
| with testbot.assertLogs() as cm: | ||
| testbot.assertCommand('!ban @nvzard', | ||
| 'Error 403: ' | ||
| 'Something went wrong:( Pls try again!') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
botcmdandre_botcmddecorators.