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)
评论列表
文章目录