@@ -328,6 +328,73 @@ def test_detail_not_found(self):
328328 views .organization_detail (request )
329329
330330
331+ class TestOrganizationActions :
332+ @pytest .mark .usefixtures ("_enable_organizations" )
333+ def test_rename_not_found (self , db_request ):
334+ admin = UserFactory .create ()
335+
336+ db_request .matchdict = {
337+ "organization_id" : "deadbeef-dead-beef-dead-beefdeadbeef"
338+ }
339+ db_request .params = {
340+ "new_organization_name" : "widget" ,
341+ }
342+ db_request .user = admin
343+ db_request .route_path = pretend .call_recorder (_organization_application_routes )
344+
345+ with pytest .raises (HTTPNotFound ):
346+ views .organization_rename (db_request )
347+
348+ @pytest .mark .usefixtures ("_enable_organizations" )
349+ def test_rename (self , db_request ):
350+ admin = UserFactory .create ()
351+ organization = OrganizationFactory .create (name = "example" )
352+
353+ db_request .matchdict = {"organization_id" : organization .id }
354+ db_request .params = {
355+ "new_organization_name" : "widget" ,
356+ }
357+ db_request .user = admin
358+ db_request .route_path = pretend .call_recorder (_organization_application_routes )
359+ db_request .session .flash = pretend .call_recorder (lambda * a , ** kw : None )
360+
361+ result = views .organization_rename (db_request )
362+
363+ assert db_request .session .flash .calls == [
364+ pretend .call (
365+ '"example" organization renamed "widget"' ,
366+ queue = "success" ,
367+ ),
368+ ]
369+ assert result .status_code == 303
370+ assert result .location == f"/admin/organizations/{ organization .id } /"
371+
372+ @pytest .mark .usefixtures ("_enable_organizations" )
373+ def test_rename_fails_on_conflict (self , db_request ):
374+ admin = UserFactory .create ()
375+ organization = OrganizationFactory .create (name = "widget" )
376+ organization = OrganizationFactory .create (name = "example" )
377+
378+ db_request .matchdict = {"organization_id" : organization .id }
379+ db_request .params = {
380+ "new_organization_name" : "widget" ,
381+ }
382+ db_request .user = admin
383+ db_request .route_path = pretend .call_recorder (_organization_application_routes )
384+ db_request .session .flash = pretend .call_recorder (lambda * a , ** kw : None )
385+
386+ result = views .organization_rename (db_request )
387+
388+ assert db_request .session .flash .calls == [
389+ pretend .call (
390+ 'Organization name "widget" has been used' ,
391+ queue = "error" ,
392+ ),
393+ ]
394+ assert result .status_code == 303
395+ assert result .location == f"/admin/organizations/{ organization .id } /"
396+
397+
331398class TestOrganizationApplicationList :
332399 @pytest .mark .usefixtures ("_enable_organizations" )
333400 def test_no_query (self , db_request ):
@@ -688,7 +755,7 @@ def _organization_application_routes(
688755 raise ValueError ("No dummy route found" )
689756
690757
691- class TestActions :
758+ class TestOrganizationApplicationActions :
692759 @pytest .mark .usefixtures ("_enable_organizations" )
693760 def test_approve (self , db_request ):
694761 admin = UserFactory .create ()
@@ -784,48 +851,6 @@ def _approve(*a, **kw):
784851 assert result .status_code == 303
785852 assert result .location == "/admin/"
786853
787- @pytest .mark .usefixtures ("_enable_organizations" )
788- def test_approve_wrong_confirmation_input (self , db_request ):
789- admin = UserFactory .create ()
790- user = UserFactory .create ()
791- organization_application = OrganizationApplicationFactory .create (
792- name = "example" , submitted_by = user
793- )
794- organization = OrganizationFactory .create (name = "example" )
795-
796- organization_service = pretend .stub (
797- get_organization_application = lambda * a , ** kw : organization_application ,
798- approve_organization_application = pretend .call_recorder (
799- lambda * a , ** kw : organization
800- ),
801- )
802-
803- db_request .matchdict = {
804- "organization_application_id" : organization_application .id
805- }
806- db_request .params = {"organization_name" : "incorrect" , "message" : "Welcome!" }
807- db_request .user = admin
808- db_request .route_path = pretend .call_recorder (_organization_application_routes )
809- db_request .find_service = pretend .call_recorder (
810- lambda iface , context : organization_service
811- )
812- db_request .session .flash = pretend .call_recorder (lambda * a , ** kw : None )
813-
814- result = views .organization_application_approve (db_request )
815-
816- assert organization_service .approve_organization_application .calls == []
817- assert db_request .session .flash .calls == [
818- pretend .call (
819- "Wrong confirmation input" ,
820- queue = "error" ,
821- ),
822- ]
823- assert result .status_code == 303
824- assert (
825- result .location
826- == f"/admin/organization_applications/{ organization_application .id } /"
827- )
828-
829854 @pytest .mark .usefixtures ("_enable_organizations" )
830855 def test_approve_not_found (self ):
831856 organization_service = pretend .stub (
@@ -1142,43 +1167,6 @@ def test_decline_turbo_mode(self, db_request):
11421167 == f"/admin/organization_applications/{ organization_application .id } /"
11431168 )
11441169
1145- @pytest .mark .usefixtures ("_enable_organizations" )
1146- def test_decline_wrong_confirmation_input (self , db_request ):
1147- admin = UserFactory .create ()
1148- user = UserFactory .create ()
1149- organization_application = OrganizationApplicationFactory .create (
1150- name = "example" , submitted_by = user
1151- )
1152-
1153- organization_service = pretend .stub (
1154- get_organization_application = lambda * a , ** kw : organization_application ,
1155- decline_organization_application = pretend .call_recorder (
1156- lambda * a , ** kw : organization_application
1157- ),
1158- )
1159-
1160- db_request .matchdict = {
1161- "organization_application_id" : organization_application .id
1162- }
1163- db_request .params = {"organization_name" : "incorrect" , "message" : "Welcome!" }
1164- db_request .user = admin
1165- db_request .route_path = pretend .call_recorder (_organization_application_routes )
1166- db_request .find_service = pretend .call_recorder (
1167- lambda iface , context : organization_service
1168- )
1169- db_request .session .flash = pretend .call_recorder (lambda * a , ** kw : None )
1170-
1171- result = views .organization_application_decline (db_request )
1172-
1173- assert db_request .session .flash .calls == [
1174- pretend .call ("Wrong confirmation input" , queue = "error" ),
1175- ]
1176- assert result .status_code == 303
1177- assert (
1178- result .location
1179- == f"/admin/organization_applications/{ organization_application .id } /"
1180- )
1181-
11821170 @pytest .mark .usefixtures ("_enable_organizations" )
11831171 def test_decline_not_found (self ):
11841172 organization_service = pretend .stub (
0 commit comments