@@ -589,8 +589,8 @@ def test_create_role_form_modal(auth_client_owner, test_organization):
589
589
590
590
# Check for modal elements
591
591
assert 'id="createRoleModal"' in response .text
592
- assert 'action="/roles/create"' in response .text
593
- assert 'method="post"' in response .text
592
+ assert 'action="http://testserver /roles/create"' in response .text
593
+ assert 'method="POST"' in response . text or 'method=" post"' in response .text
594
594
assert 'name="name"' in response .text
595
595
assert 'name="organization_id"' in response .text
596
596
assert f'value="{ test_organization .id } "' in response .text
@@ -607,47 +607,58 @@ def test_edit_role_form_modal(auth_client_owner, session, test_organization):
607
607
name = "Test Edit Role" ,
608
608
organization_id = test_organization .id
609
609
)
610
-
610
+
611
611
# Add some permissions
612
612
edit_permission = session .exec (
613
613
select (Permission ).where (Permission .name == ValidPermissions .EDIT_ROLE )
614
614
).first ()
615
615
invite_permission = session .exec (
616
616
select (Permission ).where (Permission .name == ValidPermissions .INVITE_USER )
617
617
).first ()
618
-
618
+
619
619
test_role .permissions .append (edit_permission )
620
620
test_role .permissions .append (invite_permission )
621
-
621
+
622
622
session .add (test_role )
623
623
session .commit ()
624
624
session .refresh (test_role )
625
-
625
+
626
+ # Verify DELETE_ROLE permission is NOT in the role's permissions before making request
627
+ role_permission_names = [p .name for p in test_role .permissions ]
628
+ assert ValidPermissions .DELETE_ROLE not in role_permission_names , "DELETE_ROLE should not be in permissions before test"
629
+
626
630
response = auth_client_owner .get (
627
631
f"/organizations/{ test_organization .id } " ,
628
632
follow_redirects = False
629
633
)
630
-
631
634
assert response .status_code == 200
632
-
635
+
633
636
# Check for modal elements
634
637
assert f'id="editRoleModal{ test_role .id } "' in response .text
635
- assert 'action="/roles/update"' in response .text
636
- assert 'method="post"' in response .text
638
+ assert 'action="http://testserver /roles/update"' in response .text
639
+ assert 'method="POST"' in response . text or 'method=" post"' in response .text
637
640
assert 'name="name"' in response .text
638
641
assert f'value="{ test_role .name } "' in response .text
639
642
assert 'name="id"' in response .text
640
643
assert f'value="{ test_role .id } "' in response .text
641
644
assert 'name="organization_id"' in response .text
642
645
assert f'value="{ test_organization .id } "' in response .text
643
-
646
+
644
647
# Check for permission checkboxes with correct checked state
645
648
for permission in ValidPermissions :
646
- assert permission .value in response .text
647
-
648
- # These should be checked
649
- assert f'value="{ ValidPermissions .EDIT_ROLE .value } " checked' in response .text
650
- assert f'value="{ ValidPermissions .INVITE_USER .value } " checked' in response .text
649
+ assert f'value="{ permission .value } "' in response .text
650
+
651
+ # These should be checked - use regex for robustness
652
+ edit_role_pattern = f'<input(?=[^>]*\\ svalue="{ re .escape (ValidPermissions .EDIT_ROLE .value )} ")(?=[^>]*\\ sid="perm_{ test_role .id } _{ re .escape (ValidPermissions .EDIT_ROLE .value .replace (" " , "_" ))} ")[^>]*\\ s+checked[^>]*>'
653
+ assert re .search (edit_role_pattern , response .text ) is not None , f"Checkbox for { ValidPermissions .EDIT_ROLE .value } should be checked"
654
+ invite_user_pattern = f'<input(?=[^>]*\\ svalue="{ re .escape (ValidPermissions .INVITE_USER .value )} ")(?=[^>]*\\ sid="perm_{ test_role .id } _{ re .escape (ValidPermissions .INVITE_USER .value .replace (" " , "_" ))} ")[^>]*\\ s+checked[^>]*>'
655
+ assert re .search (invite_user_pattern , response .text ) is not None , f"Checkbox for { ValidPermissions .INVITE_USER .value } should be checked"
656
+
657
+ # Check for one that should NOT be checked
658
+ delete_role_pattern = f'<input(?=[^>]*\\ svalue="{ re .escape (ValidPermissions .DELETE_ROLE .value )} ")(?=[^>]*\\ sid="perm_{ test_role .id } _{ re .escape (ValidPermissions .DELETE_ROLE .value .replace (" " , "_" ))} ")[^>]*\\ s+checked[^>]*>'
659
+ delete_match = re .search (delete_role_pattern , response .text )
660
+
661
+ assert delete_match is None , f"Checkbox for { ValidPermissions .DELETE_ROLE .value } should NOT be checked"
651
662
652
663
653
664
def test_delete_role_form (auth_client_owner , session , test_organization ):
@@ -669,8 +680,8 @@ def test_delete_role_form(auth_client_owner, session, test_organization):
669
680
assert response .status_code == 200
670
681
671
682
# Check for delete form elements
672
- assert 'action="/roles/delete"' in response .text
673
- assert 'method="post"' in response .text
683
+ assert 'action="http://testserver /roles/delete"' in response .text
684
+ assert 'method="POST"' in response . text or 'method=" post"' in response .text
674
685
assert 'name="id"' in response .text
675
686
assert f'value="{ test_role .id } "' in response .text
676
687
assert 'name="organization_id"' in response .text
0 commit comments