def get_bower_package(self, url, dest=None, version=None,
                          process_deps=True):
        dest = dest or Path(".") / "assets"
        parsed_url = urlparse(url)
        if parsed_url.scheme == "git" or parsed_url.path.endswith(".git"):
            if parsed_url.netloc == "github.com":
                user, repo = parsed_url.path[1:-4].split("/")
                response = get(github_api_uri +
                               "/repos/{}/{}/tags".format(user, repo))
                tags = response.json()
                target = None
                if not len(tags):
                    click.secho("fatal: no tags exist for {}/{}".format(
                        user, repo), fg="red")
                    raise InvalidPackageError
                if version is None:
                    target = tags[0]
                else:
                    for tag in tags:
                        if semver.match(tag["name"],
                                        Bower.clean_semver(version)):
                            target = tag
                            break
                if not target:
                    click.secho(
                        "fatal: failed to find matching tag for "
                        "{user}/{repo} {version}".format(user, repo, version),
                        fg="red")
                    raise VersionNotFoundError
                click.secho("installing {}/{}#{}".format(
                    user, repo, tags[0]["name"]), fg="green")
                return self.get_bower_package(
                    url=target["zipball_url"],
                    dest=dest,
                    version=version)
            raise NotImplementedError
            click.echo("git clone {url}".format(url=url))
            cmd = envoy.run('git clone {url} "{dest}"'.format(
                url=url, dest=dest))
        elif parsed_url.scheme in ("http", "https"):
            zip_dest = download_file(url, dest=self.temp_dir,
                                     label="{dest_basename}",
                                     expected_extension="zip")
            with zipfile.ZipFile(zip_dest, "r") as pkg:
                return self.extract_bower_zipfile(pkg, dest,
                                                  expected_version=version)
                # pkg.extractall(str(dest))
        else:
            click.secho("protocol currently unsupported :(")
            sys.exit(1)
def testProvenanceItemMetadata(self):
        """
        Test item provenance endpoint with metadata and basic changes
        """
        item = self.item1
        user = self.user
        admin = self.admin

        # check that the first version of the item exists
        # ensure version 1, created by admin user, with creation event
        self._checkProvenance(None, item, 1, admin, 'creation')

        # update meta to {x:y}
        metadata1 = {'x': 'y'}
        resp = self._getProvenanceAfterMetadata(item, metadata1, admin)
        # ensure version 2, updated by admin user, with update event, and meta
        # in provenance matches
        self._checkProvenance(resp, item, 2, admin, 'update',
                              {'new': {'meta': metadata1}})

        # update meta to {} by regular user, we have to send in the key to
        # remove it but check the saved metadata against {}
        metadata2 = {'x': None}
        resp = self._getProvenanceAfterMetadata(item, metadata2, user)
        # ensure version 3, updated by regular user, with update event, and
        # meta in provenance matches
        self._checkProvenance(resp, item, 3, user, 'update',
                              {'old': {'meta': metadata1},
                               'new': {'meta': {}}})

        # update meta to {x:y} by regular user
        metadata3 = {'x': 'y'}
        resp = self._getProvenanceAfterMetadata(item, metadata3, user)
        # ensure version 4, updated by regular user, with update event, and
        # meta in provenance matches
        self._checkProvenance(resp, item, 4, user, 'update',
                              {'old': {'meta': {}},
                               'new': {'meta': metadata3}})

        # update meta to {x:z} by regular user
        metadata4 = {'x': 'z'}
        resp = self._getProvenanceAfterMetadata(item, metadata4, user)
        # ensure version 5, updated by regular user, with update event, and
        # meta in provenance matches
        self._checkProvenance(resp, item, 5, user, 'update',
                              {'old': {'meta': metadata3},
                               'new': {'meta': metadata4}})

        # update meta to {x:z, q:u} by regular user
        metadata5 = {'x': 'z', 'q': 'u'}
        resp = self._getProvenanceAfterMetadata(item, metadata5, user)
        # ensure version 6, updated by regular user, with update event, and
        # meta in provenance matches
        self._checkProvenance(resp, item, 6, user, 'update',
                              {'old': {'meta': metadata4},
                               'new': {'meta': metadata5}})

        # update meta to {q:a} by regular user
        metadata6 = {'x': None, 'q': 'a'}
        resp = self._getProvenanceAfterMetadata(item, metadata6, user)
        # ensure version 7, updated by regular user, with update event, and
        # meta in provenance matches
        self._checkProvenance(resp, item, 7, user, 'update',
                              {'old': {'meta': metadata5},
                               'new': {'meta': {'q': 'a'}}})

        # Change the item name and description
        params = {'name': 'Renamed object', 'description': 'New description'}
        resp = self.request(path='/item/%s' % item['_id'], method='PUT',
                            user=admin, params=params)
        self.assertStatusOk(resp)
        params['lowerName'] = params['name'].lower()
        self._checkProvenance(None, item, 8, admin, 'update', {'new': params})

        # Copy the item and check that we marked it as copied
        params = {'name': 'Copied object'}
        resp = self.request(path='/item/%s/copy' % item['_id'],
                            method='POST', user=admin, params=params)
        self.assertStatusOk(resp)
        newItem = resp.json
        self._checkProvenance(None, newItem, 9, admin, 'copy',
                              {'originalId': str(item['_id'])})