aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers.py (unfollow)
Commit message (Collapse)AuthorLines
2020-02-23Sync: code style refactoringGravatar MarkKoz-7/+10
* Convert diff namedtuple to dict outside the dict comprehension * Define long condition as a boolean instead of in the if statement * Pass role and user dicts to aiohttp normally instead of unpacking
2020-02-24Make Azure CI use Python 3.8 and Ubuntu 18.04Gravatar Sebastiaan Zeeff-2/+2
Since the bot is now using Python 3.8 and some of our dependencies have Python-version specfic dependencies, it's important that the CI, which installs from our Pipfile, uses the same version of Python.
2020-02-23Fix test_time test and ensure coverageGravatar Sebastiaan Zeeff-4/+4
One of the test_time methods did not actually assert the exception message it was trying to detect as the assertion statement was contained within the context manager handling the exception. I've moved it out of the context so it actually runs. I've also added a few `praga: no cover` comments for parts that were artifically lowering coverage of the test suite.
2020-02-23Use unittest's AsyncMock instead of our AsyncMockGravatar Sebastiaan Zeeff-213/+103
Python 3.8 introduced an `unittest.mock.AsyncMock` class that can be used to mock coroutines and other types of asynchronous operations like async iterators and async context managers. As we were using our custom, but limited, AsyncMock, I have replaced our mock with unittest's AsyncMock. Since Python 3.8 also introduces a different way of automatically detecting which attributes should be mocked with an AsyncMock, I've changed our CustomMockMixin to use this new method as well. Together with a couple other small changes, this means that our Custom Mocks now use a lazy method of detecting coroutine attributes, which significantly speeds up the test suite.
2020-02-23Remove lingering pytest test_time.py fileGravatar Sebastiaan Zeeff-62/+0
I forgot to remove one pytest test file during the migration from pytest to unittest. Since we have sinced added a unittest version of the same file, I've now removed the lingering pytest file.
2020-02-23Use IsolatedAsyncioTestCase instead of async_testGravatar Sebastiaan Zeeff-70/+13
Since we upgraded to Python 3.8, we can now use the new IsolatedAsyncioTestCase test class to use coroutine-based test methods instead of our own, custom async_test decorator. I have changed the base class for all of our test classes that use coroutine-based test methods and removed the now obsolete decorator from our helpers.
2020-02-23Use mixin-composition not inheritance for LoggingTestCaseGravatar Sebastiaan Zeeff-16/+14
We used inheritence to add additional logging assertion methods to unittest's TestCase class. However, with the introduction of the new IsolatedAsyncioTestCase this extension strategy means we'd have to create multiple child classes to be able to use the extended functionality in all of the TestCase variants. Since that leads to undesirable code reuse and an inheritance relationship is not at all needed, I've switched to a mixin-composition based approach that allows the user to extend the functionality of any TestCase variant with a mixin where needed.
2020-02-23Update to Python 3.8 and discord.py 1.3.2Gravatar Sebastiaan Zeeff-79/+37
I've changed the Python version in our Pipfile to Python 3.8. The main advantage of Python 3.8 is that it comes with significant upgrades to the unittest module which allow us to test asyncio-based code more easily. While our current test suite runs in P3.8 "out of the box", it currently still relies on many of the workarounds we had to use to test asynchronous code in Python 3.7. A future commit will replace these workarounds with the new tools available in Python 3.8. This commit also updates our discord.py version to 1.3.2. Versions of discord.py <= 1.3.1 contain a bug that causes errors in the new unittest tools that come with Python 3.8. For more specific details, see https://github.com/Rapptz/discord.py/pull/2570.
2020-02-23Add Sentdex server to whitelistGravatar Leon Sandøy-0/+1
2020-02-24Change verification post log level to info, tidy code.Gravatar scragly-14/+13
2020-02-24Reduce log level of tag cooldown notice.Gravatar scragly-2/+4
2020-02-23Remove call to delete reminder, as ensure method already does it.Gravatar scragly-1/+0
2020-02-23Check reminder user and channel before send and schedule.Gravatar scragly-17/+38
2020-02-23Don't log exception traceback on Forbidden for welcomes.Gravatar scragly-12/+9
2020-02-23Don't set project log level so it uses root level.Gravatar scragly-1/+1
2020-02-23Define `_count` in `__init__`.Gravatar scragly-0/+1
2020-02-23Suppress NotFound on react clear, tidy imports.Gravatar scragly-18/+21
2020-02-21Change defcon log levels from warning to infoGravatar Joseph Banks-2/+2
2020-02-21Enable logging warnings to SentryGravatar Joseph Banks-3/+12
2020-02-21Bot: send empty cache warning to a webhookGravatar MarkKoz-3/+12
This is more visible than it would be if it was only logged. * Add a webhook for the dev-log channel to constants
2020-02-21Attach jump_to url to the eventGravatar Joseph Banks-0/+8
2020-02-21Use push_scope instead of configure_scopeGravatar Joseph Banks-2/+2
2020-02-21Use log.error instead of capture_exceptionGravatar Joseph Banks-2/+2
2020-02-21Remove AIOHTTP integration from Sentry since it is intended for AIOHTTP servers.Gravatar Joseph Banks-3/+1
2020-02-21Remove tests for custom bot logGravatar Joseph Banks-62/+2
2020-02-21Remove the space that makes the test failGravatar Deniz-1/+1
2020-02-21Use the code provided by sco1 to fix the checks failing.Gravatar Deniz-5/+10
2020-02-21Add basic sentry usage for command errors giving user information and ↵Gravatar Joseph Banks-85/+10
command context.
2020-02-21Attach extra information on a command errorGravatar Joseph Banks-1/+13
2020-02-21Set BOT_SENTRY_DSN environment variable for testsGravatar Joseph Banks-1/+1
2020-02-21Implement basic Sentry SDK usageGravatar Joseph Banks-2/+14
2020-02-20Update flake8-annotations to v2.0.Gravatar scragly-10/+51
2020-02-20Change to explicit logs, remove logmatic.Gravatar scragly-160/+76
2020-02-19API: add comment explaining class attributesGravatar MarkKoz-0/+2
Explain changes caused by 22a55534ef13990815a6f69d361e2a12693075d5.
2020-02-19Sync: add confirmation timeout and max diff to configGravatar MarkKoz-16/+24
2020-02-19Moderation: show avatar in infraction deactivation logGravatar MarkKoz-0/+5
2020-02-17Pagination migrations - Emoji Data Structure ModifiedGravatar F4zi-1/+1
Changed the pagination emoji collection from list to tuple This change was suggested since this collection is constant
2020-02-17Change snekbox api url to internal docker domain.Gravatar scragly-1/+1
NGINX has been dockerised, and proxy passes now reference internal container domains rather than referencing host or external domains. This will have a few extra benefits: - Less external factors involved for resolving the service address - Can work with the same address on development envs - Snekbox can be closed down entirely so it's inaccessible from external networks.
2020-02-16Fix missing Django logs when using Docker ComposeGravatar MarkKoz-0/+2
Fixed by allocating a pseudo-tty to the web and bot services in Docker Compose.
2020-02-15Moderation: show member as a mention in expired infraction logGravatar MarkKoz-1/+1
2020-02-15Moderation: show correct actor in expired infraction logGravatar MarkKoz-3/+4
The bot user was always being used instead of using the actor field of the infraction.
2020-02-15Moderation: add creation date & duration to expired infraction logGravatar MarkKoz-1/+7
Closes #685
2020-02-15Utils: refactor format_infraction_with_duration and support absolute valGravatar MarkKoz-13/+23
The absolute value is useful for preventing negative values in the case that date_to is in the past relative to date_from. * Add an absolute parameter to take the absolute value of the duration * Rename expiry to date_to * Rewrite the docstring
2020-02-15Add missed signature reformat from reviewGravatar S. Co1-1/+4
Co-Authored-By: Mark <[email protected]>
2020-02-15Add "cancel" as a reminder delete aliasGravatar S. Co1-1/+1
2020-02-15Add full capture of reason string to superstarify invocationGravatar S. Co1-1/+2
2020-02-15Styling & refactors from reviewGravatar S. Co1-17/+29
* Refactor confirmation embed footer string generation to be more concise * Multiline long method calls * Refactor humanized delta f string generation for readability * Switch from `datetime.isoformat` to `dateutils.parser.isoparse` to align with changes elsewhere in the codebase (should be more robust) * Shift reminder channel whitelist to constants Co-Authored-By: Mark <[email protected]>
2020-02-14Stop scheduling expiration of permanent infractions on editGravatar Sebastiaan Zeeff-2/+5
https://github.com/python-discord/bot/issues/751 The infraction edit command defined in `bot.cogs.moderation.management` contained a bug causing it to attempt to schedule an expiration task when turning a temporary infraction into a permanent infraction. Since the "expires_at" field of a permanent infractions is `None`, this caused an exception to occur in the scheduler: Traceback (most recent call last): File "/bot/bot/cogs/moderation/scheduler.py", line 415, in _scheduled_task expiry = dateutil.parser.isoparse(infraction["expires_at"]).replace(tzinfo=None) File "/usr/local/lib/python3.7/site-packages/dateutil/parser/isoparser.py", line 37, in func return f(self, str_in, *args, **kwargs) File "/usr/local/lib/python3.7/site-packages/dateutil/parser/isoparser.py", line 134, in isoparse components, pos = self._parse_isodate(dt_str) File "/usr/local/lib/python3.7/site-packages/dateutil/parser/isoparser.py", line 208, in _parse_isodate return self._parse_isodate_common(dt_str) File "/usr/local/lib/python3.7/site-packages/dateutil/parser/isoparser.py", line 213, in _parse_isodate_common len_str = len(dt_str) TypeError: object of type 'NoneType' has no len() I have solved this by adding a check that makes sure we only schedule an expiration task when the `"expires_at"` field has a truthy value (which all valid datetime strings are) using `if request_data['expires_at']`. IMPORTANT NOTE: While it's tempting to just skip the entire scheduling block for permanent infractions, it's essential to unschedule existing expiration tasks for this infraction as we're changing a temporary infraction to a permanent infraction. This commit closes #751
2020-02-13Add thousand separators to Members count, closes #744Gravatar Deniz-4/+4
2020-02-13Update the tests accordingly to reflect the new changesGravatar Deniz-3/+3