Skip to content

Commit

Permalink
test: test note creation with command line
Browse files Browse the repository at this point in the history
  • Loading branch information
evanp committed Nov 20, 2023
1 parent 04d2554 commit a4bb517
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 42 deletions.
4 changes: 2 additions & 2 deletions ap/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
44 changes: 4 additions & 40 deletions tests/test_create_note.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a4bb517

Please sign in to comment.