works
This commit is contained in:
@@ -1,31 +1,28 @@
|
||||
import pytest
|
||||
from app.models import User
|
||||
from app.models import User, Folder
|
||||
import uuid
|
||||
|
||||
def test_index_route(client, app):
|
||||
"""Test that the index route loads successfully."""
|
||||
with app.app_context():
|
||||
# Create a mock user for the test
|
||||
mock_user = User(
|
||||
id=uuid.UUID('123e4567-e89b-12d3-a456-426614174000'),
|
||||
email='test@example.com'
|
||||
)
|
||||
from app import db
|
||||
db.session.add(mock_user)
|
||||
db.session.commit()
|
||||
|
||||
def test_index_route(client, app, mock_user):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
# Check if the page contains expected elements
|
||||
assert b'Email Organizer' in response.data
|
||||
assert b'Folders' in response.data
|
||||
|
||||
def test_add_folder_route(client):
|
||||
def test_add_folder_route(client, mock_user):
|
||||
"""Test the add folder API endpoint."""
|
||||
response = client.post('/api/folders',
|
||||
json={'name': 'Test Folder', 'rule_text': 'Test rule'},
|
||||
content_type='application/json')
|
||||
# Get initial count of folders for the user
|
||||
initial_folder_count = Folder.query.count()
|
||||
|
||||
# Send form data (URL encoded) instead of JSON
|
||||
response = client.post('/api/folders',
|
||||
data={'name': 'Test Folder', 'rule_text': 'Test rule something ok yes'},
|
||||
content_type='application/x-www-form-urlencoded')
|
||||
|
||||
print(response.__dict__)
|
||||
# Verify the response status is 201 Created
|
||||
assert response.status_code == 201
|
||||
assert b'Folder added (mock)' in response.data
|
||||
assert b'Test Folder' in response.data
|
||||
|
||||
# Verify that the number of folders has increased
|
||||
final_folder_count = Folder.query.count()
|
||||
assert final_folder_count > initial_folder_count
|
||||
Reference in New Issue
Block a user