diff --git a/tests/test_commands.py b/tests/test_commands.py index 6bafb4f..5710c11 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -124,6 +124,7 @@ def test_with_multiword_term(self, mock_commands): def test_quote(): with patch('tululbot.commands.quote_engine') as mock_engine: + mock_engine.refresh_cache_if_applicable.return_value = False mock_engine.retrieve_random.return_value = 'some random quote' rv = quote() assert rv == 'some random quote' diff --git a/tests/test_quoteengine.py b/tests/test_quoteengine.py new file mode 100644 index 0000000..7382f39 --- /dev/null +++ b/tests/test_quoteengine.py @@ -0,0 +1,87 @@ +import json +from unittest.mock import patch + +import pytest + +from tululbot.utils import QuoteEngine + +generic_quote_1 = ( + '--- ' + 'quotes: ' + ' - q_no: 1' + ' quote: "Kenapa kalo mau sahur tiba2 ngantuk? Karena Anda belum punya cinta yang menemani Anda sahur."' + ' author: Anang Ferdi' + ' author_bio: Dokter cinta veteran' + ' tags: ' + ' - cinta' + ' - sahur' + ' - ramadhan' +) + +generic_quote_2 = ( + '---' + 'quotes:' + ' - q_no: 3' + ' quote: "Cinta itu bisa dibagi dengan 0 ga sih?"' + ' author: Adrian Nuradiansyah' + ' author_bio: Awesome Akhi' + ' tags: ' + ' - cinta' + ' - geek' + ' - matematika ' +) + +@pytest.fixture +def qe(): + return QuoteEngine() + +def test_refresh_time(qe): + with patch('tululbot.tils.datetime.datetime') as mock_dt: + with patch('tululbot.utils.requests') as mock_requests: + class FakeResponse: + pass + + response1 = FakeResponse() + response1.status_code = 200 + response1.text = ( + '{' + ' "commit": {' + ' "sha": "beefbeef"' + ' }' + '}' + ) + response1.ok = True + + response2 = FakeResponse() + response2.status_code = 200 + response2.text = ( + '' + '
Snowden is former CIA employee.
' + '