import pytest from app import create_app from app.models import User, db, Folder class TestIMAPRoutes: def test_imap_config_modal(self, authenticated_client): response = authenticated_client.get('/api/imap/config') assert response.status_code == 200 assert b'Configure IMAP Connection' in response.data def test_imap_connection_test_success(self, authenticated_client, app): response = authenticated_client.post('/api/imap/test', data={ 'server': 'localhost', 'port': '5143', 'username': 'user1@example.com', 'password': 'password1', 'use_ssl': False }) print(response.data) assert response.status_code == 200 # Should show either success or error message assert b'Test Connection' in response.data def test_imap_sync_folders(self, authenticated_client, app, mock_user): # Create a test user and log in mock_user.imap_config = {'server': 'localhost', 'port': 5143, 'username': 'user1@example.com', 'password': 'password1', 'use_ssl': False} db.session.commit() folders = Folder.query.filter_by(user_id=mock_user.id).all() response = authenticated_client.post('/api/imap/sync') print('respo', response.data, response) new_folders = Folder.query.filter_by(user_id=mock_user.id).all() assert len(new_folders) > len(folders) # Should fail without real IMAP server but return proper response assert response.status_code in [200, 400]