def delete_tenant(self, request_user: UserModel, tenant: TenantModel): self.logger.info("START: delete_tenant") if not request_user.can_control_tenant(): raise InvalidRoleException( "request user can't create tenant. id:{}".format( request_user.id)) tenant.delete() self.logger.info("END: delete_tenant")
def test_create_tenant_master(self, tenant_serializer, user_serializer, usecase): # MASTERユーザーで認証 api_client = APIClient() api_client.force_authenticate(user=UserModel.objects.get( email="master_email")) # 作成するテナント data = dict(tenant=dict(tenant_name='test_tenant', email='*****@*****.**', tel='03-1234-1234'), user=dict(name="test_user", email="*****@*****.**")) usecase.return_value.create_tenant.return_value = ( TenantModel(tenant_name="test_tenant", email="*****@*****.**", tel='03-1234-1234'), UserModel(email="*****@*****.**", name="test_user")) usecase.return_value.create_tenant.return_value = (mock.Mock( spec=TenantModel), mock.Mock(spec=UserModel)) tenant_serializer.return_value.data = "TEST" user_serializer.return_value.data = "TEST" # Company1の情報を取得 response = api_client.post(self.api_path_in_tenant, data=data, format='json') self.assertEqual(response.status_code, 201)
def create_tenant(self, request_user: UserModel, tenant: TenantModel, user: UserModel): self.logger.info("START: create_tenant") # 作成できるロールを持つか if not request_user.can_control_tenant(): raise InvalidRoleException( "request user can't create tenant. id:{}".format( request_user.id)) # テナント追加 tenant.save() # スケジューラーを登録する scheduler = UserModel( email=tenant.email, name="SCHEDULER", tenant=tenant, role=RoleModel.objects.get(id=RoleModel.SCHEDULER_ID), ) scheduler.reset_password() scheduler.save() # ユーザー追加 user.tenant = tenant # ランダムパスワード設定 password = user.reset_password() user.save() # 新規登録メール送信 self.logger.info("sending sign up email...") self.logger.debug( "user_email: {}, user_name: {}, tenant_name: {}".format( user.email, user.name, tenant.tenant_name)) ses = Ses(settings.SES_ADDRESS, settings.SES_ADDRESS) ses.send_signup_user(user.email, user.name, tenant.tenant_name, password) self.logger.info("sending sign up email... : DONE") self.logger.info("END: create_tenant") return tenant, user