예제 #1
0
 def test_show_request_exception(self, mock_db, mock_print):
     mock_db().get_requests.side_effect = Exception
     gpm = GPM()
     gpm.show_requests()
     mock_print.assert_called_once()
     mock_db().get_requests.assert_called_once()
     mock_db().rollback_data.assert_called_once()
예제 #2
0
 def test_show_projects(self, mock_db, mock_table):
     gpm = GPM()
     gpm.gpm_id = 'sample'
     gpm.show_projects()
     mock_db().get_gpm_projects_details.assert_called_once_with('sample')
     mock_db().get_gpm_projects_details().fetchall.assert_called_once()
     mock_table.assert_called_once()
예제 #3
0
 def test_get_members_list(self, mock_db):
     mock_db().get_user_names.return_value = [['name', 'id']]
     sample_dict = {'name': 'id'}
     gpm = GPM()
     result = gpm.get_members_list()
     mock_db().get_user_names.assert_called_once()
     self.assertEqual(result, sample_dict)
예제 #4
0
 def test_complete_member_project_exception(self, mock_db,
                                            mock_project_list, mock_print):
     mock_project_list.side_effect = sqlite3.Error
     gpm = GPM()
     gpm.complete_member_project()
     self.assertEqual(mock_print.call_count, 2)
     mock_db().rollback_data.assert_called_once()
예제 #5
0
 def test_update_member_exception(self, mock_gpm_list, mock_db, mock_print):
     mock_gpm_list.side_effect = Exception
     gpm = GPM()
     gpm.update_members()
     mock_print.assert_called_once()
     mock_gpm_list.assert_called_once()
     mock_db().rollback_data.assert_called_once()
예제 #6
0
 def test_delete_project_members_request_exception(self, mock_db,
                                                   mock_print):
     mock_db().get_created_by_id.side_effect = sqlite3.Error
     gpm = GPM()
     gpm.delete_project_request()
     mock_print.assert_called_once()
     mock_db().get_created_by_id.assert_called_once()
     mock_db().rollback_data.assert_called_once()
예제 #7
0
 def test_update_gpm_back(self, mock_gpm_list, mock_menu, mock_input):
     mock_gpm_list.return_value = {'name1': 'id1'}
     mock_menu().draw_menu.side_effect = ['BACK']
     gpm = GPM()
     gpm.update_members()
     mock_input.assert_called_once()
     mock_menu().draw_menu.assert_called_once()
     mock_gpm_list.assert_called_once()
예제 #8
0
    def test_show_members_none(self, mock_db, mock_print):
        mock_db(
        ).get_subordinate_details.return_value.fetchall.return_value = []
        gpm = GPM()
        gpm.show_members()

        mock_db().get_subordinate_details.assert_called_once()
        mock_db().get_subordinate_details().fetchall.assert_called_once()
        mock_print.assert_called_once()
예제 #9
0
 def test_create_member_invalid_gender(self, mock_print, mock_input):
     mock_input.side_effect = [
         'name', 'pass@Pas123', 'username', 'state', 'district', '232323',
         '21', 'male', ''
     ]
     gpm = GPM()
     gpm.create_members()
     mock_print.assert_called_once()
     self.assertEqual(mock_input.call_count, 9)
예제 #10
0
    def test_show_request_no_request(self, mock_db, mock_print):
        mock_db().get_requests.return_value.fetchall.return_value = []
        mock_db().get_requests.return_value.description.return_value = ()
        gpm = GPM()
        gpm.show_requests()

        mock_db().get_requests.assert_called_once()
        mock_db().get_requests().fetchall.assert_called_once()
        self.assertEqual(mock_print.call_count, 1)
예제 #11
0
 def test_project_completion_back(self, mock_print, mock_input, mock_menu,
                                  mock_project_list):
     mock_project_list.return_value = {'name': 'project_id'}
     mock_menu().draw_menu.return_value = 'BACK'
     gpm = GPM()
     gpm.project_completion()
     mock_project_list.assert_called_once()
     mock_menu().draw_menu.assert_called_once()
     mock_print.assert_called_once()
     mock_input.assert_called_once()
예제 #12
0
 def test_bdo_features(self, mock_print, mock_menu, mock_os, mock_input,
                       mock_getattr, mock_show_projects):
     gpm = GPM()
     mock_getattr.side_effect = [mock_show_projects, SystemExit]
     self.assertRaises(SystemExit, gpm.gpm_features)
     self.assertEqual(mock_menu().draw_menu.call_count, 2)
     self.assertEqual(mock_getattr.call_count, 2)
     self.assertEqual(mock_input.call_count, 3)
     mock_os.system.assert_any_call('clear')
     mock_print.assert_any_call("choose feature :\n")
