Skip to content

Commit 7c765a3

Browse files
chore: Lint test_commands
1 parent 71e4867 commit 7c765a3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

tests/test_commands.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
from pathlib import Path
66
from unittest.mock import patch
77

8-
import pytest
9-
import yaml
108
from django.core.management import call_command
119
from django.core.management.base import CommandError
10+
11+
import pytest
12+
import yaml
1213
from model_bakery import baker
1314

1415
from django_postgres_anon.models import MaskedRole, MaskingLog, MaskingPreset, MaskingRule
@@ -744,25 +745,26 @@ def test_command_permissions():
744745
@pytest.mark.django_db
745746
def test_anon_fix_permissions_command():
746747
"""Test anon_fix_permissions management command"""
748+
from unittest.mock import MagicMock, patch
749+
747750
from django_postgres_anon.models import MaskedRole
748-
from unittest.mock import patch, MagicMock
749751

750752
# Test with no arguments (should show error)
751-
with patch('sys.stdout', new_callable=MagicMock) as mock_stdout:
753+
with patch("sys.stdout", new_callable=MagicMock) as mock_stdout:
752754
call_command("anon_fix_permissions")
753755
output = str(mock_stdout.write.call_args_list)
754756
assert "Please specify" in output or "--role" in output
755757

756758
# Test with --role option
757-
with patch('django_postgres_anon.management.commands.anon_fix_permissions.create_masked_role') as mock_create:
759+
with patch("django_postgres_anon.management.commands.anon_fix_permissions.create_masked_role") as mock_create:
758760
mock_create.return_value = True
759-
with patch('sys.stdout', new_callable=MagicMock):
761+
with patch("sys.stdout", new_callable=MagicMock):
760762
call_command("anon_fix_permissions", "--role", "test_role")
761763
mock_create.assert_called_once_with("test_role")
762764

763765
# Test with --all option when no roles exist
764766
MaskedRole.objects.all().delete()
765-
with patch('sys.stdout', new_callable=MagicMock) as mock_stdout:
767+
with patch("sys.stdout", new_callable=MagicMock) as mock_stdout:
766768
call_command("anon_fix_permissions", "--all")
767769
# Should show warning about no roles
768770
output = str(mock_stdout.write.call_args_list)
@@ -772,18 +774,18 @@ def test_anon_fix_permissions_command():
772774
MaskedRole.objects.create(role_name="test_role_1")
773775
MaskedRole.objects.create(role_name="test_role_2")
774776

775-
with patch('django_postgres_anon.management.commands.anon_fix_permissions.create_masked_role') as mock_create:
777+
with patch("django_postgres_anon.management.commands.anon_fix_permissions.create_masked_role") as mock_create:
776778
mock_create.return_value = True
777-
with patch('sys.stdout', new_callable=MagicMock) as mock_stdout:
779+
with patch("sys.stdout", new_callable=MagicMock) as mock_stdout:
778780
call_command("anon_fix_permissions", "--all")
779781
assert mock_create.call_count == 2
780782
mock_create.assert_any_call("test_role_1")
781783
mock_create.assert_any_call("test_role_2")
782784

783785
# Test with failed permission fix
784-
with patch('django_postgres_anon.management.commands.anon_fix_permissions.create_masked_role') as mock_create:
786+
with patch("django_postgres_anon.management.commands.anon_fix_permissions.create_masked_role") as mock_create:
785787
mock_create.return_value = False
786-
with patch('sys.stdout', new_callable=MagicMock) as mock_stdout:
788+
with patch("sys.stdout", new_callable=MagicMock) as mock_stdout:
787789
call_command("anon_fix_permissions", "--role", "failing_role")
788790
output = str(mock_stdout.write.call_args_list)
789791
assert "Failed" in output or "failed" in output.lower()

0 commit comments

Comments
 (0)