Skip to content

Failing tests in tests/test_wiki_bot.py #14

@LuisAPI

Description

@LuisAPI

Several tests in the tests/test_wiki_bot.py file are failing. These failures need to be addressed to ensure the functionality of the project is working as expected.

Failing Tests

  1. test_connect_to_wiki

    • Error Message:
      AssertionError: Expected 'mock' to be called once. Called 0 times.
      Calls: [call.login('YouTubeWikiBot', '2HeadedTurtle!')].
      
    • Description: The mock_site object is not being called with the expected arguments.
  2. test_fetch_channels_needing_updates

    • Error Message:
      TypeError: fetch_channels_needing_updates() takes 2 positional arguments but 4 were given
      
    • Description: The function is being called with the wrong number of arguments.
  3. test_fetch_channels_needing_updates_various[* Handle: @channel_one\n* Handle: @channel_two-expected_channels0]

    • Error Message:
      AssertionError: assert [] == ['@channel_one', '@channel_two']
      
    • Description: The function is returning an empty list instead of the expected channels.
  4. test_fetch_channels_needing_updates_various[* Handle: @only_channel-expected_channels1]

    • Error Message:
      AssertionError: assert [] == ['@only_channel']
      
    • Description: The function is returning an empty list instead of the expected channels.

Steps to Reproduce

  1. Run the tests using the following command:

    pytest
  2. Observe the test failures.

Expected Behavior

All tests should pass without any errors.

Proposed Fixes

  1. test_connect_to_wiki:

    • Ensure that the connect_to_wiki function is correctly calling mwclient.Site with the expected arguments.
  2. test_fetch_channels_needing_updates:

    • Update the test to call the function with the correct number of arguments.
  3. test_fetch_channels_needing_updates_various:

    • Ensure that the fetch_channels_needing_updates function correctly parses the page content and returns the expected channels.

Additional Context

Here are the relevant sections of the test output:

==================================================== test session starts =====================================================
platform win32 -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0
rootdir: F:\Luis\Repositories\LuisAPI\YouTubeWikiBot       
collected 8 items

tests\test_wiki_bot.py F..FFF..                                                                                         [100%]

========================================================== FAILURES ==========================================================
____________________________________________________ test_connect_to_wiki ____________________________________________________ 

mock_site = <MagicMock name='Site()' id='2201688564336'>

    def test_connect_to_wiki(mock_site):
        """Test connecting to the wiki."""
        mock_site.login.return_value = True  # Mock successful login

        # Call the function with test settings
        site = connect_to_wiki(TEST_WIKI_URL, TEST_WIKI_PATH, TEST_USERNAME, TEST_PASSWORD)

        # Assertions
>       mock_site.assert_called_once_with(TEST_WIKI_URL, path=TEST_WIKI_PATH)

tests\test_wiki_bot.py:31:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

self = <MagicMock name='Site()' id='2201688564336'>, args = ('zingarese.shoutwiki.com',), kwargs = {'path': '/w/'}
msg = "Expected 'mock' to be called once. Called 0 times.\nCalls: [call.login('YouTubeWikiBot', '2HeadedTurtle!')]."

    def assert_called_once_with(self, /, *args, **kwargs):
        """assert that the mock was called exactly once and that that call was
        with the specified arguments."""
        if not self.call_count == 1:
            msg = ("Expected '%s' to be called once. Called %s times.%s"
                   % (self._mock_name or 'mock',
                      self.call_count,
                      self._calls_repr()))
>           raise AssertionError(msg)
E           AssertionError: Expected 'mock' to be called once. Called 0 times.
E           Calls: [call.login('YouTubeWikiBot', '2HeadedTurtle!')].

C:\Program Files\Python313\Lib\unittest\mock.py:988: AssertionError
____________________________________________ test_fetch_channels_needing_updates _____________________________________________ 

mock_site = <MagicMock name='Site()' id='2201688570048'>

    def test_fetch_channels_needing_updates(mock_site):
        """Test fetching channels that need updates."""
        mock_page = MagicMock()
        mock_page.text.return_value = """
        * Handle: @example_channel
        * Handle: @another_channel
        """
        mock_site.pages.__getitem__.return_value = mock_page  # Mock accessing the page

        # Call the function
