mirror of
https://github.com/timberjoegithub/GoogleScrape.git
synced 2026-07-22 00:19:48 +00:00
Refactor: repo hygiene, shared utils, focused tests, and CI improvements
- Remove dead imports/duplication from Google2xls.py and social.py - Centralize shared logic in review_workflow_utils.py - Add focused posting-flow tests in tests/test_social.py (all pass) - Update .gitignore for secrets and local artifacts - Trim requirements.txt to direct deps - Improve CI: compile all scripts, run focused tests - Prep repo for clean commit (no secrets, no local artifacts)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import unittest
|
||||
from unittest.mock import patch, MagicMock
|
||||
import social
|
||||
|
||||
class SocialPostingFlowTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Patch env and Posts for isolation
|
||||
self.env_patch = patch('social.env')
|
||||
self.mock_env = self.env_patch.start()
|
||||
self.mock_env.request_timeout = 1
|
||||
self.mock_env.facebooksleep = 0
|
||||
self.mock_env.forcegoogleupdate = False
|
||||
self.mock_env.xls = 'dummy.xlsx'
|
||||
self.mock_env.mariadb = False
|
||||
self.mock_env.mariadbuser = 'user'
|
||||
self.mock_env.mariadbpass = 'pass'
|
||||
self.mock_env.mariadbserver = 'localhost'
|
||||
self.mock_env.mariadbdb = 'db'
|
||||
self.mock_env.needreversed = False
|
||||
self.mock_env.postssession = MagicMock()
|
||||
self.mock_env.posts = []
|
||||
self.mock_env.xlsdf = MagicMock()
|
||||
self.mock_env.posts = []
|
||||
self.mock_env.postssession.query.return_value.count.return_value = 0
|
||||
self.addCleanup(self.env_patch.stop)
|
||||
|
||||
@patch('social.requests.post')
|
||||
@patch('builtins.open', new_callable=MagicMock)
|
||||
def test_post_facebook_video_handles_success(self, mock_open, mock_post):
|
||||
mock_post.return_value.json.return_value = {'id': '123'}
|
||||
mock_open.return_value.__enter__.return_value = MagicMock()
|
||||
result = social.post_facebook_video('groupid', ['video.mp4'], 'token', 'title', 'content', 'date', 'rating', 'address')
|
||||
self.assertEqual(result, {'id': '123'})
|
||||
|
||||
@patch('social.requests.post', side_effect=AttributeError('fail'))
|
||||
@patch('builtins.open', new_callable=MagicMock)
|
||||
def test_post_facebook_video_handles_error(self, mock_open, mock_post):
|
||||
mock_open.return_value.__enter__.return_value = MagicMock()
|
||||
result = social.post_facebook_video('groupid', ['video.mp4'], 'token', 'title', 'content', 'date', 'rating', 'address')
|
||||
self.assertFalse(result)
|
||||
|
||||
def test_write_to_database_handles_empty(self):
|
||||
# Should not raise
|
||||
data = []
|
||||
local_outputs = {'xlsdf': MagicMock(), 'posts': [], 'postssession': MagicMock()}
|
||||
result = social.write_to_database(data, local_outputs)
|
||||
self.assertEqual(result, data)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user