如何使用python测试特定方法

时间:2013-04-13 13:44:10

标签: python testing plone

我想为登录页面编写测试。方法是check_input,代码如下所示

def check_input(self):
    form = self.request.form
    username = form.get('name',"")
    password = form.get('password',"")
    session = getSession()
    error = ''
    print session
    if (username == '' and password == ''):
        error = "error: you must enter both username and password"          
    if (username!='') and(password == ''):
        error = "you must enter password"


    if (username and password) not in ['', None]:
        result = session.execute("select UserName,Password from membership where UserName='%s' && Password='%s' "%(username,password))
        if result:
            records = result.fetchall()
            if not records:
                error = 'username and password do not match'



    if not error:
        return self.template_success(name=username)
    else:
        return self.template(error = error)

我想测试的是是否同时输入用户名和密码,还要检查他/她是否提供密码。我想检查一下这个方法是否正确。告诉我我想在终端进行测试的必要事项。

1 个答案:

答案 0 :(得分:1)

你很幸运,因为Plone确实有一个你应该使用的测试框架。

https://ploneapptesting.readthedocs.org/en/latest/