Ejemplo n.º 1
0
    def test_diff_different_indices(self):
        # given
        BASE_URL = "https://packages.enthought.com"
        ORG = "enthought"
        REPO_GPL = "gpl"
        REPO_FREE = "free"
        PLAT = "rh6-x86_64"
        VER27 = "cp27"

        # when
        idx_gpl = get_index(url=BASE_URL,
                            org=ORG,
                            repo=REPO_GPL,
                            plat=PLAT,
                            pyver=VER27)

        idx_free = get_index(url=BASE_URL,
                             org=ORG,
                             repo=REPO_FREE,
                             plat=PLAT,
                             pyver=VER27)

        diff = index_diff(idx_gpl, idx_free)

        # then
        assert isinstance(diff, dict)
        assert diff['missing']
Ejemplo n.º 2
0
    def test_get_index_bad_org_repo(self):
        # given
        BASE_URL = "https://packages.enthought.com"
        REPO = "gpl"
        ORG = "entought"  # intentional typo
        PLAT = "rh6-x86_64"
        VER = "cp27"

        # when
        with pytest.raises(requests.HTTPError) as execinfo:
            get_index(url=BASE_URL, org=ORG, repo=REPO, plat=PLAT, pyver=VER)
        # then
        assert "Client Error" in str(execinfo.value)  # should be 404
Ejemplo n.º 3
0
    def test_get_index_bad_url(self):
        # given
        BASE_URL = "https://packages.entought.com"  # intentional typo
        REPO = "gpl"
        ORG = "enthought"
        PLAT = "rh6-x86_64"
        VER = "cp27"

        # when
        with pytest.raises(requests.exceptions.ConnectionError) as execinfo:
            get_index(url=BASE_URL, org=ORG, repo=REPO, plat=PLAT, pyver=VER)
        # then
        assert "Failed to establish a new connection" in str(execinfo.value)
Ejemplo n.º 4
0
    def test_get_index_bad_ver(self):
        """ Note: CLI validates plat + ver so this shouldn't happen when
        using the CLI but could happen if calling get_index directly.
        """
        # given
        BASE_URL = "https://packages.enthought.com"
        REPO = "gpl"
        ORG = "enthought"
        PLAT = "rh6-x86_64"
        VER = "cp17"  # intentional typo

        # when
        with pytest.raises(requests.HTTPError) as execinfo:
            get_index(url=BASE_URL, org=ORG, repo=REPO, plat=PLAT, pyver=VER)
        # then
        assert "Client Error" in str(execinfo.value)  # should be 400
Ejemplo n.º 5
0
def get_repo_size_by_platform(repos: Tuple[str], plats: Tuple[str],
                              vers: Tuple[str]) -> dict:
    """ Sum the size egg metadata for a given repo by platform.

    INPUTS:
    repos: tuple of strings in Hatcher/Brood org/repo format
    plats: tuple of platform strings
    vers: tuple of python version strings

    RETURNS:
    dict containing repo sizes in Gb by platform
    """

    sizes = defaultdict(int)
    for repo, plat, ver in product(repos, plats, vers):
        org, repo = repo.split("/")
        idx = get_index(url="https://packages.enthought.com",
                        org=org,
                        repo=repo,
                        plat=plat,
                        pyver=ver)
        for key in idx.keys():
            sizes[plat] += idx[key]['size']

    for key in sizes.keys():
        sizes[key] /= 1_000_000_000
    return sizes
Ejemplo n.º 6
0
    def test_get_index(self):
        # given
        BASE_URL = "https://packages.enthought.com"
        REPO = "gpl"
        ORG = "enthought"
        PLAT = "rh6-x86_64"
        VER = "cp27"

        # when
        idx = get_index(url=BASE_URL, org=ORG, repo=REPO, plat=PLAT, pyver=VER)
        # then
        assert isinstance(idx, dict)
        assert idx
Ejemplo n.º 7
0
    def test_to_json_file_sorted(self):
        # given
        BASE_URL = "https://packages.enthought.com"
        REPO = "gpl"
        ORG = "enthought"
        PLAT = "rh6-x86_64"
        VER = "cp27"

        # when
        idx = get_index(url=BASE_URL, org=ORG, repo=REPO, plat=PLAT, pyver=VER)
        _, path = tempfile.mkstemp(suffix=".json")
        to_json_file(idx, path, sort=True)

        # then
        assert os.path.exists(path)
        assert os.path.getsize(path) > 0
Ejemplo n.º 8
0
    def test_diff_same_index(self):
        # given
        BASE_URL = "https://packages.enthought.com"
        REPO = "gpl"
        ORG = "enthought"
        PLAT = "rh6-x86_64"
        VER = "cp27"

        # when
        idx = get_index(url=BASE_URL,
                        org=ORG,
                        repo=REPO,
                        plat=PLAT,
                        pyver=VER)

        diff = index_diff(idx, idx)

        # then
        assert isinstance(diff, dict)
        assert not diff['missing']
Ejemplo n.º 9
0
    def test_to_from_json_round_trip(self):
        # given
        BASE_URL = "https://packages.enthought.com"
        REPO = "gpl"
        ORG = "enthought"
        PLAT = "rh6-x86_64"
        VER = "cp27"

        # when
        idx_from_brood = get_index(url=BASE_URL,
                                   org=ORG,
                                   repo=REPO,
                                   plat=PLAT,
                                   pyver=VER)

        _, path = tempfile.mkstemp(suffix=".json")
        to_json_file(idx_from_brood, path)

        idx_from_file = from_json_file(path)

        # then
        assert idx_from_brood == idx_from_file