當前位置: 首頁>>代碼示例>>Python>>正文


Python Form.confirmed方法代碼示例

本文整理匯總了Python中formspree.forms.models.Form.confirmed方法的典型用法代碼示例。如果您正苦於以下問題:Python Form.confirmed方法的具體用法?Python Form.confirmed怎麽用?Python Form.confirmed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在formspree.forms.models.Form的用法示例。


在下文中一共展示了Form.confirmed方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_unconfirm_process

# 需要導入模塊: from formspree.forms.models import Form [as 別名]
# 或者: from formspree.forms.models.Form import confirmed [as 別名]
def test_unconfirm_process(client, msend):
    # confirm some forms for the same email address
    f1 = Form('[email protected]', 'testwebsite.com')
    f1.confirmed = True
    DB.session.add(f1)

    f2 = Form('[email protected]', 'othertestwebsite.com')
    f2.confirmed = True
    DB.session.add(f2)

    f3 = Form('[email protected]', 'anothertestwebsite.com')
    f3.confirmed = True
    DB.session.add(f3)
    DB.session.commit()

    # try a submission
    r = client.post('/[email protected]',
        headers = {'Referer': 'http://testwebsite.com'},
        data={'name': 'carol'}
    )
    assert msend.called
    request_unconfirm_url = url_for('request_unconfirm_form', form_id=f1.id, _external=True)
    assert request_unconfirm_url in msend.call_args[1]['text']
    msend.reset_mock()

    # this should send a confirmation email
    r = client.get(request_unconfirm_url)
    assert r.status_code == 200
    assert msend.called

    unconfirm_url_with_digest = url_for(
        'unconfirm_form',
        form_id=f1.id,
        digest=f1.unconfirm_digest(),
        _external=True
    )
    assert unconfirm_url_with_digest in msend.call_args[1]['text']
    msend.reset_mock()
    
    # unconfirm this
    r = client.get(unconfirm_url_with_digest)
    assert f1.confirmed == False

    # should show a page with the other options
    assert r.status_code == 200
    assert 'Select all' in r.data.decode('utf-8')
    assert f2.host in r.data.decode('utf-8')
    assert f3.host in r.data.decode('utf-8')

    unconfirm_multiple_url = url_for('unconfirm_multiple')
    assert unconfirm_multiple_url in r.data.decode('utf-8')

    # we can use unconfirm_multiple to unconfirm f2
    assert f2.confirmed == True
    r = client.post(unconfirm_multiple_url, data={'form_ids': [f2.id]})
    assert r.status_code == 200
    assert 'Success' in r.data.decode('utf-8')
    assert f2.confirmed == False
開發者ID:ajabo,項目名稱:formspree,代碼行數:60,代碼來源:test_unsubscribe.py


注:本文中的formspree.forms.models.Form.confirmed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。