fix: isolate dev messages from production
This commit is contained in:
1 parent
45b1c5b468
commit
c02db5ada9
6 files changed
+124
-34
No files matched your search
@@ -27,8 +27,9 @@ class DeployNoticeTests(unittest.IsolatedAsyncioTestCase):
|
||||
|
||||
async def test_does_not_send_outside_development(self):
|
||||
fake_bot = AsyncMock()
|
||||
with patch.object(bot, "DEPLOY_ENV", "production"):
|
||||
await bot.notify_development_deploy(fake_bot)
|
||||
for env in ("production", "", "staging", "Development", " development"):
|
||||
with self.subTest(env=env), patch.object(bot, "DEPLOY_ENV", env):
|
||||
await bot.notify_development_deploy(fake_bot)
|
||||
fake_bot.send_message.assert_not_awaited()
|
||||
|
||||
async def test_deploy_notice_does_not_block_if_test_api_hangs(self):
|
||||
@@ -43,6 +44,39 @@ class DeployNoticeTests(unittest.IsolatedAsyncioTestCase):
|
||||
fake_bot.send_message.assert_awaited_once()
|
||||
|
||||
|
||||
class UserFacingErrorTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_production_error_is_generic_without_exception_details(self):
|
||||
message = AsyncMock()
|
||||
with patch.object(bot, "DEPLOY_ENV", "production"):
|
||||
await bot.report_error(message, "генерация поста", RuntimeError("internal detail"))
|
||||
message.answer.assert_awaited_once()
|
||||
self.assertNotIn("internal detail", message.answer.await_args.args[0])
|
||||
|
||||
async def test_development_error_details_are_a_separate_message(self):
|
||||
message = AsyncMock()
|
||||
with patch.object(bot, "DEPLOY_ENV", "development"):
|
||||
await bot.report_error(message, "генерация поста", RuntimeError("internal detail"))
|
||||
self.assertEqual(message.answer.await_count, 2)
|
||||
self.assertNotIn("internal detail", message.answer.await_args_list[0].args[0])
|
||||
diagnostic = message.answer.await_args_list[1]
|
||||
self.assertIn("Dev-диагностика", diagnostic.args[0])
|
||||
self.assertIn("internal detail", diagnostic.args[0])
|
||||
|
||||
async def test_unknown_environment_does_not_send_developer_diagnostics(self):
|
||||
message = AsyncMock()
|
||||
with patch.object(bot, "DEPLOY_ENV", "staging"):
|
||||
await bot.report_error(message, "генерация поста", RuntimeError("internal detail"))
|
||||
message.answer.assert_awaited_once()
|
||||
self.assertNotIn("internal detail", message.answer.await_args.args[0])
|
||||
|
||||
async def test_missing_environment_disables_developer_diagnostics(self):
|
||||
message = AsyncMock()
|
||||
with patch.object(bot, "DEPLOY_ENV", ""):
|
||||
await bot.report_error(message, "генерация поста", RuntimeError("internal detail"))
|
||||
message.answer.assert_awaited_once()
|
||||
self.assertNotIn("internal detail", message.answer.await_args.args[0])
|
||||
|
||||
|
||||
|
||||
class HelpRoutingTests(unittest.TestCase):
|
||||
def test_commands_are_routed_in_command_handler(self):
|
||||
|
||||
Reference in new issue
Block a user