def __init__(self, app):
     self.app = app
     self.state = None
     self.view = AuthForm()
     self.view.setOnClose(self.onClose)
     self.view.onLoginButtonClick(self.tryAuth)
     self.model = AuthModel()
     self.model.message.addCallback(self.messageFromModel)
     self.view.show()
class TestMessage(unittest.TestCase):

    def setUp(self):
        self.view = AuthForm()
        gettext.install('IMsg', './locale', unicode=True)

    def testShowMessage_NoneData(self):
        self.assertEqual(self.view.showMessage(None, None), None,
            _("Function returns not None on None data"))

    def testShowMessage_EmptyData(self):
        self.assertEqual(self.view.showMessage("", ""), None,
            _("Function returns not None on Empty data"))

    def testShowMessage_NonValid1(self):
        self.assertEqual(self.view.showMessage("foo", ""), None,
            _("Function returns not None on empty data"))

    def testShowMessage_NonValid2(self):
        self.assertEqual(self.view.showMessage("", "bar"), None,
            _("Function returns not None on Non Valid data"))

    def testShowMessage_Error(self):
        self.assertEqual(self.view.showMessage("", "Error"), True,
            _("Function returns not True on Valid data (state=Error)"))

    def testShowMessageSuccess(self):
        self.assertEqual(self.view.showMessage("", "Success"), True,
            _("Function returns not True on Valid data (state=Success)"))
 def setUp(self):
     self.view = AuthForm()
     gettext.install('IMsg', './locale', unicode=True)
class AuthController(object):

    def __init__(self, app):
        self.app = app
        self.state = None
        self.view = AuthForm()
        self.view.setOnClose(self.onClose)
        self.view.onLoginButtonClick(self.tryAuth)
        self.model = AuthModel()
        self.model.message.addCallback(self.messageFromModel)
        self.view.show()

    def onClose(self):
        self.app.quit()
        print 'quit'
        self.view.destroy()

    def messageFromModel(self, message):
        result = None
        if not (message is None):
            self.view.showMessage(message, self.state)
            self.model.message.set(None)
            self.model.state = None
            result = True
        return result

    def tryAuth(self):
        self.state = "Error"
        login = self.view.getLogin()
        password = self.view.getPassword()
        user = self.model.login(login, password)
        if not (user is None):
            is_admin = user.is_admin
            self.state = "Success"
            self.d = dc.DataController(self.logout)
            self.d.openConnection(is_admin)
            self.view.hide()
        # self.view.setPassword("")
        # self.state = None
    def logout(self):
        AuthController(self.app)
Exemple #5
0
def main():
    app = QApplication(sys.argv)
    form = AuthForm()
    form.show()
    app.exec_()