Example #1
0
 def _get_image(self, manifest_record: ManifestRecord) -> Image:
     """
     TODO
     :param manifest_record:
     :return:
     """
     image_reader = self._get_image_reader(manifest_record.storage_location)
     return FunctionBasedImage(manifest_record.identifier, image_reader, manifest_record.image_type)
Example #2
0
 def test_post(self):
     image = create_image()
     assert image not in self.display_controller.image_store
     result = self.client.post(f"/display/{self.display_controller.identifier}/image",
                               data=image.data, headers=set_content_type_header(image))
     self.assertEqual(HTTPStatus.CREATED, result.status_code, result)
     image_identifier = result.json
     expected_image = FunctionBasedImage(image_identifier, lambda: image.data, image.type)
     self.assertEqual(expected_image, self.display_controller.image_store.get(image_identifier))
Example #3
0
def create_image(image_type: Optional[ImageType] = None) -> Image:
    """
    Creates image for testing.
    :return: created image
    """
    if image_type is None:
        image_type = random.choice(list(ImageType))
    identifier = str(uuid4())
    return FunctionBasedImage(identifier, lambda: WHITE_IMAGE.data, image_type)
Example #4
0
 def test_rotate(self):
     self.image_transformer.angle = 45
     image = FunctionBasedImage(WHITE_IMAGE.identifier,
                                lambda: WHITE_IMAGE.data,
                                WHITE_IMAGE.type,
                                rotation=45)
     rotated_image = self.image_transformer.transform(image)
     expected_size = _calculate_new_size(_get_size(image), 45 + 45)
     self.assertEqual(expected_size, _get_size(rotated_image))
Example #5
0
 def test_set_with_same_image_data(self):
     self.image_store.add(WHITE_IMAGE)
     white_image_copy = FunctionBasedImage(BLACK_IMAGE.identifier,
                                           lambda: WHITE_IMAGE.data,
                                           WHITE_IMAGE.type)
     self.image_store.add(white_image_copy)
     self.assertEqual(WHITE_IMAGE,
                      self.image_store.get(WHITE_IMAGE.identifier))
     self.assertEqual(white_image_copy,
                      self.image_store.get(white_image_copy.identifier))
Example #6
0
def _put(display_controller: DisplayController, content_type: str, imageId: str, body: bytes, *, overwrite: bool) \
        -> Tuple[str, HTTPStatus]:
    if content_type is None:
        return f"{CONTENT_TYPE_HEADER} header is required", HTTPStatus.BAD_REQUEST

    image_type = ImageTypeToMimeType.inverse.get(content_type)
    if image_type is None:
        return f"Unsupported image format: {image_type}", HTTPStatus.UNSUPPORTED_MEDIA_TYPE

    image = FunctionBasedImage(imageId, lambda: body, image_type)
    updated = False
    # FIXME: lock over both of these is required!
    if overwrite:
        updated = display_controller.image_store.remove(image.identifier)
    try:
        display_controller.image_store.add(image)
    except ImageAlreadyExistsError:
        return f"Image with same ID already exists: {imageId}", HTTPStatus.CONFLICT

    return imageId, HTTPStatus.CREATED if not updated else HTTPStatus.OK
Example #7
0
from pathlib import Path

from remote_eink.images import ImageType, FunctionBasedImage, DataBasedImage
from remote_eink.tests._resources import BLACK_IMAGE_LOCATION, WHITE_IMAGE_LOCATION

WHITE_IMAGE = DataBasedImage("white-image",
                             Path(WHITE_IMAGE_LOCATION).read_bytes(),
                             ImageType.JPG)
BLACK_IMAGE = FunctionBasedImage(
    "black-image", lambda: Path(BLACK_IMAGE_LOCATION).read_bytes(),
    ImageType.PNG)
Example #8
0
 def _transform(self, image: Image) -> Image:
     return FunctionBasedImage(
         image.identifier, lambda: RotateImageTransformer.rotate(
             image, self.angle, self.expand, self.fill_color), image.type)