Example #1
0
    def test_get_media_items_paginated(
        self,
        google_photos_api_rest_client,
        mocker,
        test_photo_media_item_dict,
        test_video_media_item_dict,
    ):
        mocker.patch(
            "google_photos_archiver.rest_client.requests.get",
            side_effect=[
                MockSuccessResponse(
                    bytes(
                        json.dumps({
                            "mediaItems": [
                                test_photo_media_item_dict,
                            ],
                            "nextPageToken": "abc123",
                        }),
                        "utf-8",
                    )),
                MockSuccessResponse(
                    bytes(
                        json.dumps(
                            {"mediaItems": [test_video_media_item_dict]}),
                        "utf-8",
                    )),
            ],
        )

        media_items = google_photos_api_rest_client.get_media_items_paginated()

        photo_media_item = create_media_item(test_photo_media_item_dict)
        video_media_item = create_media_item(test_video_media_item_dict)

        assert list(media_items) == [photo_media_item, video_media_item]
 def test_create_video_media_item(self, test_video_media_item_dict):
     test_video_media_item_dict_copy = copy.deepcopy(test_video_media_item_dict)
     video_media_item = create_media_item(test_video_media_item_dict)
     assert video_media_item == MediaItem(
         id=test_video_media_item_dict_copy["id"],
         productUrl=test_video_media_item_dict_copy["productUrl"],
         baseUrl=test_video_media_item_dict_copy["baseUrl"],
         mimeType=test_video_media_item_dict_copy["mimeType"],
         mediaMetadata=VideoMediaMetadata(
             creationTime=test_video_media_item_dict_copy["mediaMetadata"][
                 "creationTime"
             ],
             width=test_video_media_item_dict_copy["mediaMetadata"]["width"],
             height=test_video_media_item_dict_copy["mediaMetadata"]["height"],
             video=VideoMetadata(
                 cameraMake=test_video_media_item_dict_copy["mediaMetadata"][
                     "video"
                 ]["cameraMake"],
                 cameraModel=test_video_media_item_dict_copy["mediaMetadata"][
                     "video"
                 ]["cameraModel"],
                 fps=test_video_media_item_dict_copy["mediaMetadata"]["video"][
                     "fps"
                 ],
                 status=test_video_media_item_dict_copy["mediaMetadata"]["video"][
                     "status"
                 ],
             ),
         ),
         filename=test_video_media_item_dict_copy["filename"],
     )
 def test_create_photo_media_item(self, test_photo_media_item_dict):
     test_photo_media_item_dict_copy = copy.deepcopy(test_photo_media_item_dict)
     photo_media_item = create_media_item(test_photo_media_item_dict)
     assert photo_media_item == MediaItem(
         id=test_photo_media_item_dict_copy["id"],
         productUrl=test_photo_media_item_dict_copy["productUrl"],
         baseUrl=test_photo_media_item_dict_copy["baseUrl"],
         mimeType=test_photo_media_item_dict_copy["mimeType"],
         mediaMetadata=PhotoMediaMetadata(
             creationTime=test_photo_media_item_dict_copy["mediaMetadata"][
                 "creationTime"
             ],
             width=test_photo_media_item_dict_copy["mediaMetadata"]["width"],
             height=test_photo_media_item_dict_copy["mediaMetadata"]["height"],
             photo=PhotoMetadata(
                 cameraMake=test_photo_media_item_dict_copy["mediaMetadata"][
                     "photo"
                 ]["cameraMake"],
                 cameraModel=test_photo_media_item_dict_copy["mediaMetadata"][
                     "photo"
                 ]["cameraModel"],
                 focalLength=test_photo_media_item_dict_copy["mediaMetadata"][
                     "photo"
                 ]["focalLength"],
                 apertureFNumber=test_photo_media_item_dict_copy["mediaMetadata"][
                     "photo"
                 ]["apertureFNumber"],
                 isoEquivalent=test_photo_media_item_dict_copy["mediaMetadata"][
                     "photo"
                 ]["isoEquivalent"],
             ),
         ),
         filename=test_photo_media_item_dict_copy["filename"],
     )
def create_album_or_media_item(
    album_or_media_item: Dict[str, Any]
) -> Union[Album, MediaItem]:
    try:
        return create_media_item(album_or_media_item)
    except (KeyError, TypeError):
        try:
            return create_album(album_or_media_item)
        except Exception as err:
            raise GooglePhotosApiRestClientError(
                f"Unable to `create_album_or_media_item` from {album_or_media_item}"
            ) from err
Example #5
0
def test_video_media_item(test_video_media_item_dict) -> MediaItem:
    return create_media_item(test_video_media_item_dict)