예제 #1
0
 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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
 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
예제 #5
0
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
예제 #6
0
 def to_dto(self: object) -> GarmentDTO:
     return GarmentDTO().from_dict(self.asdict())
예제 #7
0
 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)
예제 #8
0
def yellow_hat_dto(yellow_hat_dict):
    from service.dtos.garment_dto import GarmentDTO
    return GarmentDTO().from_dict(yellow_hat_dict)
예제 #9
0
def garment_dto(garment_dict):
    from service.dtos.garment_dto import GarmentDTO
    return GarmentDTO().from_dict(garment_dict)
예제 #10
0
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