예제 #13
0
    def test_show_members(self, mock_db, mock_decrypt, mock_table):
        mock_db(
        ).get_subordinate_details.return_value.fetchall.return_value = [
            ('dummy', 'dummy', 'dummy')
        ]
        gpm = GPM()
        gpm.show_members()

        mock_db().get_subordinate_details.assert_called_once()
        mock_db().get_subordinate_details().fetchall.assert_called_once()
        mock_decrypt.assert_called_once()
        mock_table.assert_called_once()
예제 #14
0
    def test_assign_members_to_projects_back(self, mock_input, mock_menu,
                                             mock_project_list, mock_print):
        mock_project_list.return_value = {'project_name': 'project_id'}
        mock_menu().draw_menu.return_value = 'BACK'

        gpm = GPM()
        gpm.assign_members_to_projects()

        mock_print.assert_called_once()
        mock_input.assert_called_once()
        mock_menu().draw_menu.assert_called_once()
        mock_project_list.assert_called_once()
예제 #15
0
    def test_update_member_invalid_age(self, mock_input, mock_gpm_list,
                                       mock_validation, mock_print, mock_menu):
        mock_gpm_list.return_value = {'name1': 'id1', 'name2': 'id2'}
        mock_menu().draw_menu.side_effect = ['name1', 'AGE']
        mock_validation.age.return_value = False
        mock_input.side_effect = ['', '', 'dummy_data', '']
        gpm = GPM()
        gpm.update_members()

        self.assertEqual(mock_menu().draw_menu.call_count, 2)
        self.assertEqual(mock_print.call_count, 2)
        mock_gpm_list.assert_called_once()
        self.assertEqual(mock_input.call_count, 4)
        mock_validation.age.assert_called_once_with('dummy_data')
예제 #16
0
 def test_create_member(self, mock_db, mock_print, mock_input,
                        mock_encrypt):
     mock_input.side_effect = [
         'name', 'pass@Pas123', 'username', 'state', 'district', '232323',
         '21', 'M'
     ]
     gpm = GPM()
     gpm.create_members()
     mock_db().add_user.assert_called_once()
     mock_db().add_personal_details.assert_called_once()
     mock_db().commit_data.assert_called_once()
     mock_encrypt.assert_called_once()
     mock_print.assert_called_once()
     self.assertEqual(mock_input.call_count, 8)
예제 #17
0
파일: login.py 프로젝트: riyaz489/mnrega
def main():
    """
    this method is used to call main menu for login
    """
    conn = ConnectDb()
    try:
        os.system('clear')
        # select role for login
        print("login as:\n")
        menu = Menu()
        roles = [x.name for x in Role]
        roles.extend([str(BackButton.EXIT.name)])
        role = menu.draw_menu(roles)
        role_id = Role[role].value
        input()

        # get user name and password for login
        user_name = input("enter user name: ")
        password = getpass()

        # check user authentication
        result = conn.get_user_with_role(user_name, role_id)
        flag = True
        if result is not None:
            os.system('clear')
            actual_pass = decrypt_pass(result[1])
            if str(actual_pass.decode("utf-8")) == password:
                flag = False
                if role_id == int(Role.BDO.value):
                    bdo = BDO()
                    bdo.bdo_id = result[0]
                    bdo.bdo_features()
                elif role_id == int(Role.GPM.value):
                    gpm = GPM()
                    gpm.gpm_id = result[0]
                    gpm.gpm_features()
                elif role_id == int(Role.Member.value):
                    member = Member()
                    member.member_id = result[0]
                    member.member_features()
        if result is None or flag:
            print(Color.F_Red + 'wrong credentials' + Base.END)
            input()
            main()

    except Exception as e:
        print(e)
        sys.exit()
    finally:
        conn.close_conn()
예제 #18
0
    def test_project_completion_no_member(self, mock_db, mock_print,
                                          mock_input, mock_menu,
                                          mock_project_list):
        mock_project_list.return_value = {'name': 'project_id'}
        mock_db().get_project_members.return_value = []
        mock_menu().draw_menu.return_value = 'name'
        gpm = GPM()
        gpm.project_completion()

        mock_project_list.assert_called_once()
        mock_menu().draw_menu.assert_called_once()
        mock_input.assert_called_once()
        mock_db().get_project_members.assert_called_once()
        self.assertEqual(mock_print.call_count, 2)
