88
99@pytest .fixture
1010def youtube_mock (mocker , mock_video_info ):
11+ """Fixture to mock the YouTube instance and its videos_infos method."""
1112 mock = mocker .patch ("youtool.commands.video_info.YouTube" )
1213 mock_instance = mock .return_value
1314 mock_instance .videos_infos = Mock (return_value = mock_video_info )
1415 return mock_instance
1516
1617@pytest .fixture
1718def mock_video_info ():
19+ """Fixture to return mock video information."""
1820 return [
1921 {"id" : "tmrhPou85HQ" , "title" : "Title 1" , "description" : "Description 1" , "published_at" : "2021-01-01" , "view_count" : 100 , "like_count" : 10 , "comment_count" : 5 },
2022 {"id" : "qoI_x9fylaw" , "title" : "Title 2" , "description" : "Description 2" , "published_at" : "2021-02-01" , "view_count" : 200 , "like_count" : 20 , "comment_count" : 10 }
2123 ]
2224
2325def test_execute_with_ids_and_urls (youtube_mock , mocker , tmp_path , mock_video_info ):
26+ """Test the execute method with provided video IDs and URLs.
27+
28+ This test verifies that the execute method can handle both video IDs and URLs,
29+ and correctly writes the video information to the output CSV file.
30+ """
2431 ids = ["tmrhPou85HQ" , "qoI_x9fylaw" ]
2532 urls = ["https://www.youtube.com/watch?v=tmrhPou85HQ&ab_channel=Turicas" , "https://www.youtube.com/watch?v=qoI_x9fylaw&ab_channel=PythonicCaf%C3%A9" ]
2633 output_file_path = tmp_path / "output.csv"
@@ -36,12 +43,25 @@ def test_execute_with_ids_and_urls(youtube_mock, mocker, tmp_path, mock_video_in
3643 assert csv_data [1 ]["id" ] == "qoI_x9fylaw"
3744
3845def test_execute_missing_arguments ():
46+ """Test the execute method raises an exception when missing required arguments.
47+
48+ This test verifies that the execute method raises an exception if neither
49+ video IDs nor URLs are provided.
50+
51+ Raises:
52+ Exception: If neither 'ids' nor 'urls' is provided.
53+ """
3954 with pytest .raises (Exception ) as exc_info :
4055 VideoInfo .execute (api_key = "test_api_key" )
4156
4257 assert str (exc_info .value ) == "Either 'ids' or 'urls' must be provided for the video-info command"
4358
4459def test_execute_with_input_file_path (youtube_mock , mocker , tmp_path , mock_video_info ):
60+ """Test the execute method with an input CSV file containing video URLs and IDs.
61+
62+ This test verifies that the execute method can read video URLs and IDs from
63+ an input CSV file and correctly writes the video information to the output CSV file.
64+ """
4565 input_csv_content = """video_id,video_url
4666 tmrhPou85HQ,https://www.youtube.com/watch?v=tmrhPou85HQ&ab_channel=Turicas
4767 qoI_x9fylaw,https://www.youtube.com/watch?v=qoI_x9fylaw&ab_channel=PythonicCaf%C3%A9
@@ -64,6 +84,12 @@ def test_execute_with_input_file_path(youtube_mock, mocker, tmp_path, mock_video
6484
6585
6686def test_execute_with_info_columns (youtube_mock , mocker , tmp_path , mock_video_info ):
87+ """Test the execute method with specified info columns.
88+
89+ This test verifies that the execute method can filter the video information
90+ based on specified columns and correctly writes the filtered information
91+ to the output CSV file.
92+ """
6793 ids = ["tmrhPou85HQ" , "qoI_x9fylaw" ]
6894 output_file_path = tmp_path / "output.csv"
6995
0 commit comments