test_restgateway.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:floranet 作者: Fluent-networks 项目源码 文件源码
def test_put(self):
        """Test put method"""

        gateway = self._test_gateway()
        mockDBObject.return_value = gateway

        with patch.object(reqparse.RequestParser, 'parse_args'):
            resource = RestGateway(restapi=self.restapi, server=self.server)

            # Fail to find the gateway: raises 404 NotFound
            with patch.object(Gateway, 'find', classmethod(mockDBObject.findFail)):
                yield self.assertFailure(resource.put(gateway.host), e.NotFound)

            # Find a device, device fails validity check: raises 400 BadRequest
            with patch.object(Gateway, 'find', classmethod(mockDBObject.findSuccess)):
                gateway.valid = MagicMock(return_value=(False, {}))
                yield self.assertFailure(resource.put(gateway.host), e.BadRequest)

                # Pass validity check, returns 200
                expected = ({}, 200)
                gateway.valid = MagicMock(return_value=(True, {}))
                gateway.update = MagicMock()
                result = yield resource.put(gateway.host)
                self.assertEqual(expected, result)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号