Big-Link-Man/tests/unit/test_content_generator.py

96 lines
2.5 KiB
Python

"""
Unit tests for ContentGenerator service
"""
import pytest
from src.generation.service import ContentGenerator
def test_count_words_simple():
"""Test word count on simple text"""
generator = ContentGenerator(None, None, None, None)
html = "<p>This is a test with five words</p>"
count = generator.count_words(html)
assert count == 7
def test_count_words_with_headings():
"""Test word count with HTML headings"""
generator = ContentGenerator(None, None, None, None)
html = """
<h2>Main Heading</h2>
<p>This is a paragraph with some words.</p>
<h3>Subheading</h3>
<p>Another paragraph here.</p>
"""
count = generator.count_words(html)
assert count > 10
def test_count_words_strips_html_tags():
"""Test that HTML tags are stripped before counting"""
generator = ContentGenerator(None, None, None, None)
html = "<p>Hello <strong>world</strong> this <em>is</em> a test</p>"
count = generator.count_words(html)
assert count == 6
def test_validate_word_count_within_range():
"""Test validation when word count is within range"""
generator = ContentGenerator(None, None, None, None)
content = "<p>" + " ".join(["word"] * 100) + "</p>"
is_valid, count = generator.validate_word_count(content, 50, 150)
assert is_valid is True
assert count == 100
def test_validate_word_count_below_minimum():
"""Test validation when word count is below minimum"""
generator = ContentGenerator(None, None, None, None)
content = "<p>" + " ".join(["word"] * 30) + "</p>"
is_valid, count = generator.validate_word_count(content, 50, 150)
assert is_valid is False
assert count == 30
def test_validate_word_count_above_maximum():
"""Test validation when word count is above maximum"""
generator = ContentGenerator(None, None, None, None)
content = "<p>" + " ".join(["word"] * 200) + "</p>"
is_valid, count = generator.validate_word_count(content, 50, 150)
assert is_valid is False
assert count == 200
def test_count_words_empty_content():
"""Test word count on empty content"""
generator = ContentGenerator(None, None, None, None)
count = generator.count_words("")
assert count == 0
def test_count_words_only_tags():
"""Test word count on content with only HTML tags"""
generator = ContentGenerator(None, None, None, None)
html = "<div><p></p><span></span></div>"
count = generator.count_words(html)
assert count == 0