File size: 1,496 Bytes
692e5e8
 
90f4ddb
692e5e8
90f4ddb
692e5e8
90f4ddb
 
 
692e5e8
90f4ddb
 
 
692e5e8
 
 
 
 
 
90f4ddb
 
692e5e8
90f4ddb
 
 
 
 
692e5e8
90f4ddb
692e5e8
90f4ddb
 
 
692e5e8
90f4ddb
692e5e8
90f4ddb
692e5e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import tempfile

import pytest
from langchain_community.tools import DuckDuckGoSearchRun

from tools import GetYouTubeTranscript, get_wikipedia_page


@pytest.fixture
def yt():
    return GetYouTubeTranscript()


@pytest.fixture
def ddg():
    return DuckDuckGoSearchRun()


def test_valid_youtube_url(yt):
    # Use a real YouTube video URL with a publicly available transcript
    url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstley"  # Replace with a valid video ID
    result = yt._run(url)
    assert (
        "Never gonna give you up" in result
    )  # Check for a known part of the transcript


def test_invalid_youtube_url(yt):
    url = "https://www.youtube.com/watch?v="
    result = yt._run(url)
    assert result == "Video ID not found in the URL"


def test_non_youtube_url(yt):
    url = "https://www.example.com"
    result = yt._run(url)
    assert result == "Video ID not found in the URL"


def test_ddg_search(ddg: DuckDuckGoSearchRun):
    query = "Mercedes Sosa live albums"
    result = ddg._run(query)
    print(result)
    assert isinstance(result, str)  # Check if the result is a string


def test_wiki_get_content():
    query = "Mercedes Sosa"
    content = get_wikipedia_page(query)
    temp_file = tempfile.NamedTemporaryFile(
        delete=False, mode="w", encoding="utf-8", dir="/tmp"
    )
    with open(temp_file.name, "w", encoding="utf-8") as file:
        file.write(content)
    assert content != ""
    assert "Error" not in content