File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed
source/app/blueprints/rest/v2/manage_routes Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 2626from app .blueprints .rest .endpoints import response_api_not_found
2727from app .blueprints .rest .endpoints import response_api_deleted
2828from app .blueprints .access_controls import ac_api_requires
29+ from app .datamgmt .exceptions .ElementExceptions import ElementInUseException
2930from app .models .authorization import Permissions
3031from app .schema .marshables import CustomerSchema
3132from app .business .errors import ObjectNotFoundError
@@ -81,7 +82,8 @@ def delete(self, identifier):
8182
8283 except ObjectNotFoundError :
8384 return response_api_not_found ()
84-
85+ except ElementInUseException as e :
86+ return response_api_error ('Cannot delete a referenced customer' )
8587
8688customers_blueprint = Blueprint ('customers_rest_v2' , __name__ , url_prefix = '/customers' )
8789
Original file line number Diff line number Diff line change @@ -104,11 +104,11 @@ def create_dummy_customer(self) -> int:
104104 response = self .create ('/manage/customers/add' , {'customer_name' : f'customer{ uuid4 ()} ' }).json ()
105105 return response ['data' ]['customer_id' ]
106106
107- def create_dummy_case (self ):
107+ def create_dummy_case (self , customer_identifier = IRIS_INITIAL_CUSTOMER_IDENTIFIER ):
108108 body = {
109109 'case_name' : 'case name' ,
110110 'case_description' : 'description' ,
111- 'case_customer_id' : 1 ,
111+ 'case_customer_id' : customer_identifier ,
112112 'case_soc_id' : ''
113113 }
114114 response = self ._api .post ('/api/v2/cases' , body ).json ()
Original file line number Diff line number Diff line change @@ -141,3 +141,17 @@ def test_delete_customer_should_return_204(self):
141141
142142 response = self ._subject .delete (f'/api/v2/manage/customers/{ identifier } ' )
143143 self .assertEqual (204 , response .status_code )
144+
145+ def test_delete_customer_should_return_400_when_referenced_by_a_customer (self ):
146+ body = {'customer_name' : 'customer' }
147+ response = self ._subject .create ('/api/v2/manage/customers' , body ).json ()
148+ identifier = response ['customer_id' ]
149+
150+ self ._subject .create_dummy_case (identifier )
151+
152+ # TODO currently, to remove a customer, no user should have any access to it. I am not sure this is the optimum behavior.
153+ body = {'customers_membership' : [IRIS_INITIAL_CUSTOMER_IDENTIFIER ]}
154+ self ._subject .create (f'/manage/users/{ ADMINISTRATOR_USER_IDENTIFIER } /customers/update' , body )
155+
156+ response = self ._subject .delete (f'/api/v2/manage/customers/{ identifier } ' )
157+ self .assertEqual (400 , response .status_code )
You can’t perform that action at this time.
0 commit comments