|
2 | 2 | from datetime import datetime, timedelta, timezone
|
3 | 3 |
|
4 | 4 | import pytest
|
| 5 | +from labelbox.schema.media_type import MediaType |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def simple_ontology():
|
@@ -38,11 +39,69 @@ def test_project_editor_setup(client, project, rand_gen):
|
38 | 39 | ] == [ontology_name]
|
39 | 40 |
|
40 | 41 |
|
41 |
| -def test_project_connect_ontology_cant_call_multiple_times( |
42 |
| - client, project, rand_gen |
43 |
| -): |
44 |
| - ontology_name = f"test_project_editor_setup_ontology_name-{rand_gen(str)}" |
45 |
| - ontology = client.create_ontology(ontology_name, simple_ontology()) |
46 |
| - project.connect_ontology(ontology) |
47 |
| - with pytest.raises(ValueError): |
48 |
| - project.connect_ontology(ontology) |
| 42 | +def test_project_connect_ontology_multiple_times(client, project, rand_gen): |
| 43 | + """Test that we can connect multiple ontologies in sequence.""" |
| 44 | + # Connect first ontology |
| 45 | + ontology_name_1 = ( |
| 46 | + f"test_project_connect_ontology_multiple_times_1-{rand_gen(str)}" |
| 47 | + ) |
| 48 | + ontology_1 = client.create_ontology(ontology_name_1, simple_ontology()) |
| 49 | + project.connect_ontology(ontology_1) |
| 50 | + assert project.ontology().name == ontology_name_1 |
| 51 | + |
| 52 | + # Connect second ontology |
| 53 | + ontology_name_2 = ( |
| 54 | + f"test_project_connect_ontology_multiple_times_2-{rand_gen(str)}" |
| 55 | + ) |
| 56 | + ontology_2 = client.create_ontology(ontology_name_2, simple_ontology()) |
| 57 | + project.connect_ontology(ontology_2) |
| 58 | + assert project.ontology().name == ontology_name_2 |
| 59 | + |
| 60 | + |
| 61 | +def test_project_connect_ontology_with_different_media_types(client, rand_gen): |
| 62 | + """Test connecting ontologies with different media types to a project""" |
| 63 | + # Create a new project with Image media type |
| 64 | + project_name = f"test_project_media_type_{rand_gen(str)}" |
| 65 | + project = client.create_project( |
| 66 | + name=project_name, media_type=MediaType.Image |
| 67 | + ) |
| 68 | + |
| 69 | + try: |
| 70 | + # Create ontologies with different media types |
| 71 | + ontology_1 = client.create_ontology( |
| 72 | + f"test_ontology_1_{rand_gen(str)}", |
| 73 | + simple_ontology(), |
| 74 | + media_type=MediaType.Image, # Same media type as project |
| 75 | + ) |
| 76 | + |
| 77 | + ontology_2 = client.create_ontology( |
| 78 | + f"test_ontology_2_{rand_gen(str)}", |
| 79 | + simple_ontology(), |
| 80 | + media_type=MediaType.Video, # Different media type |
| 81 | + ) |
| 82 | + |
| 83 | + # Test connecting ontology with same media type |
| 84 | + project.connect_ontology(ontology_1) |
| 85 | + assert project.ontology().uid == ontology_1.uid |
| 86 | + |
| 87 | + # Test connecting ontology with different media type |
| 88 | + with pytest.raises(ValueError) as exc_info: |
| 89 | + project.connect_ontology(ontology_2) |
| 90 | + assert "Ontology and project must share the same type" in str( |
| 91 | + exc_info.value |
| 92 | + ) |
| 93 | + finally: |
| 94 | + # Clean up |
| 95 | + project.delete() |
| 96 | + |
| 97 | + |
| 98 | +def test_project_connect_ontology_with_unknown_type(client, project, rand_gen): |
| 99 | + """Test connecting ontology with unknown media type to a project""" |
| 100 | + # Create ontology with unknown media type |
| 101 | + unknown_type_ontology = client.create_ontology( |
| 102 | + f"test_unknown_type_{rand_gen(str)}", simple_ontology() |
| 103 | + ) |
| 104 | + |
| 105 | + # Test connecting ontology with unknown type |
| 106 | + project.connect_ontology(unknown_type_ontology) |
| 107 | + assert project.ontology().uid == unknown_type_ontology.uid |
0 commit comments