support toggle.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
from app.models import User, Folder
|
||||
from app import db
|
||||
import uuid
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
@@ -308,4 +309,64 @@ def test_edit_folder_content_whitespace_handling(authenticated_client, mock_fold
|
||||
assert updated_folder is not None
|
||||
assert updated_folder.name == 'Updated Folder With Whitespace' # Should be trimmed
|
||||
assert updated_folder.rule_text == 'Updated rule with whitespace around it' # Should be trimmed
|
||||
assert updated_folder.priority == int(test_priority)
|
||||
assert updated_folder.priority == int(test_priority)
|
||||
|
||||
def test_toggle_folder_organize_enabled(authenticated_client, mock_folder):
|
||||
"""Test toggling the organize_enabled flag for a folder."""
|
||||
# Verify initial state is True (default)
|
||||
assert mock_folder.organize_enabled is True
|
||||
|
||||
# Toggle the flag
|
||||
response = authenticated_client.put(f'/api/folders/{mock_folder.id}/toggle')
|
||||
|
||||
# Should return 200 OK
|
||||
assert response.status_code == 200
|
||||
|
||||
# Verify the folder was updated in the database
|
||||
updated_folder = Folder.query.filter_by(id=mock_folder.id).first()
|
||||
assert updated_folder is not None
|
||||
assert updated_folder.organize_enabled is False
|
||||
|
||||
# Toggle again to make sure it works both ways
|
||||
response2 = authenticated_client.put(f'/api/folders/{mock_folder.id}/toggle')
|
||||
|
||||
# Should return 200 OK
|
||||
assert response2.status_code == 200
|
||||
|
||||
# Verify the folder was updated in the database again
|
||||
updated_folder2 = Folder.query.filter_by(id=mock_folder.id).first()
|
||||
assert updated_folder2 is not None
|
||||
assert updated_folder2.organize_enabled is True
|
||||
|
||||
def test_toggle_folder_organize_enabled_not_found(authenticated_client, mock_user):
|
||||
"""Test toggling organize_enabled flag for a non-existent folder."""
|
||||
# Try to toggle a folder that doesn't exist
|
||||
response = authenticated_client.put('/api/folders/999/toggle')
|
||||
|
||||
# Should return 404 Not Found
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_toggle_folder_organize_enabled_unauthorized(authenticated_client, mock_user, app):
|
||||
"""Test toggling organize_enabled flag for a folder that doesn't belong to the user."""
|
||||
# Create a folder that belongs to a different user
|
||||
other_user = User(email='other@example.com', first_name='Other', last_name='User')
|
||||
other_user.set_password('password')
|
||||
|
||||
with app.app_context():
|
||||
db.session.add(other_user)
|
||||
db.session.commit()
|
||||
|
||||
# Create a folder for the other user
|
||||
other_folder = Folder(
|
||||
user_id=other_user.id,
|
||||
name='Other User Folder',
|
||||
rule_text='Test rule text'
|
||||
)
|
||||
db.session.add(other_folder)
|
||||
db.session.commit()
|
||||
|
||||
# Try to toggle the flag for the folder that doesn't belong to authenticated user
|
||||
response = authenticated_client.put(f'/api/folders/{other_folder.id}/toggle')
|
||||
|
||||
# Should return 404 Not Found (folder not found due to authorization check)
|
||||
assert response.status_code == 404
|
||||
Reference in New Issue
Block a user