Exemple #1
0
 def test_api(self):
     api = Api()
     attendance = AttendanceObject(api)
     self.assertEqual(api, attendance.api)
     api2 = Api()
     attendance.api = api2
     self.assertEqual(api2, attendance.api)
Exemple #2
0
 def create_mock_api(self):
     api_mock = Api()
     api_mock.get_employee_record_by_date = MagicMock(return_value=[
         datetime(2019, 1, 1, 0, 1, 1),
         datetime(2019, 1, 1, 0, 0, 1)
     ])
     return api_mock
Exemple #3
0
 def test_get_time(self):
     user = UserObject(Api())
     self.assertEqual(TimeObject, type(user.time))
     time = TimeObject(1, Api())
     user.time = time
     self.assertEqual(time, user.time)
     with self.assertRaises(TypeError):
         user.time = 'wrong-type'
Exemple #4
0
 def test_is_fired(self):
     user = UserObject(Api())
     self.assertEqual(False, user.is_fired())
     user.discharge_date = datetime(2019, 1, 1)
     self.assertEqual(True, user.is_fired())
     user.discharge_date = None
     self.assertEqual(False, user.is_fired())
Exemple #5
0
 def test_create(self):
     user = UserObject(Api(),
                       ident=1,
                       name='test',
                       discharge_date=datetime(2019, 1, 1))
     self.assertEqual(1, user.ident)
     self.assertEqual('test', user.name)
     self.assertEqual(datetime(2019, 1, 1), user.discharge_date)
Exemple #6
0
 def test_discharge_date_none(self):
     user = UserObject(Api())
     self.assertEqual(None, user.discharge_date)
     user.discharge_date = datetime(2019, 1, 1)
     self.assertEqual(datetime(2019, 1, 1), user.discharge_date)
     user.discharge_date = None
     self.assertEqual(None, user.discharge_date)
     user.discharge_date = ''
     self.assertEqual(None, user.discharge_date)
Exemple #7
0
 def test_get_employee_list_wrong_format(self):
     httpretty.register_uri(
         httpretty.POST,
         Config.ATTENDANCE_BOSSCONTROL_HOST,
         body="{\"result\": [{\"no-code\": \"1\"}]}"
     )
     Config.ATTENDANCE_DEPARTMENT = ['only-one']
     Config.ATTENDANCE_USER_IGNORE = []
     self.assertEqual([], Api().get_employee_list())
Exemple #8
0
 def test_get_employee_record_by_date(self):
     httpretty.register_uri(
         httpretty.POST,
         Config.ATTENDANCE_BOSSCONTROL_HOST,
         body="{\"result\": [{\"timestamp\": \"2019-01-01 00:00:00\"}, {\"wrong-name\": \"2019-01-01 00:00:00\"}]}"
     )
     self.assertEqual(
         [datetime(2019, 1, 1, 0, 0)],
         Api().get_employee_record_by_date('employee_id', datetime.now())
     )
Exemple #9
0
 def test_get_employee_list_by_department(self):
     httpretty.register_uri(
         httpretty.POST,
         Config.ATTENDANCE_BOSSCONTROL_HOST,
         body="{\"result\": [{\"id\": \"1\"}]}"
     )
     self.assertEqual(
         [{'id': '1'}],
         Api().get_employee_list_by_department('department_test', datetime.now(), datetime.now())
     )
Exemple #10
0
    def create_mock_api(self):
        def record_side_effect(employee_id: str, date: datetime):
            if employee_id == 'test1':
                return [
                    datetime(2019, 1, 1, 10, 9, 59),
                    datetime(2019, 1, 1, 10, 0, 0),
                    datetime(2019, 1, 1, 10, 0, 1),
                    datetime(2019, 1, 2, 10, 0, 2),
                    datetime(2019, 1, 2, 10, 0, 1)
                ]
            if employee_id == 'test3':
                return [datetime(2019, 1, 2, 10, 0, 1)]
            if employee_id == 'test4':
                return [
                    datetime(2019, 1, 2, 10, 0, 0),
                    datetime(2019, 1, 3, 10, 0, 0)
                ]

        api_mock = Api()
        api_mock.get_employee_list = MagicMock(
            return_value=[{
                'code': 'test1',
                'name': 'name1',
                'discharge_date': ''
            }, {
                'code': 'test2',
                'name': 'name2',
                'discharge_date': datetime(2018, 1, 1, 10, 1, 0)
            }, {
                'code': 'test3',
                'name': 'name3',
                'discharge_date': None
            }, {
                'code': 'test4',
                'name': 'name4',
            }])
        api_mock.get_employee_record_by_date = MagicMock(
            side_effect=record_side_effect)
        return api_mock
Exemple #11
0
 def test_get_employee_record_by_date_no_results(self):
     httpretty.register_uri(httpretty.POST, Config.ATTENDANCE_BOSSCONTROL_HOST, body="{\"no\": \"results\"}")
     self.assertEqual([], Api().get_employee_record_by_date('employee_id', datetime.now()))
Exemple #12
0
 def test_get_employee_record_by_date_bad_response(self):
     httpretty.register_uri(httpretty.POST, Config.ATTENDANCE_BOSSCONTROL_HOST, body="Bad json string")
     self.assertEqual([], Api().get_employee_record_by_date('employee_id', datetime.now()))
Exemple #13
0
 def __init__(self, api=Api()) -> None:
     super().__init__()
     self._api = api
     self._load_users()
Exemple #14
0
 def test_get_employee_list_by_department_no_results(self):
     httpretty.register_uri(httpretty.POST, Config.ATTENDANCE_BOSSCONTROL_HOST, body="{\"no\": \"results\"}")
     self.assertEqual([], Api().get_employee_list_by_department('department_test', datetime.now(), datetime.now()))
Exemple #15
0
 def test_get_employee_list_by_department_bad_response(self):
     httpretty.register_uri(httpretty.POST, Config.ATTENDANCE_BOSSCONTROL_HOST, body="Bad json string")
     self.assertEqual([], Api().get_employee_list_by_department('department_test', datetime.now(), datetime.now()))
Exemple #16
0
 def test_discharge_date_wrong_type(self):
     user = UserObject(Api())
     with self.assertRaises(TypeError):
         user.discharge_date = 'wrong-type'
Exemple #17
0
 def test_name(self):
     user = UserObject(Api())
     user.name = 'name'
     self.assertEqual('name', user.name)