def proof_of_enrollment_uploaded(self) -> bool: possible_filenames = [f"{self.id}.{ext}" for ext in SUPPORTED_FILE_EXTENSIONS] proof_of_enrollment_path = util.get_proof_of_enrollment_path() possible_proof_of_enrollment_file_paths = [ (proof_of_enrollment_path / filename) for filename in possible_filenames ] return any(path.exists() for path in possible_proof_of_enrollment_file_paths)
def profile_percentage(self) -> float: result = 0 possible_filenames = [f"{self.id}.{ext}" for ext in SUPPORTED_FILE_EXTENSIONS] copy_id_path = util.get_copy_ids_path() possible_copy_id_file_paths = [ (copy_id_path / filename) for filename in possible_filenames ] proof_of_income_path = util.get_proof_of_income_path() possible_proof_of_income_file_paths = [ (proof_of_income_path / filename) for filename in possible_filenames ] proof_of_enrollment_path = util.get_proof_of_enrollment_path() possible_proof_of_enrollment_file_paths = [ (proof_of_enrollment_path / filename) for filename in possible_filenames ] if any(path.exists() for path in possible_copy_id_file_paths): result += 20 if any(path.exists() for path in possible_proof_of_income_file_paths): result += 10 if any(path.exists() for path in possible_proof_of_enrollment_file_paths): result += 10 if self.social_accounts: result += 10 assert result <= 100 return result
def test_landlord_percentage_profile(landlord: Landlord, file, application: Application, clear_upload): copy_id_path = util.get_copy_ids_path() proof_of_income_path = util.get_proof_of_income_path() proof_of_enrollment_path = util.get_proof_of_enrollment_path() paths = [copy_id_path, proof_of_income_path, proof_of_enrollment_path] assert all(not application.file_service.list_files(path) for path in paths) assert landlord.profile_percentage == 0 application.upload_copy_id(landlord, file, "pdf") assert landlord.profile_percentage == 30
def test_tenant_percentage_profile(tenant: Tenant, file, application: Application, clear_upload): copy_id_path = util.get_copy_ids_path() proof_of_income_path = util.get_proof_of_income_path() proof_of_enrollment_path = util.get_proof_of_enrollment_path() paths = [copy_id_path, proof_of_income_path, proof_of_enrollment_path] assert all(not application.file_service.list_files(path) for path in paths) assert tenant.profile_percentage == 0 application.upload_copy_id(tenant, file, "pdf") assert tenant.profile_percentage == 20 application.upload_proof_of_enrollment(tenant, file, "pdf") assert tenant.profile_percentage == 30 application.upload_proof_of_income(tenant, file, "pdf") assert tenant.profile_percentage == 40
def download_proof_of_enrollment( tenant: Tenant = Depends(deps.get_current_active_tenant), ): """ Download user proof of enrollment """ possible_filenames = [ f"{tenant.id}.{ext}" for ext in config.SUPPORTED_FILE_EXTENSIONS ] folder_path = get_proof_of_enrollment_path() for filename in possible_filenames: file_path: Path = folder_path / filename if file_path.exists(): with open(file_path, "rb") as f: return Response( f.read(), media_type="application/octet-stream", headers={ "Content-Disposition": f"attachment;filename={filename}" }, )
def upload_proof_of_enrollment(self, user: User, file: IO, extension: str) -> Tenant: return self.__upload_file(user, file, extension, util.get_proof_of_enrollment_path())