예제 #19
0
 def show_members(self):
     """
     this method is used to print members and gpm of current bdo.
     """
     print("members List:\n")
     gpm_list = self.conn.get_user_names(self.bdo_id)
     if len(gpm_list) == 0:
         print(Color.F_Green +
               "you don't have any GPM  and members under you" + Base.END)
         return
     for gpm_detail in gpm_list:
         print('GPM name ' + gpm_detail[0])
         gpm = GPM()
         gpm.gpm_id = gpm_detail[1]
         gpm.show_members()
예제 #20
0
    def test_delete_project_members_similar_request(self, mock_db, mock_print):
        mock_db().get_created_by_id.return_value = ['bdo_id']
        mock_db().get_approvals_list.return_value = [[
            'WAGE|member1|member_id|project_id|project1'
        ]]
        gpm = GPM()
        gpm.project_id = 'project_id'
        gpm.gpm_id = 'gpm_id'
        gpm.member_id = 'member_id'

        gpm.delete_project_request()

        mock_db().get_created_by_id.assert_called_once()
        mock_db().get_approvals_list.assert_called_once()
        mock_print.assert_called_once()
예제 #21
0
    def test_complete_member_project(self, mock_db, mock_input, mock_menu,
                                     mock_project_list, mock_delete_request,
                                     mock_print):
        mock_project_list.return_value = {'name': 'id'}
        mock_db().get_project_member_name.return_value = [[
            'member_id', 'member_name'
        ]]
        mock_menu().draw_menu.side_effect = ['name', 'member_name']
        gpm = GPM()
        gpm.complete_member_project()

        mock_project_list.assert_called_once()
        self.assertEqual(mock_menu().draw_menu.call_count, 2)
        mock_db().commit_data.assert_called_once()
        mock_db().get_project_member_name.assert_called_once()
        mock_delete_request.assert_called_once()
예제 #22
0
    def test_update_member_user_details(self, mock_db, mock_input,
                                        mock_gpm_list, mock_print, mock_menu,
                                        mock_encrypt):
        mock_gpm_list.return_value = {'name1': 'id1', 'name2': 'id2'}
        mock_menu().draw_menu.side_effect = ['name1', 'PASSWORD']
        mock_encrypt.return_value = 'Pass@123'
        mock_input.side_effect = ['', '', 'Pass@123']
        gpm = GPM()
        gpm.update_members()

        self.assertEqual(mock_menu().draw_menu.call_count, 2)
        self.assertEqual(mock_print.call_count, 2)
        mock_gpm_list.assert_called_once()
        self.assertEqual(mock_input.call_count, 3)
        mock_db().update_user.assert_called_once_with('PASSWORD', mock.ANY,
                                                      'Pass@123')
        mock_db().commit_data.assert_called_once()
예제 #23
0
    def test_update_member_personal_detail(self, mock_db, mock_input,
                                           mock_gpm_list, mock_validation,
                                           mock_print, mock_menu):
        mock_gpm_list.return_value = {'name1': 'id1', 'name2': 'id2'}
        mock_menu().draw_menu.side_effect = ['name1', 'AGE']
        mock_validation.age.return_value = True
        mock_input.side_effect = ['', '', '21']
        gpm = GPM()
        gpm.update_members()

        self.assertEqual(mock_menu().draw_menu.call_count, 2)
        self.assertEqual(mock_print.call_count, 2)
        mock_gpm_list.assert_called_once()
        mock_validation.age.assert_called_once()
        self.assertEqual(mock_input.call_count, 3)
        mock_db().update_personal_details.assert_called_once_with(
            'AGE', mock.ANY, '21')
        mock_db().commit_data.assert_called_once()
예제 #24
0
    def test_show_request_invalid_index(self, mock_menu, mock_db, mock_print,
                                        mock_input, mock_table):
        mock_db().get_requests.return_value.description.return_value = [
            'dummy', 'dummy', 'dummy', 'dummy', 'dummy'
        ]
        mock_db().get_requests.return_value.fetchall.return_value = [[
            'ISSUES', 'dummy', 'request message', 'dummy', 'dummy'
        ]]
        mock_menu().draw_menu.return_value = 'APPROVED'
        mock_input.side_effect = ['invalid_row', '']

        gpm = GPM()
        gpm.show_requests()

        mock_table.assert_called_once()
        mock_db().get_requests.assert_called_once()
        mock_db().get_requests().fetchall.assert_called_once()
        self.assertEqual(mock_print.call_count, 3)
        self.assertEqual(mock_input.call_count, 2)
