aboutsummaryrefslogtreecommitdiff
path: root/tests/test_search.py
blob: f2c003cf95b4d6fba909c2ada23030e191a1f3ed (plain) (blame)
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
import unittest
from unittest.mock import patch
from search import search_log

class TestSearchLog(unittest.TestCase):

    @patch('search.LOG_PATH', 'test_log_path')
    def test_search_log_with_match(self, mock_log_path):
        query = 'crumb'
        # Create a dummy log file (for testing)
        with open('test_log_path', 'w') as f:
            f.write("* Example Entry\n")
            f.write(":PROPERTIES:\n")
            f.write(":URL:       http://example.com\n")
            f.write(":TIMESTAMP: 2023-10-27 10:00:00\n")

        search_log(query)
        # Assert that the function prints the expected output
        with open('test_log_path', 'r') as f:
            output = f.read()
        self.assertIn("* Example Entry\n", output)

    @patch('search.LOG_PATH', 'test_log_path')
    def test_search_log_no_match(self, mock_log_path):
        query = 'nonexistent'
        with open('test_log_path', 'w') as f:
            f.write("* Example Entry\n")
            f.write(":PROPERTIES:\n")
            f.write(":URL:       http://example.com\n")
            f.write(":TIMESTAMP: 2023-10-27 10:00:00\n")
        search_log(query)
        with open('test_log_path', 'r') as f:
            output = f.read()
        self.assertNotIn("* Example Entry\n", output)