aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers.py (unfollow)
Commit message (Collapse)AuthorLines
2020-08-18Silence tests: more accurately assert the silence cmd schedule a taskGravatar MarkKoz-3/+7
2020-08-18Silence tests: add a test for rescheduling active silencesGravatar MarkKoz-0/+29
2020-08-18Silence tests: test the rescheduler unsilences expired silencesGravatar MarkKoz-0/+14
2020-08-18Silence tests: test the rescheduler adds permanent silence to notifierGravatar MarkKoz-0/+14
2020-08-18Silence tests: test the scheduler skips missing channelsGravatar MarkKoz-0/+25
2020-08-18Silence tests: add a test for _init_cog rescheduling unsilencesGravatar MarkKoz-0/+7
2020-08-18Silence tests: remove _reschedule patch for cog testsGravatar MarkKoz-4/+0
They don't do anything because they patch the class rather than the instance. It's too late for patching the instance to work since the `setUp` fixture, which instantiates the cog, executes before the patches do. Patching `setUp` would work (and its done in the other test cases), but some tests in this case will need the unpatched function too. Patching it doesn't serve much benefit to most tests anyway, so it's not worth the effort trying to make them work where they aren't needed.
2020-08-18Silence tests: access everything via the silence moduleGravatar MarkKoz-24/+23
The module is imported anyway to keep imports short and clean. Using it in patch targets is shorter and allows for the two imports from the module to be removed.
2020-08-17Silence tests: add a subtest for the manual unsilence messageGravatar MarkKoz-4/+7
2020-08-17Silence tests: assert against message constantsGravatar MarkKoz-15/+24
Duplicating strings in assertions is redundant, closely coupled, and less maintainable.
2020-08-17Silence tests: also test that cache misses preserve other overwritesGravatar MarkKoz-12/+16
2020-08-17Silence tests: add a test for a mod alert on cache missGravatar MarkKoz-0/+7
2020-08-17Silence tests: add a test for default overwrites on cache missGravatar MarkKoz-4/+19
Use a False for `add_reactions` in the mock overwrite rather than None to be sure the default (also None) is actually set for it. Fix channels set by `_init_cog` not being mocked properly.
2020-08-17Silence tests: add a test for task cancellationGravatar MarkKoz-0/+5
2020-08-17Silence tests: add a test for deletion from the time cacheGravatar MarkKoz-0/+5
2020-08-17Silence tests: add tests for scheduling tasksGravatar MarkKoz-0/+12
2020-08-17Silence tests: add a test for caching permanent timesGravatar MarkKoz-0/+6
2020-08-17Silence tests: add a test for the time cacheGravatar MarkKoz-0/+15
2020-08-17Silence tests: fix mock for _init_taskGravatar MarkKoz-2/+4
An `AsyncMock` fails because it returns a coroutine which may only be awaited once. However, an `asyncio.Future` is perfect because it is easy to create and can be awaited repeatedly, just like the actual `asyncio.Task` that is being mocked.
2020-08-17Silence tests: create channel and overwrite in setUp for silence testsGravatar MarkKoz-29/+17
Reduce code redundancy by only defining them once.
2020-08-17Silence tests: merge unsilence fixture into setUpGravatar MarkKoz-32/+20
Now that there are separate test cases, there's no need to keep the fixtures separate.
2020-08-17Silence tests: autospec _reschedule and SilenceNotifier for cog testsGravatar MarkKoz-4/+10
2020-08-17Silence tests: separate test cases; refactor names & docstringsGravatar MarkKoz-71/+95
2020-08-17Silence tests: fix tests for _unsilenceGravatar MarkKoz-30/+45
Add a fixture to set up mocks for a successful `unsilence` call. This reduces code redundancy.
2020-08-17Silence tests: fix test_unsilence_private_removed_notifierGravatar MarkKoz-2/+5
2020-08-17Silence tests: fix overwrite preservation test for silencesGravatar MarkKoz-11/+15
2020-08-17Silence tests: fix command message testsGravatar MarkKoz-15/+10
2020-08-17Silence tests: fix test_silence_private_for_falseGravatar MarkKoz-4/+13
2020-08-17Silence tests: fix test_silence_private_silenced_channelGravatar MarkKoz-3/+10
2020-08-17Silence tests: fix test_silence_private_notifierGravatar MarkKoz-0/+3
2020-08-17Silence tests: fix test_unsilence_private_for_falseGravatar MarkKoz-1/+4
2020-08-17Silence tests: fix silence cache test for overwritesGravatar MarkKoz-5/+8
2020-08-17Silence tests: replace obsolete cog_unload testsGravatar MarkKoz-13/+4
Moderation notifications are no longer sent so that doesn't need to be tested.
2020-08-17Silence tests: rename test_instance_vars to test_init_cogGravatar MarkKoz-5/+5
2020-08-17Silence tests: mock RedisCachesGravatar MarkKoz-3/+2
2020-08-17Tests: optionally prevent autospec helper from passing mocksGravatar MarkKoz-19/+66
Not everything that's decorated needs the mocks that are patched. Being required to add the args to the test function anyway is annoying. It's especially bad if trying to decorate an entire test suite, as every test would need the args. Move the definition to a separate module to keep things cleaner.
2020-08-16Silence: rename _get_instance_vars to _init_cogGravatar MarkKoz-9/+9
It's a more accurate name since it also reschedules unsilences now.
2020-08-16Silence: remove event and await _get_instance_vars_task directlyGravatar MarkKoz-6/+2
The event is redundant because the task can be awaited directly to block until it's complete. If the task is already done, the await will instantly finish.
2020-08-16Silence: use aware datetimesGravatar MarkKoz-5/+6
`datetime.timestamp()` assumes naïve `datetime`s are in local time, so getting POSIX timestamps in UTC isn't easy for naïve ones. Technically, the timestamp's timezone doesn't matter if all code is on the same page and parsing it with the same timezone. Keeping it in the local timezone would be okay then, but I feel safer locking it to UTC explicitly.
2020-08-16Silence: reschedule silences on startupGravatar MarkKoz-10/+32
Remove the moderator notification when unloading the cog because. Its purpose was to remind to manually unsilence channels. However, this purpose is now obsolete due to automatic rescheduling. The notification was buggy anyway due to a race condition with the bot shutting down, and that'd be further complicated by having to asynchronously retrieve channels from the redis cache too. Fixes #1053
2020-08-16Silence: persist silenced channelsGravatar MarkKoz-0/+11
Can be used to support rescheduling.
2020-08-15Silence: add separate unsilence error for manually-silenced channelsGravatar MarkKoz-1/+9
It was confusing to reject a silence and an unsilence when overwrites were manually set to False. That's because it's contradictory to show an error stating it's already silence but then reject an unsilence with an error stating the channel isn't silenced.
2020-08-15Silence: notify admins if previous overwrites were not cachedGravatar MarkKoz-12/+25
Admins will have to manually check the default values used and adjust them if they aren't the desired values for that particular channel.
2020-08-15Silence: abort silence if there's already a scheduled taskGravatar MarkKoz-1/+1
Overwrites can be edited during a silence, which can result in the overwrites check failing. Checking the scheduler too ensures that a duplicate silence won't be scheduled.
2020-08-15Silence: revoke permissions to add reactionsGravatar MarkKoz-11/+27
No longer assume default values for the overwrites which are modified. Save and restore previous values `add_reactions` and `send_messages` via redis. When unsilencing, check if a channel is silenced via the redis cache rather than the channel's current overwrites to ensure the task is cancelled even if overwrites were manually edited.
2020-08-13Fix typo on the traceback tagGravatar AtieP-1/+1
See issue #1101