>       channels = fetch_channels_needing_updates(TEST_WIKI_URL, 'Channel Update Requests', TEST_USERNAME, TEST_PASSWORD)      
E       TypeError: fetch_channels_needing_updates() takes 2 positional arguments but 4 were given

tests\test_wiki_bot.py:72: TypeError
_______ test_fetch_channels_needing_updates_various[* Handle: @channel_one\n* Handle: @channel_two-expected_channels0] _______ 

mock_site = <MagicMock name='Site()' id='2201688569040'>, page_text = '* Handle: @channel_one\n* Handle: @channel_two'
expected_channels = ['@channel_one', '@channel_two']

    @pytest.mark.parametrize("page_text, expected_channels", [
        ("* Handle: @channel_one\n* Handle: @channel_two", ['@channel_one', '@channel_two']),
        ("* Handle: @only_channel", ['@only_channel']),
        ("No handles here", []),
        ("* Random text without proper format", []),
    ])
    def test_fetch_channels_needing_updates_various(mock_site, page_text, expected_channels):
        """Test fetching channels under various content scenarios."""
        mock_page = MagicMock()
        mock_page.text.return_value = page_text
        mock_site.pages.__getitem__.return_value = mock_page  # Mock accessing the page
    
        # Call the function
        channels = fetch_channels_needing_updates(mock_site, 'Channel Update Requests')

        # Assertions
        mock_site.pages.__getitem__.assert_called_once_with('Channel Update Requests')
>       assert channels == expected_channels
E       AssertionError: assert [] == ['@channel_on...@channel_two']
E
E         Right contains 2 more items, first extra item: '@channel_one'
E         Use -v to get more diff

tests\test_wiki_bot.py:95: AssertionError
__________________ test_fetch_channels_needing_updates_various[* Handle: @only_channel-expected_channels1] ___________________ 

mock_site = <MagicMock name='Site()' id='2201689524608'>, page_text = '* Handle: @only_channel'
expected_channels = ['@only_channel']

    @pytest.mark.parametrize("page_text, expected_channels", [
        ("* Handle: @channel_one\n* Handle: @channel_two", ['@channel_one', '@channel_two']),
        ("* Handle: @only_channel", ['@only_channel']),
        ("No handles here", []),
        ("* Random text without proper format", []),
    ])
    def test_fetch_channels_needing_updates_various(mock_site, page_text, expected_channels):
        """Test fetching channels under various content scenarios."""
        mock_page = MagicMock()
        mock_page.text.return_value = page_text
        mock_site.pages.__getitem__.return_value = mock_page  # Mock accessing the page

        # Call the function
        channels = fetch_channels_needing_updates(mock_site, 'Channel Update Requests')

        # Assertions
        mock_site.pages.__getitem__.assert_called_once_with('Channel Update Requests')
>       assert channels == expected_channels
E       AssertionError: assert [] == ['@only_channel']
E
E         Right contains one more item: '@only_channel'
E         Use -v to get more diff

tests\test_wiki_bot.py:95: AssertionError
================================================== short test summary info ===================================================
FAILED tests/test_wiki_bot.py::test_connect_to_wiki - AssertionError: Expected 'mock' to be called once. Called 0 times.       
FAILED tests/test_wiki_bot.py::test_fetch_channels_needing_updates - TypeError: fetch_channels_needing_updates() takes 2 positi
onal arguments but 4 were given                                                                                                FAILED tests/test_wiki_bot.py::test_fetch_channels_needing_updates_various[* Handle: @channel_one\n* Handle: @channel_two-expec
ted_channels0] - AssertionError: assert [] == ['@channel_on...@channel_two']                                                   FAILED tests/test_wiki_bot.py::test_fetch_channels_needing_updates_various[* Handle: @only_channel-expected_channels1] - Assert
ionError: assert [] == ['@only_channel']                                                                                       ================================================ 4 failed, 4 passed in 5.44s ===================================================

Please address these issues to ensure all tests pass successfully.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions