小编Win*_*ech的帖子

Assert_used_once_with 需要检查调用中的实例是否具有相同的信息

我正在尝试使用来自unittest.mock的assert_used_once_with https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_ Called_once_with

但我想检查是否已通过正确的属性传递了两个对象实例。

所以在类中我重写了__eq__func:

    def __eq__(self, other):
        return (
            self.id == other.id
            and self.users == other.users
        )
Run Code Online (Sandbox Code Playgroud)

在我这样使用的代码中

        mock_add_user.assert_called_once_with(context_fix, expected_user_obj1, expected_user_obj2, users)

Run Code Online (Sandbox Code Playgroud)

但我不断收到错误,并且测试人员不断比较实例的 repr,如下所示

<app.domain.model.load_md.Load object at 0x10cb7d7d0>
Run Code Online (Sandbox Code Playgroud)
<app.domain.model.load_md.Load object at 0x10cb7d7d0>
Run Code Online (Sandbox Code Playgroud)

我确实需要一种方法来断言对象的实例是否已作为填充了正确属性的函数的参数传递。

python mocking pytest python-unittest

8
推荐指数
1
解决办法
5284
查看次数

使用 typeorm 在 postgres 中搜索数组中的项目

数据库:postgres

\n

ORM:类型

\n

框架:express.js

\n

我有一个表,其中一个名为 name 的字段projects是一个字符串数组。类型"varchar"在迁移中设置为 ,装饰器设置为"simple-array"

\n

在我的获取路线中,如果我收到查询,?project=name_of_the_project它应该尝试在简单数组中查找项目。

\n

对于搜索我的获取路线是这样的:

\n
studentsRouter.get("/", async (request, response) => {\n    const { project } = request.query;\n    const studentRepository = getCustomRepository(StudentRepository);\n    const students = project\n        ? await studentRepository\n                .createQueryBuilder("students")\n                .where(":project = ANY (students.projects)", { project: project })\n                .getMany()\n        : await studentRepository.find();\n    // const students = await studentRepository.find();\n    return response.json(students);\n}); \n
Run Code Online (Sandbox Code Playgroud)\n

问题是 I\xc2\xb4m 收到错误,指出右侧应该是一个数组。

\n
(node:38971) UnhandledPromiseRejectionWarning: QueryFailedError: op …
Run Code Online (Sandbox Code Playgroud)

postgresql node.js express typescript typeorm

5
推荐指数
1
解决办法
6481
查看次数