@@ -520,6 +520,10 @@ def test_organization_radsettings_freeradius_allowed_hosts(self):
520520 "radius_settings-0-id" : radsetting .pk ,
521521 "radius_settings-0-organization" : org .pk ,
522522 "radius_settings-0-password_reset_url" : PASSWORD_RESET_URL ,
523+ "notification_settings-TOTAL_FORMS" : 0 ,
524+ "notification_settings-INITIAL_FORMS" : 0 ,
525+ "notification_settings-MIN_NUM_FORMS" : 0 ,
526+ "notification_settings-MAX_NUM_FORMS" : 1 ,
523527 }
524528 )
525529
@@ -602,6 +606,10 @@ def test_organization_radsettings_password_reset_url(self):
602606 "radius_settings-0-id" : radsetting .pk ,
603607 "radius_settings-0-organization" : org .pk ,
604608 "radius_settings-0-password_reset_url" : PASSWORD_RESET_URL ,
609+ "notification_settings-TOTAL_FORMS" : 0 ,
610+ "notification_settings-INITIAL_FORMS" : 0 ,
611+ "notification_settings-MIN_NUM_FORMS" : 0 ,
612+ "notification_settings-MAX_NUM_FORMS" : 1 ,
605613 }
606614 )
607615
@@ -1212,6 +1220,10 @@ def test_organization_radsettings_allowed_mobile_prefixes(self):
12121220 "radius_settings-0-id" : radsetting .pk ,
12131221 "radius_settings-0-organization" : org .pk ,
12141222 "radius_settings-0-password_reset_url" : PASSWORD_RESET_URL ,
1223+ "notification_settings-TOTAL_FORMS" : 0 ,
1224+ "notification_settings-INITIAL_FORMS" : 0 ,
1225+ "notification_settings-MIN_NUM_FORMS" : 0 ,
1226+ "notification_settings-MAX_NUM_FORMS" : 1 ,
12151227 }
12161228 )
12171229
@@ -1289,6 +1301,10 @@ def test_organization_radsettings_sms_message(self):
12891301 "radius_settings-0-id" : radsetting .pk ,
12901302 "radius_settings-0-organization" : org .pk ,
12911303 "radius_settings-0-password_reset_url" : PASSWORD_RESET_URL ,
1304+ "notification_settings-TOTAL_FORMS" : 0 ,
1305+ "notification_settings-INITIAL_FORMS" : 0 ,
1306+ "notification_settings-MIN_NUM_FORMS" : 0 ,
1307+ "notification_settings-MAX_NUM_FORMS" : 1 ,
12921308 "_continue" : True ,
12931309 }
12941310 )
@@ -1495,30 +1511,56 @@ def test_admin_menu_groups(self):
14951511 html = '<div class="mg-dropdown-label">RADIUS </div>'
14961512 self .assertContains (response , html , html = True )
14971513
1498- def test_radiusbatch_organization_readonly_for_existing_objects (self ):
1499- """
1500- Test that organization field is readonly for existing RadiusBatch objects
1501- """
1502- batch = self ._create_radius_batch (
1503- name = "test-batch" , strategy = "prefix" , prefix = "test-prefix"
1504- )
1505- url = reverse (f"admin:{ self .app_label } _radiusbatch_change" , args = [batch .pk ])
1506-
1507- response = self .client .get (url )
1508- self .assertEqual (response .status_code , 200 )
15091514
1510- self .assertContains (response , "readonly" )
1511- self .assertContains (response , batch .organization .name )
1515+ class TestRadiusGroupAdmin (BaseTestCase ):
1516+ def setUp (self ):
1517+ self .organization = self ._create_org ()
1518+ self .admin = self ._create_admin ()
1519+ self .organization .add_user (self .admin , is_admin = True )
1520+ self .client .force_login (self .admin )
1521+
1522+ def test_add_radiusgroup_with_inline_check_succeeds (self ):
1523+ add_url = reverse ("admin:openwisp_radius_radiusgroup_add" )
1524+
1525+ post_data = {
1526+ # Main RadiusGroup form
1527+ "organization" : self .organization .pk ,
1528+ "name" : "test-group-with-inline" ,
1529+ "description" : "A test group created with an inline check" ,
1530+ # Inline RadiusGroupCheck formset
1531+ "radiusgroupcheck_set-TOTAL_FORMS" : "1" ,
1532+ "radiusgroupcheck_set-INITIAL_FORMS" : "0" ,
1533+ "radiusgroupcheck_set-0-attribute" : "Max-Daily-Session" ,
1534+ "radiusgroupcheck_set-0-op" : ":=" ,
1535+ "radiusgroupcheck_set-0-value" : "3600" ,
1536+ # Inline RadiusGroupReply formset
1537+ "radiusgroupreply_set-TOTAL_FORMS" : "1" ,
1538+ "radiusgroupreply_set-INITIAL_FORMS" : "0" ,
1539+ "radiusgroupreply_set-0-attribute" : "Session-Timeout" ,
1540+ "radiusgroupreply_set-0-op" : "=" ,
1541+ "radiusgroupreply_set-0-value" : "1800" ,
1542+ }
15121543
1513- def test_radiusbatch_organization_editable_for_new_objects (self ):
1514- """
1515- Test that organization field is editable for new RadiusBatch objects
1516- """
1517- url = reverse (f"admin:{ self .app_label } _radiusbatch_add" )
1544+ response = self .client .post (add_url , data = post_data , follow = True )
15181545
1519- response = self .client .get (url )
15201546 self .assertEqual (response .status_code , 200 )
1521-
1522- self .assertContains (response , 'name="organization"' )
1523- form_html = response .content .decode ()
1524- self .assertIn ('name="organization"' , form_html )
1547+ final_group_name = f"{ self .organization .slug } -test-group-with-inline"
1548+
1549+ self .assertContains (response , "The group" )
1550+ self .assertContains (response , f"{ final_group_name } </a>" )
1551+ self .assertContains (response , "was added successfully." )
1552+
1553+ self .assertTrue (RadiusGroup .objects .filter (name = final_group_name ).exists ())
1554+ group = RadiusGroup .objects .get (name = final_group_name )
1555+
1556+ self .assertEqual (group .radiusgroupcheck_set .count (), 1 )
1557+ check = group .radiusgroupcheck_set .first ()
1558+ self .assertEqual (check .attribute , "Max-Daily-Session" )
1559+ self .assertEqual (check .value , "3600" )
1560+ self .assertEqual (check .groupname , group .name )
1561+
1562+ self .assertEqual (group .radiusgroupreply_set .count (), 1 )
1563+ reply = group .radiusgroupreply_set .first ()
1564+ self .assertEqual (reply .attribute , "Session-Timeout" )
1565+ self .assertEqual (reply .value , "1800" )
1566+ self .assertEqual (reply .groupname , group .name )
0 commit comments