@@ -1351,11 +1351,16 @@ def test_authz_scope_handles_empty_scopes(self):
13511351 ContentLibrary .objects .filter (slug = "empty-lib" )
13521352 )
13531353
1354- self .assertEqual (filtered .count (), 0 ,
1355- "Should return 0 libraries when user has no authorized scopes" )
1354+ self .assertEqual (
1355+ filtered .count (),
1356+ 0 ,
1357+ "Should return 0 libraries when user has no authorized scopes" ,
1358+ )
13561359
1357- self .assertTrue (ContentLibrary .objects .filter (slug = "empty-lib" ).exists (),
1358- "Library should exist in database" )
1360+ self .assertTrue (
1361+ ContentLibrary .objects .filter (slug = "empty-lib" ).exists (),
1362+ "Library should exist in database" ,
1363+ )
13591364
13601365 def test_authz_scope_q_object_has_correct_structure (self ):
13611366 """
@@ -1386,31 +1391,52 @@ def test_authz_scope_q_object_has_correct_structure(self):
13861391 self .assertIsInstance (q_obj , Q )
13871392
13881393 # Test 2: Verify Q object uses OR connector (for multiple scopes)
1389- self .assertEqual (q_obj .connector , 'OR' ,
1390- "Should use OR to combine different library scopes" )
1394+ self .assertEqual (
1395+ q_obj .connector ,
1396+ 'OR' ,
1397+ "Should use OR to combine different library scopes" ,
1398+ )
13911399
13921400 # Test 3: Verify the Q object string contains the exact fields and values
13931401 q_str = str (q_obj )
13941402
13951403 # Should filter by org__short_name field
1396- self .assertIn ("org__short_name" , q_str ,
1397- "Q object must filter by org__short_name field" )
1404+ self .assertIn (
1405+ "org__short_name" ,
1406+ q_str ,
1407+ "Q object must filter by org__short_name field" ,
1408+ )
13981409
13991410 # Should filter by slug field
1400- self .assertIn ("slug" , q_str ,
1401- "Q object must filter by slug field" )
1411+ self .assertIn (
1412+ "slug" ,
1413+ q_str ,
1414+ "Q object must filter by slug field" ,
1415+ )
14021416
14031417 # Should contain exact org values
1404- self .assertIn ("specific-org1" , q_str ,
1405- "Q object must include 'specific-org1'" )
1406- self .assertIn ("specific-org2" , q_str ,
1407- "Q object must include 'specific-org2'" )
1418+ self .assertIn (
1419+ "specific-org1" ,
1420+ q_str ,
1421+ "Q object must include 'specific-org1'" ,
1422+ )
1423+ self .assertIn (
1424+ "specific-org2" ,
1425+ q_str ,
1426+ "Q object must include 'specific-org2'" ,
1427+ )
14081428
14091429 # Should contain exact slug values
1410- self .assertIn ("specific-slug1" , q_str ,
1411- "Q object must include 'specific-slug1'" )
1412- self .assertIn ('specific-slug2' , q_str ,
1413- "Q object must include 'specific-slug2'" )
1430+ self .assertIn (
1431+ "specific-slug1" ,
1432+ q_str ,
1433+ "Q object must include 'specific-slug1'" ,
1434+ )
1435+ self .assertIn (
1436+ 'specific-slug2' ,
1437+ q_str ,
1438+ "Q object must include 'specific-slug2'" ,
1439+ )
14141440
14151441 def test_authz_scope_q_object_matches_exact_org_slug_pairs (self ):
14161442 """
@@ -1457,34 +1483,52 @@ def test_authz_scope_q_object_matches_exact_org_slug_pairs(self):
14571483 filtered = ContentLibrary .objects .filter (q_obj )
14581484
14591485 # TEST: Verify EXACTLY 2 libraries match (lib1 and lib2 only)
1460- self .assertEqual (filtered .count (), 2 ,
1461- "Must match EXACTLY 2 libraries - only those with authorized (org, slug) pairs" )
1486+ self .assertEqual (
1487+ filtered .count (),
1488+ 2 ,
1489+ "Must match EXACTLY 2 libraries - only those with authorized (org, slug) pairs" ,
1490+ )
14621491
14631492 # TEST: Verify lib1 matches (pair-org1, pair-lib1)
14641493 lib1_result = filtered .filter (slug = 'pair-lib1' , org__short_name = 'pair-org1' )
1465- self .assertEqual (lib1_result .count (), 1 ,
1466- "Must match lib1: (pair-org1, pair-lib1) - this exact pair is authorized" )
1494+ self .assertEqual (
1495+ lib1_result .count (),
1496+ 1 ,
1497+ "Must match lib1: (pair-org1, pair-lib1) - this exact pair is authorized" ,
1498+ )
14671499
14681500 # TEST: Verify lib2 matches (pair-org2, pair-lib2)
14691501 lib2_result = filtered .filter (slug = 'pair-lib2' , org__short_name = 'pair-org2' )
1470- self .assertEqual (lib2_result .count (), 1 ,
1471- "Must match lib2: (pair-org2, pair-lib2) - this exact pair is authorized" )
1502+ self .assertEqual (
1503+ lib2_result .count (),
1504+ 1 ,
1505+ "Must match lib2: (pair-org2, pair-lib2) - this exact pair is authorized" ,
1506+ )
14721507
14731508 # TEST: Verify lib3 does NOT match (pair-org1, pair-lib3)
14741509 lib3_result = filtered .filter (slug = 'pair-lib3' , org__short_name = 'pair-org1' )
1475- self .assertEqual (lib3_result .count (), 0 ,
1476- "Must NOT match lib3: (pair-org1, pair-lib3) - only pair-lib1 is authorized for pair-org1" )
1510+ self .assertEqual (
1511+ lib3_result .count (),
1512+ 0 ,
1513+ "Must NOT match lib3: (pair-org1, pair-lib3) - only pair-lib1 is authorized for pair-org1" ,
1514+ )
14771515
14781516 # TEST: Verify lib4 does NOT match (pair-org3, pair-lib1)
14791517 lib4_result = filtered .filter (slug = 'pair-lib1' , org__short_name = 'pair-org3' )
1480- self .assertEqual (lib4_result .count (), 0 ,
1481- "Must NOT match lib4: (pair-org3, pair-lib1) - only pair-org1 is authorized for pair-lib1" )
1518+ self .assertEqual (
1519+ lib4_result .count (),
1520+ 0 ,
1521+ "Must NOT match lib4: (pair-org3, pair-lib1) - only pair-org1 is authorized for pair-lib1" ,
1522+ )
14821523
14831524 # TEST: Verify the result set contains exactly the right libraries
14841525 result_pairs = set (filtered .values_list ('org__short_name' , 'slug' ))
14851526 expected_pairs = {('pair-org1' , 'pair-lib1' ), ('pair-org2' , 'pair-lib2' )}
1486- self .assertEqual (result_pairs , expected_pairs ,
1487- f"Result must contain exactly { expected_pairs } , got { result_pairs } " )
1527+ self .assertEqual (
1528+ result_pairs ,
1529+ expected_pairs ,
1530+ f"Result must contain exactly { expected_pairs } , got { result_pairs } " ,
1531+ )
14881532
14891533
14901534@ddt .ddt
0 commit comments