ARTICLE DETAIL

资讯详情

深耕编程入门与网站建设的一线实战洞察。

YourIntegration

YourIntegration YourIntegration【免费下载链接】recipesApplication for managing recipes, planning meals, building shopping lists and much much more!项目地址: https://gitcode.com/GitHub_Trending/re/recipesa little blurb about how it works or anything users should know about how the data needs to be formatted.同时建议把新集成补充到文档顶部的集成能力总表| Integration | Import | Export | Images | 四列表格中如实标记导入/导出/图片支持状态也可以等集成充分测试后再更新表格。 ## 步骤五注册 Vue 前端 在 [vue3/src/utils/integration_utils.ts](https://link.gitcode.com/i/8c4c7cb372665b288c2cba544ec6920f) 中找到 export const INTEGRATIONS: ArrayIntegration在长列表中新增一行 ts {id: YOURINTEGRATION, name: Your Integration, import: true, export: false, helpUrl: https://docs.tandoor.dev/features/import_export/#yourintegration},其中id必须与 forms.py 中的全大写类型常量一致import/export为布尔值true表示该集成会出现在导入或导出菜单中按你的集成实际支持能力填写helpUrl指向文档锚点形如.../import_export/#yourintegration对应步骤四中创建的章节。仓库现有条目如CHEFTAP、COOKLANG、PESTLE可作参照。修改之后需要用yarn重新构建前端确保生成的 HTML 文件同步更新。为集成编写测试Tandoor 使用 Pytest 进行测试。测试文件放在cookbook/tests/other/目录下新建test_yourintegration.py即可——文件名必须以test_开头这是 pytest 发现测试的约定。用于解析的样例数据文件则放在 cookbook/tests/other/test_data/ 下建议建立你自己的子目录如your_integration/在测试中引用样例文件时路径要从cookbook/起写全仓库现有的 Cooklang 样例位于cookbook/tests/other/test_data/Cooklang/测试中即以cookbook/tests/other/test_data/Cooklang/xxx.cook形式引用见 cookbook/tests/other/test_cooklang_integration.py。生成带 request 的集成对象集成类是Integration的子类构造时必须传入request和export_type两个参数。export_type只要是一个字符串即可官方示例惯例使用export而request需要借助 Django 的RequestFactory与项目自带的u1_s1fixture 构造。官方给出的测试模板如下from io import BytesIO from django.contrib import auth from django.test import RequestFactory from django_scopes import scope from cookbook.integration.cooklang import YourIntegrationClass def test_yourintegration(u1_s1): user auth.get_user(u1_s1) space user.userspace_set.first().space request RequestFactory() request.user user request.space space with scope(spacespace): integration_object YourIntegrationClass(request, export) with open(cookbook/tests/other/test_data/your_integration/recipe_file.txt, rb) as file: recipe_bytes file.read() recipe_name file.name buffer BytesIO(recipe_bytes) buffer.name recipe_name recipe_object integration_object.get_recipe_from_file(buffer) # all of your test function logic inside this with clause说明u1_s1是项目预置的 pytest fixture作为测试函数参数传入后可用auth.get_user(u1_s1)取出测试用户再通过user.userspace_set.first().space拿到测试空间RequestFactory()构造出的 request 需要手动挂上user和space属性这正是Integration.__init__和导入逻辑所依赖的整个逻辑必须包裹在with scope(spacespace):中因为项目使用django-scopes做空间级数据隔离模型操作离开该作用域会抛错。测试函数名同样必须以test_开头才会被执行——这也是在测试文件里定义辅助函数时的关键约定非test_前缀的函数不会被当作测试运行。拿到recipe_object后即可针对它的name、steps、keywords、各步骤的ingredients等断言解析结果。真实测试样例仓库的 cookbook/tests/other/test_cooklang_integration.py 是这套测试范式的完整实践它先定义一个request_generator(u1_s1)辅助函数复用 request 构造逻辑再在test_cooklang_integration中读取.cook样例、调用get_recipe_from_file随后逐项断言元数据name、description、servings、keywords、working_time等、每个步骤的指令文本以及每个步骤关联的配料三元组(food, amount, unit)space, request request_generator(u1_s1) with scope(spacespace): cooklang_integration Cooklang(request, export) with open(cookbook/tests/other/test_data/Cooklang/Butter Swirl Shortbread Cookies.cook, rb) as file: recipe_bytes file.read() recipe_name file.name buffer BytesIO(recipe_bytes) buffer.name recipe_name recipe cooklang_integration.get_recipe_from_file(buffer) # 断言元数据、步骤文本、步骤配料 ...【免费下载链接】recipesApplication for managing recipes, planning meals, building shopping lists and much much more!项目地址: https://gitcode.com/GitHub_Trending/re/recipes创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表