首页 \ 问答 \ 如何测试进行重定向的帮助程序Grok视图(How to test a helper Grok view that makes a redirect)

如何测试进行重定向的帮助程序Grok视图(How to test a helper Grok view that makes a redirect)

我有一个内容类型需要在调用帮助Grok视图后以某种方式进行修改,该视图检查某些条件,进行一些更改,设置消息并重定向到原始对象。

我的帮助器视图只有一个render方法,我想为它编写一些测试,但我不知道如何处理它。

我想检查一些条件不满足时的错误消息,以及一切正常时的信息消息。

我的代码看起来像这样:

class MyHelperView(grok.View):

    grok.context(IMyType)
    grok.layer(IMyLayer)
    grok.name('helper-view')
    grok.require('my.permission')

    def render(self):
        variable = self.request.form.get('variable', None)
        if not variable:
            msg = _(u'Required input is missing.')
            api.portal.show_message(message=msg, request=self.request, type='error')
        else:
            do_something()
            msg = _(u'Information processed.')
            api.portal.show_message(message=msg, request=self.request)
        self.request.response.redirect(self.context.absolute_url())

当我调用视图时,显然我以一个None对象结束,因为视图没有返回任何内容。 我不知道在哪里寻找消息......请求? 响应? 任何提示?


I have a content type that needs to be modified in some way after calling a helper Grok view that checks some condition, makes some changes, sets a message and redirects to the original object.

my helper view only has a render method and I want to write some tests for it but I have no idea how to handle this.

I would like to check for an error message when some condition is not met, and for an info message when everything goes fine.

my code looks like this:

class MyHelperView(grok.View):

    grok.context(IMyType)
    grok.layer(IMyLayer)
    grok.name('helper-view')
    grok.require('my.permission')

    def render(self):
        variable = self.request.form.get('variable', None)
        if not variable:
            msg = _(u'Required input is missing.')
            api.portal.show_message(message=msg, request=self.request, type='error')
        else:
            do_something()
            msg = _(u'Information processed.')
            api.portal.show_message(message=msg, request=self.request)
        self.request.response.redirect(self.context.absolute_url())

when I call the view obviously I ended with a None object, as the view returns nothing. I don't know where to look for messages... request? response? any hint?


原文:https://stackoverflow.com/questions/23226093
更新时间:2023-08-25 09:08

最满意答案

有许多因素会导致堆规范之外的内存使用。

在你的情况下,一个主要的是永久的一代。 它用于加载运行应用程序所需的所有依赖项的类以及其他一些东西。 由于必要的类,对于给定的应用程序没有太多的约束。 您可能需要大约64M(可能更多)才能在Jetty上运行Solr。

您可以指定最大大小以防止永久生成为其他事物增长,例如将-XX:MaxPermSize=64M添加到命令行。 尽管如此,它不太可能有所帮助,如果需要更多,它甚至可能会破坏它。 通常它几乎全部由您需要的类使用。

堆之外的内存使用的另一个贡献因素是每个线程的堆栈大小。 你的案例中的每个线程将消耗512K。 您可以安全地指定256K,尽管您可能没有足够的线程运行太重要。


There are a number of factors that contribute to memory usage beyond the heap specification.

A major one in your situation is the permanent generation. It's used to load classes for all the dependencies required to run the application and a few other things. There's not too much getting around a certain minimum for a given application due the classes necessary. You likely need around 64M (perhaps more) to run Solr on Jetty.

You can specify a maximum size to prevent the permanent generation from growing for the other things, e.g. add -XX:MaxPermSize=64M to your command line. It's unlikely going to help much though, and it might even break it if more is required. Usually it's almost all used by classes that you need.

Another contributor to memory usage beyond the heap is the stack size per thread. Each thread in your case is going to consume 512K. You can probably specify 256K safely, although you probably don't have enough threads running to matter too much.

相关问答

