-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_search_wordpress_urls.py
48 lines (36 loc) · 1.67 KB
/
test_search_wordpress_urls.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
import unittest
from specific import search_for_url_in_wordpress
class TestSearchWordpressUrls(unittest.TestCase):
def test_search_url_in_post_content(self):
# Mock data
sites_directory = 'test_data'
target_url = 'http://example.com'
expected_post_id = 123
# Call function
search_for_url_in_wordpress(sites_directory, target_url)
# Assert URL found in expected post
self.assertIn('Found URL http://example.com in post content for site: testsite', self.output)
self.assertIn('Post ID: 123', self.output)
def test_search_url_in_post_meta(self):
# Mock data
sites_directory = 'test_data'
target_url = 'http://example.com'
expected_post_id = 456
expected_meta_key = 'test_meta_key'
# Call function
search_for_url_in_wordpress(sites_directory, target_url)
# Assert URL found in expected post meta
self.assertIn('Found URL http://example.com in post meta for site: testsite', self.output)
self.assertIn('Post ID: 456, Meta Key: test_meta_key', self.output)
def test_database_connection_error(self):
# Mock data
sites_directory = 'test_data'
target_url = 'http://example.com'
# Patch pymysql to raise an error
with patch('pymysql.connect') as mock_connect:
mock_connect.side_effect = pymysql.Error()
# Call function
search_for_url_in_wordpress(sites_directory, target_url)
# Assert error handled correctly
self.assertIn('Error searching for URL for site: testsite', self.output)
self.assertIn('Error details:', self.output)