def test_upload_gallery(self, subprocess_run):
        subprocess_run.return_value = subprocess.CompletedProcess([],
                                                                  returncode=0)

        with TempDirectory() as tempdir:
            # Setup mock file and uploader
            tempdir.write('index.html', b'')
            gallery_path = os.path.join(tempdir.path, 'index.html')
            uploader = get_uploader('aws')

            # Test upload to bucket
            uploader.upload_gallery('s3://testbucket/path/', gallery_path)
            subprocess_run.assert_called_with([
                'aws', 's3', 'sync', gallery_path, 's3://testbucket/path/',
                '--exclude', '.DS_Store'
            ])

            # Test upload to bucket without prefix
            uploader.upload_gallery('testbucket/path/', gallery_path)
            subprocess_run.assert_called_with([
                'aws', 's3', 'sync', gallery_path, 's3://testbucket/path/',
                '--exclude', '.DS_Store'
            ])

            # Test upload to bucket without trailing /
            uploader.upload_gallery('s3://testbucket/path', gallery_path)
            subprocess_run.assert_called_with([
                'aws', 's3', 'sync', gallery_path, 's3://testbucket/path/',
                '--exclude', '.DS_Store'
            ])
예제 #2
0
    def test_upload_gallery(self, subprocess_run):
        subprocess_run.return_value = subprocess.CompletedProcess([],
                                                                  returncode=0)

        with TempDirectory() as tempdir:
            # Setup mock file and uploader
            tempdir.write("index.html", b"")
            gallery_path = os.path.join(tempdir.path, "index.html")
            uploader = get_uploader("aws")

            # Test upload to bucket
            uploader.upload_gallery("s3://testbucket/path/", gallery_path)
            subprocess_run.assert_called_with([
                "aws",
                "s3",
                "sync",
                gallery_path,
                "s3://testbucket/path/",
                "--exclude",
                ".DS_Store",
            ])

            # Test upload to bucket without prefix
            uploader.upload_gallery("testbucket/path/", gallery_path)
            subprocess_run.assert_called_with([
                "aws",
                "s3",
                "sync",
                gallery_path,
                "s3://testbucket/path/",
                "--exclude",
                ".DS_Store",
            ])

            # Test upload to bucket without trailing /
            uploader.upload_gallery("s3://testbucket/path", gallery_path)
            subprocess_run.assert_called_with([
                "aws",
                "s3",
                "sync",
                gallery_path,
                "s3://testbucket/path/",
                "--exclude",
                ".DS_Store",
            ])
    def test_get_uploader(self):
        self.assertIs(AWSUploader, get_uploader('aws').__class__)
        self.assertIs(NetlifyUploader, get_uploader('netlify').__class__)

        with self.assertRaises(spg_common.SPGException):
            get_uploader('non_existing_uploader')
예제 #4
0
 def test_no_location(self):
     uploader = get_uploader("aws")
     self.assertFalse(uploader.check_location(""))
def main():
    """
    Uploads the gallery to the specified hosting provider
    """

    # Parse the arguments
    args = parse_args()

    # Create the uploader
    try:
        uploader = get_uploader(args.hosting)
    except spg_common.SPGException as exception:
        spg_common.log(exception.message)
        sys.exit(1)
    except Exception as exception:
        spg_common.log(
            f"Something went wrong while preparing the upload: {str(exception)}"
        )
        sys.exit(1)

    # Read the gallery config
    gallery_root = args.path
    gallery_config_path = os.path.join(gallery_root, "gallery.json")
    gallery_config = spg_common.read_gallery_config(gallery_config_path)
    if not gallery_config:
        spg_common.log(f"Cannot load the gallery.json file ({gallery_config_path})!")
        sys.exit(1)

    # Get the location from the command line or from the gallery.json
    location = args.location
    if not location:
        if "remote_location" in gallery_config:
            location = gallery_config["remote_location"]

    # Check if the uploader location is valid
    if not uploader.check_location(location):
        spg_common.log(f"The specified location if not valid for this hosting type.")
        sys.exit(1)

    # Check if the gallery is built
    if not os.path.exists(
        os.path.join(gallery_root, gallery_config["public_path"], "index.html")
    ):
        spg_common.log(
            f"Cannot find index.html. Please build the gallery first with gallery_build.!"
        )
        sys.exit(1)

    # Upload the gallery
    try:
        uploader.upload_gallery(
            location, os.path.join(gallery_root, gallery_config["public_path"])
        )
    except spg_common.SPGException as exception:
        spg_common.log(exception.message)
        sys.exit(1)
    except Exception as exception:
        spg_common.log(
            f"Something went wrong while uploading the gallery: {str(exception)}"
        )
        sys.exit(1)
예제 #6
0
 def setUp(self) -> None:
     self.uploader = get_uploader('netlify')
 def test_no_location(self):
     uploader = get_uploader('aws')
     self.assertFalse(uploader.check_location(''))