|
| 1 | +import pytest |
| 2 | +from indico.client import IndicoClient |
| 3 | +from indico.queries.gallery import ListGallery, GetGalleryTags |
| 4 | +from indico.types.component_blueprint import BlueprintPage, BlueprintTags |
| 5 | + |
| 6 | + |
| 7 | +def test_list_gallery(indico): |
| 8 | + """Test listing all blueprints from the gallery.""" |
| 9 | + client = IndicoClient() |
| 10 | + |
| 11 | + bppage = client.call(ListGallery()) |
| 12 | + assert isinstance(bppage, BlueprintPage) |
| 13 | + assert hasattr(bppage, "blueprints") |
| 14 | + |
| 15 | + if bppage.blueprints: |
| 16 | + blueprint = bppage.blueprints[0] |
| 17 | + assert hasattr(blueprint, "id") |
| 18 | + assert hasattr(blueprint, "name") |
| 19 | + assert hasattr(blueprint, "component_type") |
| 20 | + assert hasattr(blueprint, "icon") |
| 21 | + assert hasattr(blueprint, "description") |
| 22 | + assert hasattr(blueprint, "enabled") |
| 23 | + assert hasattr(blueprint, "footer") |
| 24 | + assert hasattr(blueprint, "tags") |
| 25 | + assert hasattr(blueprint, "model_options") |
| 26 | + |
| 27 | + |
| 28 | +def test_list_gallery_with_args(indico): |
| 29 | + """Test listing gallery blueprints with variables.""" |
| 30 | + client = IndicoClient() |
| 31 | + |
| 32 | + limit_bppage = client.call(ListGallery(limit=5)) |
| 33 | + assert isinstance(limit_bppage, BlueprintPage) |
| 34 | + assert len(limit_bppage.blueprints) <= 5 |
| 35 | + |
| 36 | + desc_bppage = client.call(ListGallery(order_by="name", desc=True)) |
| 37 | + assert isinstance(desc_bppage, BlueprintPage) |
| 38 | + |
| 39 | + filters = { |
| 40 | + "op": "and", |
| 41 | + "filters": [ |
| 42 | + { |
| 43 | + "op": "eq", |
| 44 | + "field": "component_type", |
| 45 | + "value": "model_group", |
| 46 | + } |
| 47 | + ], |
| 48 | + } |
| 49 | + filtered_bppage = client.call(ListGallery(filters=filters)) |
| 50 | + assert isinstance(filtered_bppage, BlueprintPage) |
| 51 | + filtered_component_bps = filtered_bppage.blueprints |
| 52 | + assert filtered_component_bps[0].component_type == "MODEL_GROUP" |
| 53 | + assert filtered_component_bps[-1].component_type == "MODEL_GROUP" |
| 54 | + |
| 55 | + |
| 56 | +def test_list_gallery_pagination(indico): |
| 57 | + """Test gallery pagination functionality using the new cursor-based pagination.""" |
| 58 | + client = IndicoClient() |
| 59 | + blueprints = [] |
| 60 | + num_pages_to_check = 3 # Check 3 pages of results |
| 61 | + |
| 62 | + # Use paginate to get multiple pages |
| 63 | + for i, page in enumerate(client.paginate(ListGallery(limit=2))): |
| 64 | + assert isinstance(page, BlueprintPage) |
| 65 | + assert len(page.blueprints) <= 2 |
| 66 | + blueprints.extend(page.blueprints) |
| 67 | + |
| 68 | + if i >= num_pages_to_check - 1: |
| 69 | + break |
| 70 | + |
| 71 | + # Verify we got results |
| 72 | + assert blueprints is not None |
| 73 | + assert len(blueprints) > 0 |
| 74 | + |
| 75 | + # Verify we got different results on each page |
| 76 | + if len(blueprints) >= 2: |
| 77 | + # Check that we have unique blueprints |
| 78 | + blueprint_ids = [bp.id for bp in blueprints] |
| 79 | + assert len(blueprint_ids) == len(set(blueprint_ids)), ( |
| 80 | + "Duplicate blueprints found in pagination" |
| 81 | + ) |
| 82 | + |
| 83 | + |
| 84 | +def test_get_gallery_tags(indico): |
| 85 | + """Test retrieving gallery tags.""" |
| 86 | + client = IndicoClient() |
| 87 | + |
| 88 | + # Test getting all tags |
| 89 | + tags = client.call(GetGalleryTags()) |
| 90 | + assert isinstance(tags, BlueprintTags) |
| 91 | + assert hasattr(tags, "tags") |
| 92 | + |
| 93 | + # Verify tag structure |
| 94 | + if tags.tags: |
| 95 | + tag = tags.tags[0] |
| 96 | + assert hasattr(tag, "tag") |
| 97 | + assert hasattr(tag, "value") |
| 98 | + assert hasattr(tag, "tag_category") |
| 99 | + |
| 100 | + |
| 101 | +def test_get_gallery_tags_with_args(indico): |
| 102 | + """Test retrieving gallery tags with filters.""" |
| 103 | + client = IndicoClient() |
| 104 | + |
| 105 | + # Test with component family filter |
| 106 | + tags = client.call(GetGalleryTags(component_family="MODEL")) |
| 107 | + assert isinstance(tags, BlueprintTags) |
| 108 | + |
| 109 | + # Test with tag categories filter |
| 110 | + tags = client.call(GetGalleryTags(tag_categories=["PROVIDER"])) |
| 111 | + assert isinstance(tags, BlueprintTags) |
| 112 | + |
| 113 | + # Test with both filters |
| 114 | + tags = client.call( |
| 115 | + GetGalleryTags(component_family="MODEL", tag_categories=["PROVIDER"]) |
| 116 | + ) |
| 117 | + assert isinstance(tags, BlueprintTags) |
0 commit comments