def test_immutable_sequence_append(): sequence = Vector([0, 1, 2]) appended_sequence = sequence.append(3) assert appended_sequence is not sequence assert isinstance(appended_sequence, Vector) assert isinstance(sequence, Vector) assert [0, 1, 2, 3] == appended_sequence == [0, 1, 2, 3]
def test_immutable_sequence_remove(): sequence = Vector([0, 1, 2]) removed_sequence = sequence.remove(1) assert removed_sequence is not sequence assert isinstance(removed_sequence, Vector) assert isinstance(sequence, Vector) assert [0, 2] == removed_sequence == [0, 2] assert [0, 1, 2] == sequence == [0, 1, 2]
def test_immutable_sequence_insert(): sequence = Vector([0, 1, 2]) inserted_sequence = sequence.insert(1, 9) assert inserted_sequence is not sequence assert isinstance(inserted_sequence, Vector) assert isinstance(sequence, Vector) assert [0, 9, 1, 2] == inserted_sequence == [0, 9, 1, 2] assert [0, 1, 2] == sequence == [0, 1, 2]
def test_immutable_sequence_reverse(): sequence = Vector([0, 1, 2]) reversed_sequence = sequence.reverse() assert reversed_sequence is not sequence assert isinstance(reversed_sequence, Vector) assert isinstance(sequence, Vector) assert [2, 1, 0] == reversed_sequence == [2, 1, 0] assert [0, 1, 2] == sequence == [0, 1, 2]
def test_immutable_sequence_extend(): sequence = Vector([0, 1, 2]) extend_sequence = [3, 4, 5] extended_sequence = sequence.extend(extend_sequence) assert extended_sequence is not sequence assert extended_sequence is not extend_sequence assert isinstance(extended_sequence, Vector) assert isinstance(sequence, Vector) assert [0, 1, 2, 3, 4, 5] == extended_sequence == [0, 1, 2, 3, 4, 5]
def test_immutable_sequence_copy(): sequence = Vector([0, 1, 2]) copied_sequence = sequence.copy() assert copied_sequence is not sequence assert isinstance(copied_sequence, Vector) assert isinstance(sequence, Vector) assert copied_sequence == sequence == copied_sequence assert [0, 1, 2] == copied_sequence == [0, 1, 2] assert [0, 1, 2] == sequence == [0, 1, 2]
def test_immutable_sequence_init(): assert [] == Vector() == [] assert [] == Vector([]) == [] assert [] == Vector(()) == [] # assert [] == Vector({}) == [] # Syntax Error sequence = Vector([0, 1, 2]) assert isinstance(sequence, Vector) assert 0 == sequence[0] == 0 assert [0, 1, 2] == sequence == [0, 1, 2] assert (0, 1, 2) != sequence != (0, 1, 2) assert {0, 1, 2} != sequence != {0, 1, 2} assert [0, 2, 4] == Vector([element * 2 for element in sequence]) == [0, 2, 4]
async def get( employee_id: entity.Id, application_id: entity.Id ) -> Tuple[Optional[employee.Employee], Optional[application.Application], Optional[workflow.Workflow], ]: employee_entity = employee.Employee( id_=employee_id, username="******", full_name="test", email_address="test_mail_address", duties=Vector([]), join_date=None, retirement_date=None, hashed_password="", disabled=False, ) application_entity = application.Application( id_=application_id, applicant_id=application_id, workflow_id=workflow_id, ) workflow_entity = workflow.Workflow( id_=workflow_id, name="test", description="test", duties=governance.Duties.MANAGEMENT_DEPARTMENT, ) return employee_entity, application_entity, workflow_entity
def test_immutable_sequence_add(): # immutable + mutalbe collection = Vector([0, 1, 2]) im_collection = collection + [3] assert im_collection is not collection assert isinstance(im_collection, Vector) assert [0, 1, 2, 3] == im_collection == [0, 1, 2, 3] assert [0, 1, 2] == collection == [0, 1, 2] assert im_collection != collection # immutable + immutable other_collection = Vector([3, 4, 5]) ii_collection = collection + other_collection assert ii_collection is not collection assert ii_collection is not other_collection assert isinstance(ii_collection, Vector) assert [0, 1, 2, 3, 4, 5] == ii_collection == [0, 1, 2, 3, 4, 5] assert [0, 1, 2] == collection == [0, 1, 2] assert [3, 4, 5] == other_collection == [3, 4, 5] assert ii_collection != collection assert ii_collection != other_collection
async def insert_user(): entity = employee.Employee( id_=employee_id, username="******", full_name="John Doe", email_address="*****@*****.**", duties=Vector([governance.Duties.MANAGEMENT_DEPARTMENT]), join_date=datetime.now(), retirement_date=None, # plain_password="******", hashed_password="******", disabled=False, ) await employee_dao.EmployeeDocument(**entity.as_dict()).commit()
def test_immutable_sequence_index(): sequence = Vector([0, 1, 2]) index = sequence.index(1, 0, 2) assert isinstance(sequence, Vector) assert 1 == index assert [0, 1, 2] == sequence == [0, 1, 2]
def edit( self, /, *, workflow: Workflow, name: str, description: str, duties: governance.Duties, ) -> Result[Vector[Error], Workflow]: """ワークフローを編集する FIXME: 申請済がある場合はどうする? """ errors: list[Error] = list() if not name: errors.append(NoNameError("名称が未定です.")) if not description: errors.append(NoDescriptionError("説明が未記入です.")) if (not duties) and (duties not in self.duties): errors.append(NoJobAuthorityError("職務権限がありません.")) if errors: return Err(Vector(errors)) return Ok( workflow._update( name=name if name else workflow.name, description=description if description else description, duties=duties if duties else duties, ) )
def test_immutable_sequence_redece(): sequence = Vector([0, 1, 2]) reduced_sequence = sequence.reduce( function=lambda left, right: left * right, initial=1) assert reduced_sequence is not sequence assert 0 == reduced_sequence
def test_immutable_sequence_count(): sequence = Vector([0, 1, 2]) assert 1 == sequence.count(0) assert type(sequence) assert [0, 1, 2] == sequence == [0, 1, 2]
def test_immutable_sequence_map(): sequence = Vector([0, 1, 2]) mapped_sequence = sequence.map(function=lambda x: x * 2) assert mapped_sequence is not sequence assert [0, 2, 4] == mapped_sequence
def test_immutable_sequence_size(): sequence = Vector([0, 1, 2]) assert 3 == sequence.size()
def test_immutable_sequence_non_empty(): sequence = Vector([0, 1, 2]) assert True is sequence.non_empty()
def test_immutable_sequence_empty(): sequence = Vector([0, 1, 2]) assert False is sequence.is_empty()
async def get( employee_id: entity.Id, application_id: entity.Id ) -> Result[ Exception, Tuple[ Optional[employee.Employee], Optional[application.Application], Optional[workflow.Workflow], ], ]: try: got_employee_dto = await employee_dao.get(id_=employee_id) got_employee = ( None if got_employee_dto is None else employee.Employee( id_=mongodb.ULID(got_employee_dto.id_), username=got_employee_dto.username, full_name=got_employee_dto.full_name, email_address=got_employee_dto.email_address, hashed_password=got_employee_dto.hashed_password, duties=Vector( [governance.Duties(item) for item in got_employee_dto.duties] ), join_date=got_employee_dto.join_date, retirement_date=got_employee_dto.retirement_date, disabled=got_employee_dto.disabled, ) ) got_application_dto = await application_dao.get(id_=application_id) got_application = ( None if got_application_dto is None else application.Application( id_=mongodb.ULID(got_application_dto.id_), applicant_id=mongodb.ULID(got_application_dto.applicant_id), workflow_id=mongodb.ULID(got_application_dto.workflow_id), route=application.Route( [ application.Progress( approver_id=mongodb.ULID(progress.approver_id), approve=progress.approve, process_datetime=progress.process_datetime, comment=progress.comment, ) for progress in got_application_dto.route ] ), ) ) got_workflow_dto = await workflow_dao.get(id_=got_application.workflow_id) got_workflow = ( None if got_workflow_dto is None else workflow.Workflow( id_=mongodb.ULID(got_workflow_dto.id_), name=got_workflow_dto.name, description=got_workflow_dto.description, duties=governance.Duties(got_workflow_dto.duties), ) ) except Exception as error: return Err(error) return Ok((got_employee, got_application, got_workflow))