def generate_entity_update(cls, entity_dto: GarmentDTO) -> GarmentDTO: updated_dto = GarmentDTO() updated_dto.id = entity_dto.id updated_dto.article = entity_dto.article colors = [color for color in Color if color != entity_dto.color] updated_dto.color = colors[0] return updated_dto
def test_garment_dto_as_serialized_dict(garment_dict): from service.dtos.garment_dto import GarmentDTO dto = GarmentDTO().from_dict(garment_dict) expected_result = garment_dict.copy() expected_result["id"] = str(expected_result["id"]) expected_result["article"] = expected_result["article"].value expected_result["color"] = expected_result["color"].value assert dto.as_serialized_dict() == expected_result
def test_garment_dto_instance(garment_dict): from service.dtos.color import Color from service.dtos.garment_dto import GarmentDTO dto = GarmentDTO().from_dict(garment_dict) assert isinstance(dto, GarmentDTO) assert isinstance(dto.id, uuid.UUID) assert isinstance(dto.color, Color) assert { "id": dto.id, "article": dto.article, "color": dto.color } == garment_dict
def register_garment( self: object, garment_article: GarmentArticle, garment_color: Color, ) -> uuid.UUID: logging.debug("GarmentManagement.register_garment") garment_id = uuid.uuid4() garment_dto = GarmentDTO().from_dict({ "id": garment_id, "article": garment_article, "color": garment_color, }) self.__repository.add_garment(garment_dto=garment_dto) return garment_id
def persisted_garment_dto_population(garment_repository): from service.dtos.color import Color from service.dtos.garment_dto import GarmentDTO, GarmentArticle garment_dto_population = [] for x in range(1, 6): garment_dto = GarmentDTO().from_dict({ "id": uuid.uuid4(), "article": [article for article in GarmentArticle][x % len(GarmentArticle)], "color": [color for color in Color][x % len(Color)], }) garment_repository.add_garment(garment_dto=garment_dto) garment_dto_population.append(garment_dto) return garment_dto_population
def to_dto(self: object) -> GarmentDTO: return GarmentDTO().from_dict(self.asdict())
def put(self: object, garment_id: uuid.UUID): logging.debug(f"GarmentHandler.put(garment_id={garment_id})") garment_data = {"id": garment_id} garment_data.update(request.get_json()) garment_dto = GarmentDTO().from_dict(garment_data) self.__domain.update_garment(garment_dto=garment_dto)
def yellow_hat_dto(yellow_hat_dict): from service.dtos.garment_dto import GarmentDTO return GarmentDTO().from_dict(yellow_hat_dict)
def garment_dto(garment_dict): from service.dtos.garment_dto import GarmentDTO return GarmentDTO().from_dict(garment_dict)
def test_garment_dto_asdict(garment_dict): from service.dtos.garment_dto import GarmentDTO dto = GarmentDTO().from_dict(garment_dict) assert dto.asdict() == garment_dict