import pytest from app import create_app from app.models import User, db, Folder class TestIMAPRoutes: def test_imap_config_modal(self, client): # Create a test user and log in user = User(email='test@example.com', first_name='Test', last_name='User') user.set_password('password') db.session.add(user) db.session.commit() client.post('/auth/login', data={ 'email': 'test@example.com', 'password': 'password' }) response = 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, client, app): with app.app_context(): # Create a test user and log in user = User(email='test2@example.com', first_name='Test', last_name='User') user.set_password('password') db.session.add(user) db.session.commit() client.post('/auth/login', data={ 'email': 'test2@example.com', 'password': 'password' }) response = client.post('/api/imap/test', data={ 'server': 'test.com', 'port': '993', 'username': 'test@test.com', 'password': 'testpass', 'use_ssl': 'on' }) 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, client, app): with app.app_context(): # Create a test user and log in user = User(email='test3@example.com', first_name='Test', last_name='User') user.set_password('password') user.imap_config = {'server': 'test.com', 'port': 993, 'username': 'test', 'password': 'pass'} db.session.add(user) db.session.commit() client.post('/auth/login', data={ 'email': 'test3@example.com', 'password': 'password' }) response = client.post('/api/imap/sync') # Should fail without real IMAP server but return proper response assert response.status_code in [200, 400]