Exemplo n.º 1
0
    def add(self, userName, passWord):
        # we have to check if username or password is None first
        if userName is None:
            return (UsersModel.ERR_BAD_USERNAME, self.Err_Num)
        if passWord is None:
            return (UsersModel.ERR_BAD_PASSWORD, self.Err_Num)
        if len(userName) > UsersModel.MAX_USERNAME_LENGTH or len(userName) == 0 : # check if username is valid
            return (UsersModel.ERR_BAD_USERNAME, self.Err_Num)
        if len(passWord) > UsersModel.MAX_PASSWORD_LENGTH: # check if password is valid
            return (UsersModel.ERR_BAD_PASSWORD, self.Err_Num)

        try:
            newOne = User.objects.get(Q(user = userName)) # username must be unique
            return (UsersModel.ERR_USER_EXISTS, self.Err_Num)
        except:
            newOne = User(userName, passWord)
            newOne.count += 1
            newOne.save()
            return (UsersModel.SUCCESS, newOne.count)
Exemplo n.º 2
0
	def setUp(self):
		newOne = User(user = '******', password = '******' )
		newOne.save()