mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Add a unit test for Thought of the Day
This commit is contained in:
@@ -3,6 +3,7 @@ __docformat__ = "numpy"
|
||||
|
||||
import re
|
||||
import random
|
||||
from typing import Dict
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
@@ -12,20 +13,26 @@ from gamestonk_terminal.helper_funcs import get_user_agent
|
||||
class ThoughtOfTheDay:
|
||||
""" ThoughtOfTheDay class """
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, urls: Dict[str, str] = None):
|
||||
""" Constructor """
|
||||
self.urls = {
|
||||
"Marcus_Aurelius": "https://www.goodreads.com/author/quotes/17212.Marcus_Aurelius",
|
||||
"Epictetus": "https://www.goodreads.com/author/quotes/13852.Epictetus",
|
||||
"Seneca": "https://www.goodreads.com/author/quotes/4918776.Seneca",
|
||||
"Marcus_Tullius_Cicero": "https://www.goodreads.com/author/quotes/13755.Marcus_Tullius_Cicero",
|
||||
"Aristotle": "https://www.goodreads.com/author/quotes/2192.Aristotle",
|
||||
"Plato": "https://www.goodreads.com/author/quotes/879.Plato",
|
||||
"Pythagoras": "https://www.goodreads.com/author/quotes/203707.Pythagoras",
|
||||
}
|
||||
|
||||
self.metadata = {}
|
||||
|
||||
if urls is None:
|
||||
self.urls = {
|
||||
"Marcus_Aurelius": "https://www.goodreads.com/author/quotes/17212.Marcus_Aurelius",
|
||||
"Epictetus": "https://www.goodreads.com/author/quotes/13852.Epictetus",
|
||||
"Seneca": "https://www.goodreads.com/author/quotes/4918776.Seneca",
|
||||
"Marcus_Tullius_Cicero": "https://www.goodreads.com/author/quotes/13755.Marcus_Tullius_Cicero",
|
||||
"Aristotle": "https://www.goodreads.com/author/quotes/2192.Aristotle",
|
||||
"Plato": "https://www.goodreads.com/author/quotes/879.Plato",
|
||||
"Pythagoras": "https://www.goodreads.com/author/quotes/203707.Pythagoras",
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
self.urls = urls
|
||||
|
||||
def get_urls(self) -> dict:
|
||||
""" Getter method for URLs """
|
||||
return self.urls
|
||||
|
||||
82
tests/test_thought_of_the_day.py
Executable file
82
tests/test_thought_of_the_day.py
Executable file
@@ -0,0 +1,82 @@
|
||||
""" thought_of_the_day.py tests """
|
||||
import unittest
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from gamestonk_terminal import thought_of_the_day
|
||||
|
||||
import mock
|
||||
|
||||
mock_goodreads_page = """
|
||||
<html>
|
||||
<body>
|
||||
<div class="quotes">
|
||||
<h2>Epicurus quotes <span class="smallText">
|
||||
Showing 1-30 of 171
|
||||
</span>
|
||||
</h2>
|
||||
<div class='quote'>
|
||||
<div class='quoteDetails'>
|
||||
|
||||
<div class="quoteText">
|
||||
“Do not spoil what you have”
|
||||
<br> ―
|
||||
<span class="authorOrTitle">
|
||||
Epicurus
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="quoteFooter">
|
||||
<div class="greyText smallText left">
|
||||
tags:
|
||||
<a href="/quotes/tag/desire">desire</a>,
|
||||
<a href="/quotes/tag/gratitude">gratitude</a>,
|
||||
<a href="/quotes/tag/hope">hope</a>
|
||||
</div>
|
||||
<div class="right">
|
||||
<a class="smallText" title="View this quote" href="/quotes/169009-do-not-spoil-what-you-have-by-desiring-what-you">2582 likes</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class='action'>
|
||||
<a class="gr-button gr-button--small" rel="nofollow" href="/user/new">Like</a>
|
||||
</div>
|
||||
</div>
|
||||
<div style="text-align: right; width: 100%">
|
||||
<div><span class="previous_page disabled">« previous</span> <em class="current">1</em> <a rel="next" href="/author/quotes/114041.Epicurus?page=2">2</a> <a href="/author/quotes/114041.Epicurus?page=3">3</a> <a href="/author/quotes/114041.Epicurus?page=4">4</a> <a href="/author/quotes/114041.Epicurus?page=5">5</a> <a href="/author/quotes/114041.Epicurus?page=6">6</a> <a class="next_page" rel="next" href="/author/quotes/114041.Epicurus?page=2">next »</a></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
class TestThoughtOfTheDay(unittest.TestCase):
|
||||
def test_get_urls(self):
|
||||
urls = {"some author": "https://www.goodreads.com/author/quotes/someauthor"}
|
||||
|
||||
a_totd = thought_of_the_day.ThoughtOfTheDay(urls)
|
||||
|
||||
self.assertEqual(a_totd.get_urls(), urls)
|
||||
|
||||
@mock.patch("gamestonk_terminal.thought_of_the_day.requests")
|
||||
def test_get_metadata(self, mock_request_get):
|
||||
urls = {"some author": "https://www.goodreads.com/author/quotes/someauthor"}
|
||||
|
||||
mock_request_get.get().text = mock_goodreads_page
|
||||
|
||||
a_totd = thought_of_the_day.ThoughtOfTheDay(urls)
|
||||
|
||||
meta = a_totd.get_metadata("some author")
|
||||
|
||||
self.assertEqual(
|
||||
meta,
|
||||
{
|
||||
"pages": "6",
|
||||
"quoutes": "171",
|
||||
"quotes": [
|
||||
"\n “Do not spoil what you have”\n ―\n \n Epicurus\n \n"
|
||||
],
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user