Пример #1
0
    def login(self):
        """
        Takes the credentials,validates them and redirects to specific user tasks.
        :return:
        """
        try:
            print("WELCOME TO AIMS!!\n")
            print("Login as: \n"
                  "1: Admin \n"
                  "2: Supervisor \n"
                  "3: Member\n")
            num = int(input("Select user: "******"Enter Email: ")
                password = input("Enter password: "******"Invalid Choice. Please Enter again: ")
                self.login()

        except Exception as e:
            print("Error", e)
            self.login()
Пример #2
0
def start_session(comline):
    print('\n Start session')
    global admin, user1  # , user2
    if comline['admin'] == '':
        admin = Admin(email='*****@*****.**', pwd='*Anycash15')
    else:
        print(' Admin token...')
        admin = Admin(token=comline['admin'])
    user1 = User(user={'email': comline['user1'].split(':')[0], 'pwd': comline['user1'].split(':')[1]})
    # user2 = User(user(email=comline['user2'].split(':')[0]), pwd=comline['user2'].split(':')[1]))
    user1.authorization(user1.email, pwd=user1.pwd)
    # user2.authorization_by_email(user2.email, pwd=user2.pwd)
    yield admin, user1  # , user2
    user1.logout()
    user1.driver.quit()
Пример #3
0
def _before():
    # Force all connections to be secure
    if app.config['REQUIRE_SSL'] and not request.is_secure:
        return redirect(request.url.replace("http://", "https://"))

    #ensure that nothing is served from the instance directory
    if 'instance' in request.url:
        abort(404)

    update_config_for_host()

    get_db()

    # Is the user signed in?
    g.user = None
    if 'user' in session:
        g.user = session['user']

    if 'admin' not in g:
        g.admin = Admin(g.db)
        # Add items to the Admin menu
        # the order here determines the order of display in the menu

        # a header row must have the some permissions or higher than the items it heads
        g.admin.register(User,
                         url_for('user.display'),
                         display_name='User Admin',
                         header_row=True,
                         minimum_rank_required=500)

        g.admin.register(User,
                         url_for('user.display'),
                         display_name='Users',
                         minimum_rank_required=500,
                         roles=[
                             'admin',
                         ])
        g.admin.register(Role,
                         url_for('role.display'),
                         display_name='Roles',
                         minimum_rank_required=1000)
        g.admin.register(Pref,
                         url_for('pref.display'),
                         display_name='Prefs',
                         minimum_rank_required=1000)
Пример #4
0
def _before():
    # Force all connections to be secure
    if app.config['REQUIRE_SSL'] and not request.is_secure:
        return redirect(request.url.replace("http://", "https://"))

    get_db()

    # Is the user signed in?
    g.user = None
    if 'user' in session:
        g.user = session['user']

    if 'admin' not in g:
        """Register menu items for the user dropdown"""
        g.admin = Admin(g.db)
        g.admin.register(User,
                         url_for('user.display'),
                         display_name='Users',
                         minimum_rank_required=500,
                         roles=[
                             'admin',
                         ])
        g.admin.register(Role,
                         url_for('role.display'),
                         display_name='Roles',
                         minimum_rank_required=1000)
        g.admin.register(Pref,
                         url_for('pref.display'),
                         display_name='Prefs',
                         minimum_rank_required=1000)

        g.admin.register(Article,
                         url_for('news.display'),
                         header_row=True,
                         display_name='News',
                         minimum_rank_required=500)
        g.admin.register(Article,
                         url_for('news.display'),
                         minimum_rank_required=500)
        g.admin.register(Article,
                         url_for('news.edit'),
                         display_name='Add Article',
                         minimum_rank_required=500)
PRIMARY KEY (`ID`),
UNIQUE KEY (`email`)) ROW_FORMAT=DYNAMIC;'''
conn.execute(query)

# skill/exp table
print("rebuild skill/exp table...")
query = '''CREATE TABLE skills (
skill TINYINT DEFAULT -1,
experience TINYINT DEFAULT 0,
collaboratorID int(11) NOT NULL,
FOREIGN KEY (`collaboratorID`) REFERENCES collaborator(`ID`)) ROW_FORMAT=DYNAMIC;'''
conn.execute(query)

# Always create No.1 collaborator/dreamer/admin for system keeping to avoid foreign key error
print("create No.1 user as admin from config")
new_admin = Admin(config['Admin']['Name'], config['Admin']['Email'],
                  config['Admin']['Password']).commit(conn)
new_collab = Collaborator(config['Admin']['Name'], config['Admin']['Email'],
                          config['Admin']['Password']).commit(conn)
new_dreamer = Dreamer(config['Admin']['Name'], config['Admin']['Email'],
                      config['Admin']['Password']).commit(conn)

# project table
print("rebuild project table...")
query = '''CREATE TABLE project (
ID INT(11) NOT NULL AUTO_INCREMENT,
project_title VARCHAR(100) DEFAULT NULL,
description TEXT DEFAULT NULL,
category TINYINT DEFAULT -1,
dreamerID int(11) NOT NULL,FOREIGN KEY (`dreamerID`) REFERENCES dreamer(`ID`),
project_status TINYINT DEFAULT 1,
is_hidden TINYINT DEFAULT 0,
Пример #6
0
from database.database import DBCommands
from preload.load_all import dp
from aiogram.types import Message
from aiogram.dispatcher.filters import Command
from users.admin import Admin

db = DBCommands()
denis = Admin()


@dp.message_handler(Command('add_teacher'))
async def add_teacher(message: Message):
    teacher_id = int(message.text)
    await denis.add_teacher(teacher_id=teacher_id)
    await message.answer(f'Преподователь ')


@dp.message_handler(Command('delete_teacher'))
async def delete_teacher(message: Message):
    teacher_id = int(message.text)
    await denis.delete_teacher(teacher_id=teacher_id)
    await message.answer(f'Преподователь ')
Пример #7
0
def test_admin():
    admin = Admin(db)
    admin.register(User,
                   '/user/',
                   display_name='Users',
                   minimum_rank_required=500,
                   role_list=[
                       'admin',
                   ])
    admin.register(Role,
                   '/role/',
                   display_name='User Permissions',
                   minimum_rank_required=2000)
    assert len(admin.permissions) == 2

    assert admin.has_access('admin') == True
    assert admin.has_access('admin', User) == True
    assert admin.has_access('admin', Role) == False
    assert admin.has_access('bleddy') == False
    assert admin.has_access('bleddy', User) == False
    assert admin.has_access('') == False
Пример #8
0
 def setUp(self):
     self.admin = Admin()
Пример #9
0
class workerTest(unittest.TestCase):

    def setUp(self):
        self.admin = Admin()

    @mock.patch.object(Admin, 'admin_report_management')
    @mock.patch.object(Admin, 'show_complaints')
    @mock.patch.object(Admin, 'admin_supervisor_mgmnt')
    @mock.patch.object(Admin, 'admin_worker_mgmnt')
    @mock.patch('builtins.input')
    def test_worker_tasks(self, mock_input, mock_admin_worker_mgmnt, mock_admin_supervisor_mgmnt, mock_show_complaints,
                          mock_admin_report_management):
        # choice = 1
        mock_input.return_value = 1
        self.supervisor.supervisor_tasks()
        mock_admin_worker_mgmnt.assert_called_once()

        # choice = 2
        mock_input.return_value = 2
        self.supervisor.supervisor_tasks()
        mock_admin_supervisor_mgmnt.assert_called_once()

        # choice = 3
        mock_input.return_value = 3
        self.supervisor.supervisor_tasks()
        mock_show_complaints.assert_called_once()

        # choice = 4
        mock_input.return_value = 4
        self.supervisor.supervisor_tasks()
        mock_admin_report_management.assert_called_once()

    @mock.patch.object(Admin, 'admin_tasks')
    @mock.patch.object(Admin, 'assign_jobrole')
    @mock.patch.object(Admin, 'delete_worker')
    @mock.patch.object(Admin, 'show_reports')
    @mock.patch.object(Admin, 'show_allworkers')
    @mock.patch.object(Admin, 'create_worker')
    @mock.patch('builtins.input')
    def test_admin_worker_mgmnt(self, mock_input, mock_create_worker, mock_show_allworkers, mock_show_reports,
                                mock_delete_worker, mock_assign_jobrole, mock_admin_tasks):
        # choice = 1
        mock_input.return_value = 1
        self.admin.admin_worker_mgmnt()
        mock_create_worker.assert_called_once()

        # choice = 2
        mock_input.return_value = 2
        self.admin.admin_worker_mgmnt()
        mock_show_allworkers.assert_called_once()

        # choice = 3
        mock_input.return_value = 3
        self.admin.admin_worker_mgmnt()
        mock_show_reports.assert_called_once()

        # choice = 4
        mock_input.return_value = 4
        self.admin.admin_worker_mgmnt()
        mock_delete_worker.assert_called_once()

        # choice = 5
        mock_input.return_value = 5
        self.admin.admin_worker_mgmnt()
        mock_assign_jobrole.assert_called_once()

        # choice = 6
        mock_input.return_value = 6
        self.admin.admin_worker_mgmnt()
        mock_admin_tasks.assert_called_once()

    @mock.patch.object(Admin, "input_create_worker_data")
    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_create_worker(self, mock_input, mock_dbconnection, mock_input_create_worker_data):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        mock_input.side_effect = ('rahul', '*****@*****.**', 'Abc@1')
        query = Queries.create.value
        mock_cursor.execute.assert_called_once_with(query.format('rahul', '*****@*****.**', 'Abc@1'))
        mock_input_create_worker_data.assert_called_once()

    @mock.patch.object(Admin, "admin_worker_mgmnt")
    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_delete_worker(self, mock_input, mock_dbconnection, mock_admin_worker_mgmnt):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        self.admin.delete_worker_id == 123
        mock_cursor.execute.assert_called_once()
        mock_admin_worker_mgmnt.assert_called_once()

    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_allworkers(self, mock_input, mock_dbconnection):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        data = [('1', 'rahul', '*****@*****.**', 'xyz')]
        mock_cursor.execute.return_value = data
        mock_input.return_value = 1
        mock_input.assert_called_once()
        self.admin.show_allworkers()

    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_unassigned_workers(self, mock_input, mock_dbconnection):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        data = [('1', 'rahul', '*****@*****.**', 'xyz')]
        mock_cursor.execute.return_value = data
        mock_input.return_value = 1
        mock_input.assert_called_once()
        self.admin.show_unassigned_workers()

    @mock.patch.object(Admin, 'admin_tasks')
    @mock.patch.object(Admin, 'assign_supervisor')
    @mock.patch.object(Admin, 'delete_supervisor_team')
    @mock.patch.object(Admin, 'delete_supervisor')
    @mock.patch.object(Admin, 'create_report')
    @mock.patch.object(Admin, 'create_supervisorTeam')
    @mock.patch('builtins.input')
    def test_admin_supervisor_mgmnt(self, mock_input, mock_create_supervisorTeam, mock_create_report,
                                    mock_delete_supervisor,
                                    mock_delete_supervisor_team, mock_assign_supervisor, mock_admin_tasks):
        # choice = 1
        mock_input.return_value = 1
        self.admin.admin_supervisor_mgmnt()
        mock_create_supervisorTeam.assert_called_once()

        # choice = 2
        mock_input.return_value = 2
        self.admin.admin_supervisor_mgmnt()
        mock_create_report.assert_called_once()

        # choice = 3
        mock_input.return_value = 3
        self.admin.admin_supervisor_mgmnt()
        mock_delete_supervisor.assert_called_once()

        # choice = 4
        mock_input.return_value = 4
        self.admin.admin_supervisor_mgmnt()
        mock_delete_supervisor_team.assert_called_once()

        # choice = 5
        mock_input.return_value = 5
        self.admin.admin_supervisor_mgmnt()
        mock_assign_supervisor.assert_called_once()

        # choice = 6
        mock_input.return_value = 6
        self.admin.admin_supervisor_mgmnt()
        mock_admin_tasks.assert_called_once()

    @mock.patch.object(Admin, "admin_supervisor_mgmnt")
    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_create_supervisorTeam(self, mock_input, mock_dbconnection, mock_admin_supervisor_mgmnt):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        mock_input.side_effect = ('1', 'rahul', '*****@*****.**', 'Abc@1')
        query = Queries.create.value
        mock_cursor.execute.assert_called_once_with(query.format('1', 'rahul', '*****@*****.**', 'Abc@1'))
        mock_admin_supervisor_mgmnt.assert_called_once()

    @mock.patch.object(Admin, "admin_supervisor_mgmnt")
    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_delete_supervisor(self, mock_input, mock_dbconnection, mock_admin_supervisor_mgmnt):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        self.admin.delete_supervisor_id == 123
        mock_cursor.execute.assert_called_once()
        mock_admin_supervisor_mgmnt.assert_called_once()

    @mock.patch.object(Admin, "admin_supervisor_mgmnt")
    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_allsupervisors(self, mock_input, mock_dbconnection, mock_admin_supervisor_mgmnt):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        self.admin.delete_supervisor_teamnumber_id == 123
        mock_cursor.execute.assert_called_once()
        mock_admin_supervisor_mgmnt.assert_called_once()

    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_allsupervisors(self, mock_input, mock_dbconnection):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        data = [('1', 'rahul', '*****@*****.**', 'none', '1')]
        mock_cursor.execute.return_value = data
        mock_input.return_value = 1
        mock_input.assert_called_once()
        self.admin.show_allsupervisors()

    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_unassigned_supervisors(self, mock_input, mock_dbconnection):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        data = [('1', 'rahul', '*****@*****.**', 'none', '1')]
        mock_cursor.execute.return_value = data
        mock_input.return_value = 1
        mock_input.assert_called_once()
        self.admin.show_unassigned_workers()

    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_complaints(self, mock_input, mock_dbconnection):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        data = [('1', 'fire', 'xyz')]
        mock_cursor.execute.return_value = data
        mock_input.return_value = 1
        mock_input.assert_called_once()
        self.admin.show_complaints()

    @mock.patch.object(Admin, 'admin_tasks')
    @mock.patch.object(Admin, 'show_pending_reports')
    @mock.patch.object(Admin, 'show_rejected_reports')
    @mock.patch.object(Admin, 'show_approved_reports')
    @mock.patch.object(Admin, 'show_all_reports')
    @mock.patch('builtins.input')
    def test_admin_report_management(self, mock_input, mock_show_all_reports, mock_show_approved_reports,
                                     mock_show_rejected_reports,
                                     mock_show_pending_reports, mock_admin_tasks):
        # choice = 1
        mock_input.return_value = 1
        self.admin.admin_report_management()
        mock_show_all_reports.assert_called_once()

        # choice = 2
        mock_input.return_value = 2
        self.admin.admin_report_management()
        mock_show_approved_reports.assert_called_once()

        # choice = 3
        mock_input.return_value = 3
        self.admin.admin_report_management()
        mock_show_rejected_reports.assert_called_once()

        # choice = 4
        mock_input.return_value = 4
        self.admin.admin_report_management()
        mock_show_pending_reports.assert_called_once()

        # choice = 5
        mock_input.return_value = 5
        self.admin.admin_report_management()
        mock_admin_tasks.assert_called_once()

    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_all_reports(self, mock_input, mock_dbconnection):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        data = [('1', '2', '1', 'fire', 'xyz', 'open', 'fire', 'xyz')]
        mock_cursor.execute.return_value = data
        mock_input.return_value = 1
        mock_input.assert_called_once()
        self.admin.show_all_reports()

    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_approved_reports(self, mock_input, mock_dbconnection):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        data = [('1', '2', '1', 'fire', 'xyz', 'open', 'fire', 'xyz')]
        mock_cursor.execute.return_value = data
        mock_input.return_value = 1
        mock_input.assert_called_once()
        self.admin.show_approved_reports()

    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_rejected_reports(self, mock_input, mock_dbconnection):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        data = [('1', '2', '1', 'fire', 'xyz', 'fire', 'xyz')]
        mock_cursor.execute.return_value = data
        mock_input.return_value = 1
        mock_input.assert_called_once()
        self.admin.show_rejected_reports()

    @mock.patch.object(DatabaseConnection, "dbconnection")
    @mock.patch('builtins.input')
    def test_show_pending_reports(self, mock_input, mock_dbconnection):
        mock_conn = mock.Mock()
        mock_cursor = mock.Mock()
        mock_dbconnection.return_value = mock_conn
        mock_conn.cursor.return_value = mock_cursor
        data = [('1', '2', '1', 'fire', 'xyz', 'fire', 'xyz')]
        mock_cursor.execute.return_value = data
        mock_input.return_value = 1
        mock_input.assert_called_once()
        self.admin.show_pending_reports()