From a4bb517723b19611917ce83695668638d364a4fa Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 19 Nov 2023 22:46:17 -0500 Subject: [PATCH] test: test note creation with command line --- ap/main.py | 4 ++-- tests/test_create_note.py | 44 ++++----------------------------------- 2 files changed, 6 insertions(+), 42 deletions(-) diff --git a/ap/main.py b/ap/main.py index 43a3e0c..c54de35 100755 --- a/ap/main.py +++ b/ap/main.py @@ -105,9 +105,9 @@ def make_parser(): action="store_true", help="Whether the note is followers-only", ) - note_parser.add_argument("--to", type=str, nargs="+", help="Additional recipients") + note_parser.add_argument("--to", type=str, action='append', help="Additional recipients") note_parser.add_argument( - "--cc", type=str, nargs="+", help="Additional CC recipients" + "--cc", type=str, action='append', help="Additional CC recipients" ) accept_parser = subparsers.add_parser("accept", help="Accept an activity") diff --git a/tests/test_create_note.py b/tests/test_create_note.py index f2281d4..7bd5e83 100644 --- a/tests/test_create_note.py +++ b/tests/test_create_note.py @@ -1,6 +1,6 @@ import unittest from unittest.mock import patch, mock_open, MagicMock -from ap.commands.create_note import CreateNoteCommand +from ap.main import run_command from argparse import Namespace import io import sys @@ -64,19 +64,7 @@ def tearDown(self): @patch("requests_oauthlib.OAuth2Session.post", side_effect=mock_oauth_post) @patch("requests_oauthlib.OAuth2Session.get", side_effect=mock_oauth_get) def test_create_note_public(self, mock_requests_get, mock_requests_post, mock_file): - args = Namespace( - subcommand="create", - subsubcommand="note", - content=[CONTENT], - public=True, - private=False, - followers_only=False, - to=[], - cc=[], - ) - cmd = CreateNoteCommand(args) - - cmd.run() + run_command(["create", "note", "--public", CONTENT], {}) # Assertions self.assertGreaterEqual(mock_requests_get.call_count, 1) @@ -90,19 +78,7 @@ def test_create_note_public(self, mock_requests_get, mock_requests_post, mock_fi def test_create_note_followers_only( self, mock_requests_get, mock_requests_post, mock_file ): - args = Namespace( - subcommand="create", - subsubcommand="note", - content=[CONTENT], - public=False, - private=False, - followers_only=True, - to=[], - cc=[], - ) - cmd = CreateNoteCommand(args) - - cmd.run() + run_command(["create", "note", "--followers-only", CONTENT], {}) # Assertions self.assertGreaterEqual(mock_requests_get.call_count, 1) @@ -116,19 +92,7 @@ def test_create_note_followers_only( def test_create_note_private( self, mock_requests_get, mock_requests_post, mock_file ): - args = Namespace( - subcommand="create", - subsubcommand="note", - content=[CONTENT], - public=False, - private=True, - followers_only=False, - to=[OTHER_ID], - cc=[], - ) - cmd = CreateNoteCommand(args) - - cmd.run() + run_command(["create", "note", '--to', OTHER_ID, CONTENT], {}) # Assertions self.assertGreaterEqual(mock_requests_get.call_count, 1)