diff --git a/gamestonk_terminal/thought_of_the_day.py b/gamestonk_terminal/thought_of_the_day.py index 0afa152c7a2..98690116487 100644 --- a/gamestonk_terminal/thought_of_the_day.py +++ b/gamestonk_terminal/thought_of_the_day.py @@ -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 diff --git a/tests/test_thought_of_the_day.py b/tests/test_thought_of_the_day.py new file mode 100755 index 00000000000..7bfe9d0e809 --- /dev/null +++ b/tests/test_thought_of_the_day.py @@ -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 = """ + + +
+

Epicurus quotes +Showing 1-30 of 171 + +

+
+
+ +
+ “Do not spoil what you have” +
― + + Epicurus + +
+ + +
+
+ tags: + desire, + gratitude, + hope +
+ +
+ +
+
+Like +
+
+
+
« previous 1 3 4 5 6
+
+ + +""" + + +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" + ], + }, + )