更多
  • 试试像这样: nohup yourcommand > output.log 2>&1 & nohup将防止您在注销事件中终止您的命令。 &将在后台运行它。 > output.log将把stdout发送到output.log 2>&1会将stderr重定向到stdout Try something like: nohup yourcommand > output.log 2>&1 & nohup will prevent yourcommand from being terminated in the e ...
  • 必须根据您的业务设置Solr堆大小。 设置-Xms=2G和-Xmx=12G只是对许多流行的Solr应用程序的推荐,但它不是强制性的。 您需要评估您的需求并将堆设置为适合您。 我真的建议你在堆上使用至少2G 。 Solr使用的一部分堆只是为了维护服务器而512m可能是不够的。 Solr heap size must be set according your business. Set -Xms=2G and -Xmx=12G is just a recommendation to lots of popul ...
  • 我猜你在谈论SSL而不是SSH 。 该错误消息告诉您Java无法解密私钥,它使用提供给应用程序容器的密码。 如果您在手册中查看“ 启用SSL ”,则会有一个部分提供有关如何在启动Solr时将密码设置为环境变量的示例(在solr.in.sh中 - 请参阅手册中的部分): SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks SOLR_SSL_KEY_STORE_PASSWORD=secret SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystor ...
  • 运行2个不同的jetty实例不会占用大量资源,并且可以让您灵活地关闭另一个,我们在Apache后面运行多个Jettys,而且没有任何问题 如果他们服务于不同的目的,这将是一个好的途径,但是,如果他们是相关的,那么你应该看看是否可以选择多核设置 没有必要在码头重新索引,索引文件是相同的,即使在Linux和Windows之间移动也不是问题。 Running 2 different jetty instances will not be resource intensive and will give you t ...
  • precisionStep参数仅与范围查询相关。 要执行排序,Lucene需要在field cache加载字段值。 长8字节,您的字段的字段缓存应该需要大约8B * 50M~400 MB。 如果你真的需要这个字段的长,没有办法减少内存使用(另一方面,使用int只需要~200MB)。 The precisionStep parameter is only relevant for range queries. To perform a sort, Lucene needs to load field valu ...
  • 线索是将solr示例目录示例/ lib / ext中的lib集成到solr.war中。 从solr.war中提取文件。 然后将libs放入WEB-INF / lib文件夹中。 创建一个包含libs的新solr.war。 The clue is to integrate the libs from the solr example directory example/lib/ext into the solr.war. Extract the files from the solr.war. Then put ...
  • 我也一直在寻找关于在应用程序中嵌入i-Jetty服务器的信息。 像原始海报一样,我需要为静态和动态资源提供服务。 我发现以下帖子是一个有用的开始: http://puregeekjoy.blogspot.com/2011/06/running-embedded-jetty-in-android-app.html 我注意到,在寻找有关将Web服务器嵌入到Android应用程序中的回答时(许多响应者),而不是提供有用的答案,因此想要在“电话中”执行此类操作,请将原始的海报留下。 然后他们着手给出所有理由不要。 ...
  • 弄清楚了。 所以,你几乎无法用我能找到的任何Unix做到这一点。 因此,要做的是运行一个虚拟化操作系统,它具有您想要的内存量。 然后,虚拟操作系统将被驱动到交换,但你的主操作系统将嗡嗡声很好。 更好的是,如果您只想计算页面错误而不是计算挂钟时间,使用这种方法可以使虚拟机的交换磁盘成为未虚拟化的磁盘 - 从而使页面错误几乎没有时间来解决虚拟机! Figured it out. So, you pretty much can't do this with any Unix I could find. There ...
  • 有许多因素会导致堆规范之外的内存使用。 在你的情况下,一个主要的是永久的一代。 它用于加载运行应用程序所需的所有依赖项的类以及其他一些东西。 由于必要的类,对于给定的应用程序没有太多的约束。 您可能需要大约64M(可能更多)才能在Jetty上运行Solr。 您可以指定最大大小以防止永久生成为其他事物增长,例如将-XX:MaxPermSize=64M添加到命令行。 尽管如此,它不太可能有所帮助,如果需要更多,它甚至可能会破坏它。 通常它几乎全部由您需要的类使用。 堆之外的内存使用的另一个贡献因素是每个线程的堆 ...
  • Solr显然在这个数字中加入了“buff / cache”。 如果将其添加到“已使用”,则获得98%。 记忆是可以回收的,所以你不应该担心。 操作系统只是尽可能地使用RAM进行磁盘缓存。 Solr apparently includes "buff/cache" into that number. If you add it to "used" you get 98%. That memory is reclaimable, so you shouldn't be worried. Operating sy ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。