| import pytest |
| import json |
| from app import create_app |
| from unittest.mock import patch, MagicMock |
|
|
| def test_generate_post_with_unicode(): |
| """Test that generate post endpoint handles Unicode characters correctly.""" |
| app = create_app() |
| client = app.test_client() |
| |
| |
| with patch('backend.services.content_service.ContentService.generate_post_content') as mock_generate: |
| |
| test_content = "π Check out this amazing new feature! π #innovation" |
| mock_generate.return_value = test_content |
| |
| |
| with app.test_request_context(): |
| from flask_jwt_extended import create_access_token |
| with patch('flask_jwt_extended.get_jwt_identity') as mock_identity: |
| mock_identity.return_value = "test-user-id" |
| |
| |
| access_token = create_access_token(identity="test-user-id") |
| |
| |
| response = client.post( |
| '/api/posts/generate', |
| headers={'Authorization': f'Bearer {access_token}'}, |
| content_type='application/json' |
| ) |
| |
| |
| assert response.status_code == 200 |
| data = json.loads(response.data) |
| |
| |
| assert 'success' in data |
| assert data['success'] is True |
| assert 'content' in data |
| assert data['content'] == test_content |
| |
| |
| assert not response.data.decode('utf-8').encode('utf-8').decode('latin-1', errors='ignore') != response.data.decode('utf-8') |
|
|
| def test_get_posts_with_unicode_content(): |
| """Test that get posts endpoint handles Unicode content correctly.""" |
| app = create_app() |
| client = app.test_client() |
| |
| |
| mock_post_data = [ |
| { |
| 'id': 'test-post-1', |
| 'Text_content': 'π Amazing post with emoji! β¨', |
| 'is_published': False, |
| 'created_at': '2025-01-01T00:00:00Z', |
| 'Social_network': { |
| 'id_utilisateur': 'test-user-id' |
| } |
| } |
| ] |
| |
| with app.test_request_context(): |
| from flask_jwt_extended import create_access_token |
| with patch('flask_jwt_extended.get_jwt_identity') as mock_identity: |
| mock_identity.return_value = "test-user-id" |
| |
| |
| with patch('app.supabase') as mock_supabase: |
| mock_response = MagicMock() |
| mock_response.data = mock_post_data |
| mock_supabase.table.return_value.select.return_value.execute.return_value = mock_response |
| |
| access_token = create_access_token(identity="test-user-id") |
| |
| |
| response = client.get( |
| '/api/posts', |
| headers={'Authorization': f'Bearer {access_token}'}, |
| content_type='application/json' |
| ) |
| |
| |
| assert response.status_code == 200 |
| data = json.loads(response.data) |
| |
| |
| assert 'success' in data |
| assert data['success'] is True |
| assert 'posts' in data |
| assert len(data['posts']) == 1 |
| assert data['posts'][0]['Text_content'] == 'π Amazing post with emoji! β¨' |
|
|
| if __name__ == '__main__': |
| test_generate_post_with_unicode() |
| test_get_posts_with_unicode_content() |
| print("All Unicode integration tests passed!") |