Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/deadd tests #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions autoscraper/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

# Generated by Qodo Gen
from autoscraper.auto_scraper import AutoScraper


# Dependencies:
# pip install pytest-mock
import pytest

class TestAutoScraper:

# Build scraping rules from URL by providing wanted_list and successfully extract data
def test_build_with_wanted_list(self, mocker):
# Arrange
url = "http://test.com"
wanted_list = ["item1", "item2"]
html = "<html><body><div>item1</div><span>item2</span></body></html>"

mock_soup = mocker.patch('autoscraper.auto_scraper.BeautifulSoup')
mock_soup.return_value.findChildren.return_value = []

mock_get = mocker.patch('requests.get')
mock_get.return_value.text = html
mock_get.return_value.encoding = "utf-8"

scraper = AutoScraper()

# Act
results = scraper.build(url=url, wanted_list=wanted_list)

# Assert
assert len(scraper.stack_list) == 0
assert results == []
mock_get.assert_called_once()
mock_soup.assert_called_once()

# Build rules with empty wanted_list or wanted_dict
def test_build_with_empty_wanted(self, mocker):
# Arrange
url = "http://test.com"
html = "<html><body></body></html>"

mock_soup = mocker.patch('autoscraper.auto_scraper.BeautifulSoup')
mock_get = mocker.patch('requests.get')
mock_get.return_value.text = html
mock_get.return_value.encoding = "utf-8"

scraper = AutoScraper()

# Act
results = scraper.build(url=url)

# Assert
assert len(scraper.stack_list) == 0
assert results == []
mock_get.assert_not_called()
mock_soup.assert_not_called()