Repository: TheFriendlyCoder/friendlypins

Issue:
rework dt command to delete boards
Instead of having the '-d' option delete each pin one at a time, we should rework it to delete the board once complete ... either that or remove the option completely and add a new command called "delete_board" to just delete a given board.

Discussion:

Patch:
diff --git a/src/friendlypins/scripts/fpins.py b/src/friendlypins/scripts/fpins.py
index 1338bec..f9656c7 100644
--- a/src/friendlypins/scripts/fpins.py
+++ b/src/friendlypins/scripts/fpins.py
@@ -14,7 +14,7 @@ def _download_thumbnails(args):
     :returns: zero on success, non-zero on failure
     :rtype: :class:`int`
     """
-    return download_thumbnails(args.token, args.board, args.path, args.delete)
+    return download_thumbnails(args.token, args.board, args.path)
 
 def _edit_board(args):
     """Callback for manipulating a Pinterest board
@@ -80,11 +80,6 @@ def get_args(args):
         required=True,
         help="Path to the folder where thumbnails are to be downloaded",
     )
-    thumbnails_cmd.add_argument(
-        '--delete', '-d',
-        action="store_true",
-        help="Deletes each pin as it's thumbnail is downloaded"
-    )
 
     # Board manipulation sub-command
     desc = 'Manipulates boards owned by the authenticated user'
diff --git a/src/friendlypins/utils/console_actions.py b/src/friendlypins/utils/console_actions.py
index 30ecd5f..943a7bb 100644
--- a/src/friendlypins/utils/console_actions.py
+++ b/src/friendlypins/utils/console_actions.py
@@ -48,13 +48,12 @@ def _download_pin(pin, folder):
     return 0
 
 
-def download_thumbnails(api_token, board_name, output_folder, delete):
+def download_thumbnails(api_token, board_name, output_folder,):
     """Downloads thumbnails of all pins on a board
 
     :param str api_token: Authentication token for accessing the Pinterest API
     :param str board_name: name of the board containing the pins to process
     :param str output_folder: path where the thumbnails are to be downloaded
-    :param bool delete: flag to delete pins as their thumbnails are downloaded
     :returns:
         status code describing the result of the action
         zero on success, non-zero on failure
@@ -89,8 +88,6 @@ def download_thumbnails(api_token, board_name, output_folder, delete):
             retval = _download_pin(cur_pin, output_folder)
             if retval:
                 return retval
-            if delete:
-                cur_pin.delete()
             pbar.update()
 
     return 0


Test patch:
diff --git a/unit_tests/test_console_actions.py b/unit_tests/test_console_actions.py
index 37ae68c..509de7d 100644
--- a/unit_tests/test_console_actions.py
+++ b/unit_tests/test_console_actions.py
@@ -74,7 +74,7 @@ def test_download_thumbnails(rest_io, action_requests, mock_open, mock_os):
     mock_os.path.exists.return_value = False
 
     # Flex our code
-    result = download_thumbnails("1234abcd", expected_board_name, "/tmp", False)
+    result = download_thumbnails("1234abcd", expected_board_name, "/tmp")
 
     # Make sure the call was successful, and that our mock APIs
     # that must have executed as part of the process were called
@@ -85,86 +85,6 @@ def test_download_thumbnails(rest_io, action_requests, mock_open, mock_os):
     mock_open.assert_called()
 
 
-@mock.patch("friendlypins.utils.console_actions.os")
-@mock.patch("friendlypins.utils.console_actions.open")
-@mock.patch("friendlypins.utils.console_actions.requests")
-@mock.patch("friendlypins.api.RestIO")
-def test_download_thumbnails_with_delete(rest_io, action_requests, mock_open, mock_os):
-
-    # Fake user data for the user authenticating to Pinterest
-    expected_user_data = {
-        'data': {
-            'url': 'https://www.pinterest.com/MyUserName/',
-            'first_name': "John",
-            'last_name': "Doe",
-            'id': "12345678"
-        }
-    }
-
-    # Fake board data for the boards owned by the fake authenticated user
-    expected_board_name = "MyBoard"
-    expected_board_data = {
-        "data": [{
-            "id": "6789",
-            "name": expected_board_name,
-            "url": "https://www.pinterest.ca/MyName/MyBoard/",
-            "counts": {
-                "pins": 1
-            }
-        }]
-    }
-
-    # Fake pin data for the fake board, with fake thumbnail metadata
-    expected_thumbnail_url = "https://i.pinimg.com/originals/1/2/3/abcd.jpg"
-    expected_pin_data = {
-        "data": [{
-            "id": "1234",
-            "url": "https://www.pinterest.ca/MyName/MyPin/",
-            "note": "My Pin descriptive text",
-            "link": "http://www.mysite.com/target",
-            "media": {
-                "type": "image"
-            },
-            "image": {
-                "original": {
-                    "url": expected_thumbnail_url,
-                    "width": "800",
-                    "height": "600"
-                }
-            }
-        }],
-        "page": {
-            "cursor": None
-        }
-    }
-
-    # fake our Pinterest API data to flex our implementation logic
-    mock_response = mock.MagicMock()
-    mock_response.get.side_effect = [
-        expected_user_data,
-    ]
-    mock_response.get_pages.side_effect = [
-        [expected_board_data],
-        [expected_pin_data]
-        ]
-    rest_io.return_value = mock_response
-
-    # Make sure the code think's the output file where the
-    # thumbnail is to be downloaded doesn't already exist
-    mock_os.path.exists.return_value = False
-
-    # Flex our code
-    result = download_thumbnails("1234abcd", expected_board_name, "/tmp", True)
-
-    # Make sure the call was successful, and that our mock APIs
-    # that must have executed as part of the process were called
-    assert result == 0
-    action_requests.get.assert_called_once_with(expected_thumbnail_url, stream=True)
-    mock_os.makedirs.assert_called()
-    mock_os.path.exists.assert_called()
-    mock_open.assert_called()
-    mock_response.delete.assert_called_once()
-
 @mock.patch("friendlypins.utils.console_actions.os")
 @mock.patch("friendlypins.utils.console_actions.open")
 @mock.patch("friendlypins.utils.console_actions.requests")
@@ -239,7 +159,7 @@ def test_download_thumbnails_error(rest_io, action_requests, mock_open, mock_os)
     action_requests.get.return_value = mock_action_response
 
     # Flex our code
-    result = download_thumbnails("1234abcd", expected_board_name, "/tmp", False)
+    result = download_thumbnails("1234abcd", expected_board_name, "/tmp")
 
     # Make sure the call was successful, and that our mock APIs
     # that must have executed as part of the process were called
@@ -318,7 +238,7 @@ def test_download_thumbnails_missing_board(rest_io, action_requests, mock_open,
     mock_os.path.exists.return_value = False
 
     # Flex our code
-    result = download_thumbnails("1234abcd", "FuBar", "/tmp", False)
+    result = download_thumbnails("1234abcd", "FuBar", "/tmp")
 
     # Make sure the call was successful, and that our mock APIs
     # that must have executed as part of the process were called
@@ -401,7 +321,7 @@ def test_download_thumbnails_exists(rest_io, action_requests, mock_open, mock_os
 
     # Flex our code
     output_folder = "/tmp"
-    result = download_thumbnails("1234abcd", expected_board_name, output_folder, False)
+    result = download_thumbnails("1234abcd", expected_board_name, output_folder)
 
     # Make sure the call was successful, and that our mock APIs
     # that must have executed as part of the process were called