Beispiel #1
0
class TestRoleService(TestServiceBase):
    role_svc = RoleService()

    def test_create_role(self):
        role = self.role_svc.create_role('foo')
        self.assertEqual('foo', role.name)

    def test_get_roles(self):
        self.role_svc.create_role('foo')
        self.role_svc.create_role('bar')
        x = self.role_svc.get_roles()
        self.assertEqual(3, len(self.role_svc.get_roles()))
Beispiel #2
0
from colorama import Fore, Style
from getpass import getpass
from service.user_service import UserService
from service.news_service import NewsService
from service.role_service import RoleService
from service.type_service import TypeService
import os
import sys
import time

__user_service = UserService()
__news_service = NewsService()
__role_service = RoleService()
__type_service = TypeService()

while True:
    os.system("cls")
    print(Fore.LIGHTBLUE_EX, "\n\t===================")
    print(Fore.LIGHTBLUE_EX, "\n\t欢迎来到新闻管理系统")
    print(Fore.LIGHTBLUE_EX, "\n\t===================")
    print(Fore.LIGHTGREEN_EX, "\n\t1.登陆系统")
    print(Fore.LIGHTGREEN_EX, "\n\t2.退出系统")
    print(Style.RESET_ALL)
    op = input("\n\t输入操作编号:")
    #登录系统
    if op == "1":
        os.system("cls")
        username = input("\n\t请您输入用户账号:")
        password = getpass("\n\t请您输入用户密码:")
        result = __user_service.login(username, password)
        #登陆成功
class TestUserRoleService(TestServiceBase):
    user_svc = UserService()
    user_role_svc = UserRoleService()
    role_svc = RoleService()

    def test_create_user_role_no_commit(self):
        role_id = self.role_svc.create_role("test").id
        user = self.user_svc.create_user_no_commit("*****@*****.**", "z")
        user_role = self.user_role_svc.create_user_role_no_commit(
            user_id=user.id, role_id=role_id)

        self.assertEqual(user.id, user_role.user_id)
        db.session.rollback()
        self.assertIsNone(
            UserRole.query.filter_by(user_id=user_role.user_id,
                                     role_id=user_role.role_id).first())

    def test_create_user_role_by_name(self):
        role_id = self.role_svc.create_role("test").id
        user = self.user_svc.create_user("*****@*****.**", "z")
        user_role = self.user_role_svc.create_user_role_by_name(
            user_id=user.id, role_name="test")
        self.assertEqual(user.id, user_role.user_id)
        self.assertEqual(role_id, user_role.role_id)
        self.assertIsNotNone(
            UserRole.query.filter_by(user_id=user_role.user_id,
                                     role_id=user_role.role_id).first())

    def test_create_user_role_by_id(self):
        role_id = self.role_svc.create_role("test").id
        user = self.user_svc.create_user("*****@*****.**", "z")
        user_role = self.user_role_svc.create_user_role_by_id(user_id=user.id,
                                                              role_id=role_id)
        self.assertEqual(user.id, user_role.user_id)
        self.assertEqual(role_id, user_role.role_id)
        self.assertIsNotNone(
            UserRole.query.filter_by(user_id=user_role.user_id,
                                     role_id=user_role.role_id).first())

    def test_delete_role_id_for_user_id(self):
        role_id = self.role_svc.create_role("test").id
        user_id = self.user_svc.create_user("*****@*****.**", "z").id
        user_role = self.user_role_svc.create_user_role_by_id(user_id=user_id,
                                                              role_id=role_id)

        self.assertEqual(1,
                         len(UserRole.query.filter_by(user_id=user_id).all()))

        deleted = self.user_role_svc.delete_role_id_for_user_id(
            role_id, user_id)
        self.assertEqual(role_id, deleted.role_id)
        self.assertEqual(user_id, deleted.user_id)
        self.assertEqual(
            0, len(UserRole.query.filter_by(user_id=user_role.user_id).all()))

        self.assertIsNone(
            self.user_role_svc.delete_role_id_for_user_id(role_id, user_id))

    def test_delete_user_roles_for_user_id(self):
        role_ids = [
            self.role_svc.create_role("test").id,
            self.role_svc.create_role("test2").id
        ]
        user_id = self.user_svc.create_user("*****@*****.**", "z").id
        for role_id in role_ids:
            self.user_role_svc.create_user_role_by_id(user_id=user_id,
                                                      role_id=role_id)

        self.assertEqual(2,
                         len(UserRole.query.filter_by(user_id=user_id).all()))
        self.user_role_svc.delete_user_roles_for_user_id(user_id)
        self.assertEqual(0,
                         len(UserRole.query.filter_by(user_id=user_id).all()))
Beispiel #4
0
from service.user_service import UserService
from service.role_service import RoleService
from service.type_service import TypeService
from service.assign_service import AssignService
from colorama import  Fore, Style
from getpass import getpass
from datetime import datetime
import time
import sys
import os

__user_service = UserService()
__role_service = RoleService()
__type_service = TypeService()
__assign_service = AssignService()

while True:
    os.system("cls")
    print(Fore.LIGHTBLUE_EX, "\n\t================================")
    print(Fore.LIGHTBLUE_EX, "\n\t      欢迎使用作业管理系统")
    print(Fore.LIGHTBLUE_EX, "\n\t================================")
    print(Fore.LIGHTGREEN_EX, "\n\t1.登陆系统")
    print(Fore.LIGHTGREEN_EX, "\n\t2.退出系统")
    print(Style.RESET_ALL)
    opt = input("\n\t输入操作编号: ")

    if opt == "1":
        username = input("\n\t用户名: ")
        password = getpass("\n\t密码: ")
        result = __user_service.login(username, password)
Beispiel #5
0
# ---------------------------
# Administrator 2021/2/23 11:15 
# ---------------------------

from colorama import Style,Fore
from service.user_service import UserService
from service.new_service import NewsService
from service.role_service import RoleService
from getpass import getpass
import os
import sys
from time import sleep

__user_service = UserService()
__news_service = NewsService()
__role_service = RoleService()

while True:
    os.system('cls')
    print(Fore.LIGHTBLUE_EX,'\n\t=================')
    print(Fore.LIGHTBLUE_EX,'\n\t欢迎来到新闻管理系统')
    print(Fore.LIGHTBLUE_EX,'\n\t=================')
    print(Fore.LIGHTYELLOW_EX,'\n\t1.登录系统')
    print(Fore.LIGHTYELLOW_EX,'\n\t2.退出系统')
    print(Style.RESET_ALL)
    opt = input('\n\t请输入操作编号:')
    if opt == '1':
        username = input('\n\t请输入用户名:')
        password = getpass('\n\t请输入密码:')
        # 比较登录的结果
        result = __user_service.login(username,password)
Beispiel #6
0
from flask import Blueprint
from flask import jsonify
from flask_login import login_required

from core.authorization import admin_permission
from model.role import roles_schema
from service.role_service import RoleService

role_api = Blueprint('role_api', __name__)

role_service = RoleService()

@role_api.route("/role", methods=["GET"])
@login_required
@admin_permission.require()
def get_roles():
    roles = role_service.get_roles()
    return jsonify(roles_schema.dump(roles))