小编Fra*_*ant的帖子

在Django 1.8上运行django-celery测试

最终,我想让测试通过Django 1.9.django-celery目前适用于Django <1.9.因此,第一步是确保库测试在我的机器上通过Django 1.8传递.

我在测试项目中克隆了https://github.com/celery/django-celery并安装了这些要求.对于Django 1.7,测试正在通过.对于Django 1.8我应该多次得到相同的错误,而它应该工作...

请参阅https://github.com/celery/django-celery/blob/master/tox.ini包括Django 1.8:

...
1.8: Django>=1.8.0,<1.9.0
Run Code Online (Sandbox Code Playgroud)

对于Django 1.7:

pip install Django==1.7
./django-celery/tests/manage.py test djcelery.tests
...
Ran 64 tests in 0.319s
OK
Run Code Online (Sandbox Code Playgroud)

对于Django 1.8:

pip install Django==1.8
./django-celery/tests/manage.py test djcelery.tests

...
======================================================================
ERROR: test_all_as_schedule (djcelery.tests.test_schedulers.test_DatabaseScheduler)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/francois/web/test_project/django-celery/djcelery/tests/test_schedulers.py", line 110, in setUp
    m1 = create_model_interval(schedule(timedelta(seconds=10)))
  File "/Users/francois/web/test_project/django-celery/djcelery/tests/test_schedulers.py", line 20, in create_model_interval
    **kwargs)
  File "/Users/francois/web/test_project/django-celery/djcelery/tests/test_schedulers.py", line 40, in create_model
    return Model(**dict(entry, **kwargs))
  File "/Users/francois/Envs/test_project/lib/python2.7/site-packages/django/db/models/base.py", line …
Run Code Online (Sandbox Code Playgroud)

testing django-celery django-1.8

5
推荐指数
0
解决办法
452
查看次数

测试Django 1-5重置密码表单 - 如何为测试生成令牌?

通过以下测试,令牌不会被识别为有效.在我的手动测试中,它正在工作,所以我错过了生成密码的方式我想.

def test_actual_reset_password(self):
    new_password = "myNewPassword012*"
    token_generator = PasswordResetTokenGenerator()
    user = UserFactory.create()
    token = token_generator.make_token(user=user)

    response = self.assert_page_loading(path="/forgot-password/reset/{0}/".format(token))
    print response 
    # That loads the page with the error message mentioning that the token was already used        

    # So I cannot carry on:
    form = response.form
    form['new_password1'] = new_password
    form['new_password2'] = new_password

    response = form.submit()
Run Code Online (Sandbox Code Playgroud)

在django源代码中,在PasswordResetForm中,我找到了这段代码; 我看不出有什么区别:

def save(self, ..., token_generator=default_token_generator, ...):
    """
    Generates a one-use only link for resetting password and sends to the
    user.
    """
    ...
    for user in …
Run Code Online (Sandbox Code Playgroud)

authentication django django-webtest

4
推荐指数
1
解决办法
1556
查看次数

Cypress - 在另一个元素中选择元素 - “within”的选择器语法快捷方式

我的 HTML 中有一个元素,其中包含一个复选框;类似于(实际输出有点复杂,因为我们使用的是 React + Material UI。然而,这是总体思路,一个“容器”,其中只有一个复选框):

<span class="..." cy-data="checkbox-container">
  ...
  <checkbox ... />
</span>
Run Code Online (Sandbox Code Playgroud)

目前,为了在我的测试中获得复选框,我正在使用这个:

 cy.get('[data-cy=checkbox-container]').within(() => {
   cy.get('[type="checkbox"]').check();
 })
Run Code Online (Sandbox Code Playgroud)

有没有更短的方法来写这个?


cy.get('[data-cy=checkbox-container]').get('[type="checkbox"]')返回完整文档中找到的第一个复选框;不是下面的那个checkbox-container

cy.get('[data-cy=checkbox-container] > [type="checkbox"]')引发“未找到”错误。

selector cypress

3
推荐指数
1
解决办法
7957
查看次数

Django,Wagtail 管理员:使用“through”处理多对多

我有 2 个带有直通表的模型,例如:

class A(models.Model):
    title = models.CharField(max_length=500)
    bs = models.ManyToManyField(to='app.B', through='app.AB', blank=True)

    content_panels = [
        FieldPanel('title'),
        FieldPanel('fields'),    # what should go here?
    ]

class AB(models.Model):
    a = models.ForeignKey(to='app.A')
    b = models.ForeignKey(to='app.B')
    position = models.IntegerField()

    class Meta:
        unique_together = ['a', 'b']
Run Code Online (Sandbox Code Playgroud)

尝试保存时出现以下错误:

无法在指定中间模型的 ManyToManyField 上设置值。

这个错误对我来说很有意义。我应该保存 AB 实例。我只是不确定在 Wagtail 中实现这一目标的最佳方法是什么。

django wagtail

2
推荐指数
1
解决办法
897
查看次数