Beispiel #1
0
def test_format_none():
    """
    Test the format (portrait/landscape) function raises an exception with None images.
    """
    with pytest.raises(ValueError):
        assert not IcloudPhotos.is_correct_format(None, "portrait")

    with pytest.raises(ValueError):
        assert not IcloudPhotos.is_correct_format(None, "landscape")
Beispiel #2
0
def test_format_invalid_orientation():
    """
    Test the format method for a photo if the orientation is an invalid value.
    """
    photo = DummyPhoto()
    with pytest.raises(ValueError):
        assert IcloudPhotos.is_correct_format(photo, "blah")
Beispiel #3
0
def test_is_image_with_photos(mock_photo_record):
    """
    Test photo is recognised as an image with various MIME types.

    :param mock_photo_record: mock photo setup by the Mock framework
    """
    photo = DummyPhoto()

    mock_photo_record.return_value = {
        "fields": {
            "itemType": {
                "value": "public.jpeg"
            }
        }
    }
    assert IcloudPhotos.is_image(photo)

    mock_photo_record.return_value = {
        "fields": {
            "itemType": {
                "value": "public.png"
            }
        }
    }
    assert IcloudPhotos.is_image(photo)

    mock_photo_record.return_value = {
        "fields": {
            "itemType": {
                "value": "public.heic"
            }
        }
    }
    assert IcloudPhotos.is_image(photo)

    mock_photo_record.return_value = {
        "fields": {
            "itemType": {
                "value": "public.tiff"
            }
        }
    }
    assert IcloudPhotos.is_image(photo)
Beispiel #4
0
def test_is_image_with_none_photos(mock_photo_record):
    """
    Test photo is not classified as an image with various (non-image) MIME types.

    :param mock_photo_record: mock photo setup by the Mock framework
    """
    photo = DummyPhoto()
    mock_photo_record.return_value = {
        "fields": {
            "itemType": {
                "value": "public.mpeg"
            }
        }
    }
    assert not IcloudPhotos.is_image(photo)
Beispiel #5
0
def main():
    """
    Read command-line args and start the download
    """
    parser = argparse.ArgumentParser(description="icloud photo frame")
    parser.add_argument("user", help="icloud user")
    parser.add_argument("password", help="password")
    parser.add_argument("--output",
                        help="folder to store downloaded network",
                        default="tmp/raw")
    parser.add_argument("--sample",
                        help="number of network to download",
                        type=int,
                        default=5)
    parser.add_argument("--album",
                        help="icloud album to find network",
                        default="All Photos")
    parser.add_argument("--orientation",
                        help="orientation of network",
                        choices=["portrait", "landscape"],
                        default=None)
    parser.add_argument("--list",
                        help="list albums (no photo downloading)",
                        action='store_true',
                        default=False)
    args = parser.parse_args()
    print(args)

    api = IcloudPhotos(args.user, args.password)

    if args.list:
        print("Albums:")
        albums = api.get_albums()
        for album in albums:
            print(album)
        sys.exit(1)

    try:
        # get all network in the photo frame album
        logger.info("Downloading photo list...")
        photos = api.get_all_photos(args.album, args.orientation)
    except KeyError as exception:
        print("Could not find album: ", exception)
        sys.exit(1)

    # get a random sample to download
    logger.info("Selecting random sample (%d from %d)", args.sample,
                len(photos))
    photos_sample = photo_utils.get_sample(photos, args.sample)

    logger.info("Downloading photos to %s...", args.output)
    IcloudPhotos.download(photos_sample, args.output)
Beispiel #6
0
def test_is_image_with_none():
    """
    Test the is_image method handles None images without failing.
    """
    assert not IcloudPhotos.is_image(None)
Beispiel #7
0
def test_format(mock_photo_master_record, mock_photo_asset_record,
                mock_photo_dimensions):
    """
    Test photo is recognised corrctly as portrait vs. landscape (including when rotated).

    :param mock_photo_master_record: mock photo setup by the Mock framework
    :param mock_photo_asset_record: mock photo setup by the Mock framework
    :param mock_photo_dimensions: mock photo setup by the Mock framework
    """
    photo = DummyPhoto()

    mock_photo_master_record.return_value = {
        "fields": {
            "originalOrientation": {
                "value": 3
            }
        }
    }
    mock_photo_asset_record.return_value = {
        "fields": {
            "orientation": {
                "value": 3
            }
        }
    }
    mock_photo_dimensions.return_value = (50, 100)
    assert IcloudPhotos.is_correct_format(photo, "portrait")
    assert not IcloudPhotos.is_correct_format(photo, "landscape")

    mock_photo_master_record.return_value = {
        "fields": {
            "originalOrientation": {
                "value": 3
            }
        }
    }
    mock_photo_asset_record.return_value = {
        "fields": {
            "orientation": {
                "value": 3
            }
        }
    }
    mock_photo_dimensions.return_value = (100, 50)
    assert not IcloudPhotos.is_correct_format(photo, "portrait")
    assert IcloudPhotos.is_correct_format(photo, "landscape")

    # photo is rotated so dimensions needs to be swapped
    mock_photo_master_record.return_value = {
        "fields": {
            "originalOrientation": {
                "value": 6
            }
        }
    }
    mock_photo_asset_record.return_value = {
        "fields": {
            "orientation": {
                "value": 6
            }
        }
    }
    mock_photo_dimensions.return_value = (100, 50)
    assert IcloudPhotos.is_correct_format(photo, "portrait")
    assert not IcloudPhotos.is_correct_format(photo, "landscape")

    mock_photo_master_record.return_value = {
        "fields": {
            "originalOrientation": {
                "value": 8
            }
        }
    }
    mock_photo_asset_record.return_value = {
        "fields": {
            "orientation": {
                "value": 8
            }
        }
    }
    mock_photo_dimensions.return_value = (100, 50)
    assert IcloudPhotos.is_correct_format(photo, "portrait")
    assert not IcloudPhotos.is_correct_format(photo, "landscape")