单元测试python烧瓶中的验证码

时间:2016-03-12 06:21:55

标签: python unit-testing flask

在烧瓶应用中,我有一个寄存器表格

class RegisterForm(BaseForm):
    phone_or_email = StringField('user', validators=[input_required()])
    password = PasswordField('password',
                             validators=[Length(min=6, max=20),
                                         input_required()])
    captcha = StringField('captcha',
                          validators=[Length(min=4,max=4)])
    submit = SubmitField('submit')

    def validate_captcha(self, field):
        if field.data != str(session['CAPTCHA_NUM']):
            raise ValidationError('captcha error')

在测试代码中

def test_phone_register(self):
    response = self.client.post(url_for('auth.register'),
                                data={
                                    'phone_or_email' : 'no-reply@g.cc',
                                    'password': 'google',
                                    'captcha': 1234
                                })
    self.assertTrue('captcha error' in response.get_data(as_text=True))

问题是在单元测试中我不知道如何获取验证码。因为catpcha在会话中,我应该在测试用户注册时加入它吗?

0 个答案:

没有答案
相关问题