testing - plone 3.3.5 - 使用 last_login_time 和日期范围索引的测试目录查询失败

标签 testing plone catalog plone-3.x

我在 Plone 3.3.5 上,正在为我的包编写一些测试。

在测试中,我需要检索自用户上次登录以来的所有 PloneboardComment。

这是我正在使用的代码:

class FunctionalTestSetup(base.FunctionalTestCase):
    [...]
    def test_new_since_last_login(self):
        # we log in as user1
        userid = 'user1'
        self.login(userid)
        # XXX: last_login_time is not updated
        self.updateLoginTime(userid)
        # and we should get no msg since last login
        new = getNewSinceLastLoginNr(self.forum, userid)
        self.assertEquals(new,0)

    def updateLoginTime(self, userid):
        member = self.portal.portal_membership.getMemberById(userid)
        member.setMemberProperties({'last_login_time': DateTime(),})


def getNewSinceLastLogin(forum, userid):
    """ returns all the new msgs since user's last login
    """
    acl = getToolByName(forum,'acl_users')
    user = acl.getUserById(userid)
    last_login = user.getProperty('last_login_time')

    query = dict(
        path = {'query':"/".join(forum.getPhysicalPath()),
                'depth':-1,},
        portal_type = "PloneboardComment",
        created = {'query':last_login, 'range': 'min'},
    )
    brains = self.catalog(query)
    return brains

在“afterSetup”上,我创建了一个有 2 条评论的论坛,但它们不应该被“getNewSinceLastLogin”计算在内,因为它们是在 user1 登录之前创建的。

无论如何,测试失败是因为在“self.assertEquals(new,0)”上 new=2 而不是 0。

奇怪的是,如果我打印所有日期,查询应该有效:

* last_login_time on login:
2011/12/07 13:44:24.131 GMT+1
* updated last_login_time:
2011/12/07 13:44:24.146 GMT+1
* last_login_time on catalog query:
2011/12/07 13:44:24.146 GMT+1
* creation date of comments:
2011/12/07 13:44:23.875 GMT+1
2011/12/07 13:44:24.019 GMT+1

是的,差别很小,但即使在“updateLoginTime”之前放置一个“sleep(10)”也不起作用。

奇怪的是,如果我在检查之前放置“sleep(30)”,或者如果我在测试中放置一个 pdb,并且我在几秒钟后手动调用这些方法,我得到 0 (!!!) 那是正确的查询结果。

我不明白这里出了什么问题...是否有针对此类查询的特定于测试的设置?为什么目录需要一直保持最新,即使我在创建后立即“手动”重新索引每个对象?

最佳答案

这可能是因为日期四舍五入为 5 分钟。看看这些票:#11827#11936#11827

关于testing - plone 3.3.5 - 使用 last_login_time 和日期范围索引的测试目录查询失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8416465/

相关文章:

python - 编目词典列表

magento - 如何在magento中获取产品名称?

performance - Perl 的 prove 命令输出的统计信息(usr、sys、cusr、csys 和 CPU)是什么意思?

testing - 有人用过 TestCocoon 吗?

Docker/TeamCity/xUnit - 测试选项卡丢失且测试失败不会停止构建

unit-testing - 测试代码的理想时间范围是多少

full-text-search - Plone 中的自定义 SearchableText 和 HTML 字段

wiki - Plone4 的任何类似 wiki 的东西

python - Plone CMS 日历源中的图像损坏

database - `pg_user` 是 View 还是目录?