progress
This commit is contained in:
@@ -3,61 +3,33 @@ 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')
|
||||
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, 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': '5153',
|
||||
'username': 'user1@example.com',
|
||||
'password': 'password1',
|
||||
'use_ssl': 'off'
|
||||
})
|
||||
|
||||
assert response.status_code == 200
|
||||
# Should show either success or error message
|
||||
assert b'Test 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, 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]
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user