Пример #1
0
    def test_delete(self):
        print("Testing delete...")
        test_user = self.test_user2

        UserSQL.delete(test_user)
        users = UserSQL.selectAll()

        self.assertEqual(len(users), 1)
Пример #2
0
    def test_insert(self):
        print("Testing insert...")

        test_user = User(0, "dpham", "password", False)

        UserSQL.insert(test_user)
        users = UserSQL.selectAll()

        self.assertEqual(len(users), 3)
Пример #3
0
    def test_update(self):
        print("Testing update...")
        test_user = self.test_user2
        test_user.userID = "updated"
        test_user.password = "******"
        test_user.admin = True

        UserSQL.update(test_user)
        users = UserSQL.selectAll()
        user = UserSQL.selectByUserID(test_user.userID)[0]

        self.assertEqual(len(users), 2)
        self.assertEqual(user.userID, test_user.userID)
        self.assertEqual(user.password, test_user.password)
        self.assertEqual(user.admin in ["True", "1"], True)
Пример #4
0
def profile():
    from database import UserSQL
    from utils import ObjectEncoder

    user = UserSQL.selectByUserID(session['userID'])[0]

    return jsonify({'user': json.dumps(user, cls=ObjectEncoder)})
Пример #5
0
    def test_select_by_userID(self):
        print("Testing select_by_UserID...")

        userID = 'admin'
        password = '******'
        users = UserSQL.selectByUserID(userID)

        self.assertEqual(len(users), 1)
        self.assertEqual(users[0].userID, 'admin')
Пример #6
0
def login():
    from database import UserSQL
    # from extension import bcrypt

    json_data = request.json
    # Filter username
    user = UserSQL.selectByUserID(json_data['userID'])[0]

    # Check password is correct.
    # if user and bcrypt.check_password_hash(user.password, json_data['password']):
    if user and user.password == json_data['password']:
        # create session
        session['logged_in'] = True
        session['userID'] = json_data['userID']

        status = True
    else:
        status = False
    return jsonify({'result': status})
Пример #7
0
    def setUp(self):

        print("Setup...")
        UserSQL.create_table()

        self.test_user1 = User(id=1,
                               userID='admin',
                               password='******',
                               admin=True)
        self.test_user2 = User(id=2,
                               userID='user',
                               password='******',
                               admin=False)

        UserSQL.insert(self.test_user1)
        UserSQL.insert(self.test_user2)
Пример #8
0
 def __init__(self, dbexample = "None"):
     self.dbexample = UserSQL()
Пример #9
0
class dbAPI(object):
    """docstring for dbAPI"""
    def __init__(self, dbexample = "None"):
        self.dbexample = UserSQL()

# ---------------------------------------------------------------------
###账户信息
    # 账户检索(账户名)
    def searchUser(self, name):
        # 404 不存在, 200 存在
        return self.dbexample.searchUser(name)

    # 获取账户ID
    def pullUserID(self, name):
        return int(self.dbexample.pullUserid(name))

    # 账户注册(账户名,密码)
    def sign_up(self, name, password):
        searchResult = self.searchUser(name)
        if searchResult == 404:
            accountResult = self.dbexample.account(name, password)
            if accountResult != 200:
                result = 403
            else:
                result = self.sign_in(name, password) #测试登陆
        else:
            result = 403
        return result

    # 账户登录(账户名,密码)
    def sign_in(self, name, password):
        searchResult = self.searchUser(name)
        if searchResult == 404:
            result = 404 #用户不存在
        else:
            userid = self.pullUserID(name)
            loginResult = self.dbexample.login(userid, password)
            if loginResult == 200:
                result = 200
            else:
                result = 403    #登陆失败
        return result

    # 账户删除(账户名,密码)
    def rmuser(self, name, password):
        searchResult = self.searchUser(name)
        if searchResult == 404:
            result = 404 #用户不存在
        else:
            userid = self.pullUserID(name)
            rmResult = self.dbexample.rmUser(userid, password)
            rmpersonResult = self.dbexample.rmUserPerson(userid)
            rmdiscussResult = self.dbexample.rmUserDiscuss(userid)
            if (rmResult == 200 or rmResult == 404) and (rmpersonResult == 200 or rmpersonResult == 404) and (rmdiscussResult == 200 or rmdiscussResult == 404):
                result = 200
            else:
                result = 403
        return result
