diff --git a/bin/notifier/test_notifier.py b/bin/notifier/test_notifier.py index 46450389..c6acf357 100644 --- a/bin/notifier/test_notifier.py +++ b/bin/notifier/test_notifier.py @@ -96,6 +96,18 @@ class Notify(Project): self.assertIn("cannot reach https://127.0.0.1:1", failed.reason) self.assertNotIn("secret-token", failed.reason) + def test_sender_in_fails_for_an_env_file_that_no_notifier_reads(self): + self.name_notifier(None, MATTERMOST_KEYS) + failed = notify.sender_in(str(self.checkout), self.home) + assert isinstance(failed, Failure), failed + self.assertIn("sets no `notifier`", failed.reason) + + def test_sender_in_fails_with_the_configs_reason_where_no_config_names_the_checkout(self): + other = self.home / "code" / "other" + other.mkdir() + subprocess.run(["git", "init", "--quiet", str(other)], check=True, env=isolated_env()) + self.assertIsInstance(notify.sender_in(str(other), self.home), Failure) + def test_sender_in_names_the_settings_to_add_where_the_config_names_no_notifier(self): failed = notify.sender_in(str(self.checkout), self.home) assert isinstance(failed, Failure), failed @@ -116,6 +128,12 @@ class Main(Project): self.assertEqual(self.run_main(argv, stdin, lambda message: sent.append(message)), (0, "")) self.assertEqual(sent, ["Which one?"]) + def test_prints_help_for_either_help_flag_whatever_follows_it(self): + for argv in (["-h"], ["--help"], ["--help", "extra"]): + with self.subTest(argv=argv), contextlib.redirect_stdout(io.StringIO()) as printed: + self.assertEqual(self.run_main(argv), (0, "")) + self.assertEqual(printed.getvalue(), main.__doc__.strip() + "\n") + def test_exits_2_on_misuse_naming_it(self): for argv, stdin, said in ( ([], " \n", "notify: the message is empty\n"), diff --git a/bin/slack_dm/test_slack_dm.py b/bin/slack_dm/test_slack_dm.py index f6c07b60..8d73fed7 100644 --- a/bin/slack_dm/test_slack_dm.py +++ b/bin/slack_dm/test_slack_dm.py @@ -56,6 +56,11 @@ class Send(unittest.TestCase): self.assertIsNone(dm.send(CONFIG, "Use & []?", slack)) self.assertEqual(slack.requests[0][3], {"channel": "U0123ABCD", "text": "Use <b> & [<setting>]?"}) + def test_leaves_quotes_as_they_are_since_slack_reads_only_three_characters_as_control(self): + slack = Slack({"ok": True}) + self.assertIsNone(dm.send(CONFIG, "Use \"a\" or 'b'?", slack)) + self.assertEqual(slack.requests[0][3]["text"], "Use \"a\" or 'b'?") + def test_fails_naming_slacks_error_code_where_slack_answers_ok_false(self): self.assertEqual(dm.send(CONFIG, "hi", Slack({"ok": False, "error": "invalid_auth"})), Failure("POST /api/chat.postMessage refused the message: invalid_auth"))