2022-08-21 02:04:05 +05:30
|
|
|
import unittest
|
|
|
|
from unittest.mock import patch
|
2023-02-09 17:09:22 +05:30
|
|
|
from main import get_titles
|
2022-08-21 02:04:05 +05:30
|
|
|
|
|
|
|
# patch out the environ dictionary
|
|
|
|
# used to instantiate global variables in the titles_updater script
|
|
|
|
# maybe move the call to os.environ in the script to the update_titles method?
|
|
|
|
environ_patcher = patch.dict('os.environ', {
|
|
|
|
'REDDIT_CLIENT_ID': '',
|
|
|
|
'REDDIT_CLIENT_SECRET': '',
|
|
|
|
'REDDIT_PASSWORD': ''
|
|
|
|
})
|
|
|
|
environ_patcher.start()
|
|
|
|
|
2022-08-31 14:30:55 +05:30
|
|
|
class TestGetTitles(unittest.TestCase):
|
2022-08-21 02:04:05 +05:30
|
|
|
@patch('main.json.load', return_value={'titles': ['foo', 'bar', 'baz']})
|
|
|
|
def test_get_titles_returns_a_list(self, _):
|
|
|
|
titles = get_titles()
|
|
|
|
self.assertIsInstance(titles, list)
|
|
|
|
|
|
|
|
@patch('main.json.load', return_value={'titles': ['foo', 'bar', 'baz']})
|
|
|
|
def test_get_titles_contains_titles_from_dataset_file(self, mock_json_load):
|
|
|
|
titles = get_titles()
|
|
|
|
|
|
|
|
self.assertTrue(all(map(lambda title: title in mock_json_load.return_value['titles'], titles)))
|
|
|
|
|
|
|
|
environ_patcher.stop()
|