예제 #25
0
    def test_assign_members_to_projects_member_exceeded(
            self, mock_db, mock_input, mock_menu, mock_member_list,
            mock_project_list, mock_print):
        mock_member_list.return_value = {
            'name': 'member_id',
            'name2': 'member_id2'
        }
        mock_project_list.return_value = {'project_name': 'project_id'}
        mock_db().get_project_members.return_value = [['member_id']]
        mock_db().get_project_members_required.return_value = [1]
        mock_menu().draw_menu.return_value = 'project_name'

        gpm = GPM()
        gpm.assign_members_to_projects()

        mock_member_list.assert_called_once()
        self.assertEqual(mock_menu().draw_menu.call_count, 1)
        self.assertEqual(mock_input.call_count, 1)
        self.assertEqual(mock_print.call_count, 3)
        mock_db().get_project_members_required.assert_called_once()
        mock_db().get_project_members.assert_called_once()
예제 #26
0
    def test_show_request_rejected_issue(self, mock_menu, mock_db, mock_print,
                                         mock_input, mock_table):
        mock_db().get_requests.return_value.description.return_value = [
            'dummy', 'dummy', 'dummy', 'dummy', 'dummy'
        ]
        mock_db().get_requests.return_value.fetchall.return_value = [[
            'ISSUES', 'dummy', 'member request msg', 'dummy', 'dummy'
        ]]
        mock_menu().draw_menu.return_value = 'REJECTED'
        mock_input.side_effect = ['0', '']

        gpm = GPM()
        gpm.show_requests()

        mock_menu().draw_menu.assert_called_once()
        mock_table.assert_called_once()
        mock_db().get_requests.assert_called_once()
        mock_db().resolve_request.assert_called_once()
        mock_db().commit_data.assert_called_once()
        mock_db().get_requests().fetchall.assert_called_once()
        self.assertEqual(mock_print.call_count, 3)
        self.assertEqual(mock_input.call_count, 2)
예제 #27
0
    def test_delete_project_members_request(self, mock_db, mock_print):
        mock_db().get_created_by_id.return_value = ['bdo_id']
        mock_db().get_approvals_list.return_value = [[
            'WAGE|member1|cc29a75e-8bf8-48e0-85f5-6990f4cc87e8|4b602623-'
            '8d64-4fdf-8e9f-18b7b3f4389b|project1'
        ]]
        mock_db().get_user_name.return_value = ['name']
        mock_db().get_project_name.return_value = ['project_name']
        gpm = GPM()
        gpm.project_id = 'project_id'
        gpm.gpm_id = 'gpm_id'
        gpm.member_id = 'member_id'

        gpm.delete_project_request()

        mock_db().get_created_by_id.assert_called_once()
        mock_db().get_approvals_list.assert_called_once()
        mock_db().get_user_name.assert_called_once_with('member_id')
        mock_db().get_project_name.assert_called_once_with('project_id')
        mock_db().register_complain.assert_called_once()
        mock_db().commit_data.assert_called_once()
        mock_print.assert_called_once()
예제 #28
0
    def test_assign_members_to_projects(self, mock_db, mock_input, mock_menu,
                                        mock_member_list, mock_project_list,
                                        mock_member_request, mock_print):
        mock_member_list.return_value = {
            'name': 'member_id',
            'name2': 'member_id2'
        }
        mock_project_list.return_value = {'project_name': 'project_id'}
        mock_db().get_project_members.return_value = [['member_id']]
        mock_db().get_project_members_required.return_value = [2]
        mock_menu().draw_menu.side_effect = ['project_name', 'name2']

        gpm = GPM()
        gpm.assign_members_to_projects()

        mock_member_list.assert_called_once()
        mock_member_request.assert_called_once()
        self.assertEqual(mock_menu().draw_menu.call_count, 2)
        self.assertEqual(mock_input.call_count, 2)
        self.assertEqual(mock_print.call_count, 2)
        mock_db().get_project_members_required.assert_called_once()
        mock_db().get_project_members.assert_called_once()
예제 #29
0
 def test_bdo_features_exception(self, mock_print, mock_menu, mock_input,
                                 mock_getattr, mock_sys):
     gpm = GPM()
     gpm.gpm_features()
     mock_sys.exit.assert_called_once()
     self.assertEqual(mock_print.call_count, 2)
예제 #30
0
 def test_create_member_exception(self, mock_print, mock_input, mock_db):
     gpm = GPM()
     gpm.create_members()
     mock_input.assert_called_once()
     mock_print.assert_called_once()
     mock_db().rollback_data.assert_called_once()