github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/python-wrapper/tests/integration/test_repository.py (about)

     1  import uuid
     2  import pytest
     3  
     4  import lakefs
     5  
     6  from tests.integration.conftest import _setup_repo, get_storage_namespace
     7  
     8  _NUM_PREFIXES = 10
     9  _NUM_ELEM_PER_PREFIX = 20
    10  
    11  
    12  @pytest.fixture(name="setup_repo_with_branches_and_tags", scope="session")
    13  def fixture_setup_repo_with_branches_and_tags():
    14      clt, repo = _setup_repo(get_storage_namespace("branches-and-tags"),
    15                              "branches-and-tags",
    16                              "main")
    17      for i in range(_NUM_PREFIXES):
    18          for j in range(_NUM_ELEM_PER_PREFIX):
    19              b = repo.branch(f"branches{i:02d}-{j:02d}").create("main")
    20              repo.tag(tag_id=f"tags{i:02d}-{j:02d}").create(b)
    21  
    22      return clt, repo
    23  
    24  
    25  @pytest.mark.parametrize("attr", ("branches", "tags"))
    26  def test_repository_listings(setup_repo_with_branches_and_tags, attr):
    27      _, repo = setup_repo_with_branches_and_tags
    28  
    29      generator = getattr(repo, attr)
    30  
    31      total = _NUM_PREFIXES * _NUM_ELEM_PER_PREFIX
    32      if attr == "branches":
    33          total += 1  # Including main
    34      assert len(list(generator())) == total
    35  
    36      after = 9
    37      res = list(generator(max_amount=100, prefix=f"{attr}01", after=f"{attr}01-{after:02d}"))
    38      assert len(res) == 10
    39      for i, b in enumerate(res):
    40          assert b.id == f"{attr}01-{i + after + 1:02d}"
    41  
    42  
    43  def test_repositories(storage_namespace):
    44      repo_base_name = f"test-repo{uuid.uuid4()}-"
    45      for i in range(10):
    46          lakefs.repository(f"{repo_base_name}{i}").create(storage_namespace=f"{storage_namespace}-{i}")
    47  
    48      repos = list(lakefs.repositories(prefix=repo_base_name))
    49      assert len(repos) == 10
    50      for i, repo in enumerate(repos):
    51          assert repo.properties.id == f"{repo_base_name}{i}"