# -------------------------------------------------------------
###会议主题
    # 会议主题搜索
    def searchtheme(self, theme):
        # 不存在 404, 存在 200
        return self.dbexample.searchTheme(theme)

    # 获取会议主题ID
    def pullthemeid(self, theme):
        return int(self.dbexample.pullThemeid(theme))

    # 发布会议
    def pushtheme(self, theme):
        searchResult = self.searchtheme(theme)
        if searchResult != 404:
            result = 403
        else:
            push = self.dbexample.pushTheme(theme)
            if push != 200:
                result = 403
            else:
                result = self.searchtheme(theme)
        return result

    # 结束会议
    def rmtheme(self, theme):
        searchResult = self.searchtheme(theme)
        if searchResult == 404:
            result = 404
        else:
            themeid = self.pullthemeid(theme)
            rmResult = self.dbexample.rmTheme(themeid)
            rmpersonResult = self.dbexample.rmThemePerson(themeid)
            rmdiscussResult = self.dbexample.rmThemeDiscuss(themeid)
            if (rmResult == 200 or rmResult == 404) and (rmpersonResult == 200 or rmpersonResult == 404) and (rmdiscussResult == 200 or rmdiscussResult == 404):
                result = 200
            else:
                result = 403
        return result
# ---------------------------------------------------------------
###主题会议参会
    # 参会人员搜索(单个 or 所有)
    def searchperson(self, theme, name):
        if name == "all":
            result = "all"
        else:
            nameResult = self.searchUser(name)
            themeResult = self.searchtheme(theme)
            if nameResult == 404 or themeResult == 404:
                result = 404
            else:
                userid = self.pullUserID(name)
                themeid = self.pullthemeid(theme)
                personResult = self.dbexample.searchPerson(themeid, userid)
                if personResult == 404:
                    result = 404
                else:
                    result = 200
        return result
        
    # 报名会议
    def applytheme(self, theme, name):
        nameResult = self.searchUser(name)
        themeResult = self.searchtheme(theme)
        if nameResult == 404 or themeResult == 404:
            result = 404
        else:
            userid = self.pullUserID(name)
            themeid = self.pullthemeid(theme)
            applyResult = self.dbexample.applyTheme(themeid, userid)
            if applyResult == 200:
                result = 200
            else:
                result = 403
        return result

# ------------------------------------------------------------------
###主题会议评论"""
    # 评论信息源信息
    def discussinfo(self, content):
        infoResult = self.dbexample.pullDiscussInfo(content)
        return infoResult

    # 评论信息过滤展示
    def discussfilter(self, content):
        filterResult = self.discussinfo(content)
        themename = self.dbexample.pullidTheme(filterResult[1])
        username = self.dbexample.pullidUser(filterResult[2])
        filterResult[1] = themename
        filterResult[2] = username
        filterResult.append(content)
        return filterResult     #评论id、主题会议名、用户名、评论内容

    # 发帖&评论
    def discuss(self, theme, name, content):
        nameResult = self.searchUser(name)
        themeResult = self.searchtheme(theme)
        if nameResult == 404 or themeResult == 404:
            result = 404
        else:
            userid = self.pullUserID(name)
            themeid = self.pullthemeid(theme)
            discResult = self.dbexample.discuss(themeid, userid, content)
            if discResult == 200:
                result = 200
            else:
                result = 403
        return result

    # 删帖
    def rmdiscuss(self, discussid, theme, name):
        nameResult = self.searchUser(name)
        themeResult = self.searchtheme(theme)
        if nameResult == 404 or themeResult == 404:
            result = 404
        else:
            userid = self.pullUserID(name)
            themeid = self.pullthemeid(theme)
            rmResult = self.dbexample.rmdiscuss(discussid, themeid, userid)
            if rmResult == 200:
                result = 200
            else:
                result = 404
        return result
Пример #10
0
 def test_select_all(self):
     print("Testing select_all...")
     users = UserSQL.selectAll()
     self.assertEqual(len(users), 2)
Пример #11
0
import sys
sys.path.append("..")

from project.user.models import User
from database import UserSQL

UserSQL.create_table()

test_user1 = User(id=1, userID='admin', password='******', admin=True)
test_user2 = User(id=2, userID='user', password='******', admin=False)

UserSQL.insert(test_user1)
UserSQL.insert(test_user2)