def test_resource_inequality(): employee_1 = Employee.from_dict(employee_dict) employee_dict_mod = get_employee_dict_mod(id=7, first_name='Beta') employee_2 = Employee.from_dict(employee_dict_mod) assert employee_2.id_ == 7 assert employee_2.last_name == 'Lovelace' assert employee_1 != employee_2 assert hash(employee_1) != hash(employee_2)
def test_resource_ordering(): employee_1 = Employee.from_dict(employee_dict) employee_dict_mod = get_employee_dict_mod(id=7, first_name='Beta') employee_2 = Employee.from_dict(employee_dict_mod) assert employee_1 != employee_2 # id 42 > id 7 assert employee_1 > employee_2 assert employee_2 < employee_1
def test_parse_employee_dyn_changes(): employee = Employee.from_dict(employee_dict, dynamic_fields=dyn_mapping) employee.dynamic['hobbies'].append('horse races') assert 'horse races' in employee.dynamic['hobbies'] d = employee.to_dict() assert d['attributes']['dynamic_44'][ 'value'] == 'math,analytical thinking,music,horse races'
def get_employees(self) -> List[Employee]: """ Get a list of all employee records in your account. :return: list of ``Employee`` instances """ response = self.request_json('company/employees') employees = [Employee.from_dict(d, self) for d in response['data']] return employees
def get_employee(self, employee_id: int) -> Employee: """ Get a single employee with the specified ID. :param employee_id: the Personio ID of the employee to fetch :return: an ``Employee`` instance or a PersonioApiError, if the employee does not exist """ response = self.request_json(f'company/employees/{employee_id}') employee = Employee.from_dict(response['data'], self) return employee
def test_parse_employee(): employee = Employee.from_dict(employee_dict) assert employee.id_ == 42 assert len(employee.dynamic_raw) == 3 assert employee.first_name == 'Ada' assert employee.created_at == datetime(1835, 1, 2, 13, 0, 0, tzinfo=timezone.utc) serialized = employee.to_dict() assert serialized
def test_parse_employee_dyn_typed(): employee = Employee.from_dict(employee_dict, dynamic_fields=dyn_mapping) assert employee.dynamic assert employee.dynamic['birthday'] == datetime(1815, 12, 10, 0, 0, 0, tzinfo=timezone.utc) assert employee.dynamic['hobbies'] == [ 'math', 'analytical thinking', 'music' ] assert len(employee.dynamic_raw) == 3
def test_resource_equality(): employee_1 = Employee.from_dict(employee_dict) employee_2 = Employee.from_dict(employee_dict) assert id(employee_1) != id(employee_2) assert employee_1 == employee_2 assert hash(employee_1) == hash(employee_2)
def test_tuple_view(): employee = Employee.from_dict(employee_dict) employee_tuple = employee.to_tuple() assert isinstance(employee_tuple, tuple) assert len(employee_tuple) > 20 assert employee_tuple.id_ == 42
def test_serialize_employee(): employee = Employee.from_dict(employee_dict, dynamic_fields=dyn_mapping) d = employee.to_dict() assert d == employee_dict