|
| 1 | +"""Tests for entity query functionality.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from arkiv import Arkiv |
| 6 | +from arkiv.types import Cursor |
| 7 | + |
| 8 | + |
| 9 | +class TestQueryEntitiesParameterValidation: |
| 10 | + """Test parameter validation for query_entities method.""" |
| 11 | + |
| 12 | + def test_query_entities_requires_query_or_cursor( |
| 13 | + self, arkiv_client_http: Arkiv |
| 14 | + ) -> None: |
| 15 | + """Test that query_entities raises ValueError when neither query nor cursor is provided.""" |
| 16 | + with pytest.raises(ValueError, match="Must provide either query or cursor"): |
| 17 | + arkiv_client_http.arkiv.query_entities() |
| 18 | + |
| 19 | + def test_query_entities_validates_none_for_both( |
| 20 | + self, arkiv_client_http: Arkiv |
| 21 | + ) -> None: |
| 22 | + """Test that explicitly passing None for both query and cursor raises ValueError.""" |
| 23 | + with pytest.raises(ValueError, match="Must provide either query or cursor"): |
| 24 | + arkiv_client_http.arkiv.query_entities(query=None, cursor=None) |
| 25 | + |
| 26 | + def test_query_entities_accepts_query_only(self, arkiv_client_http: Arkiv) -> None: |
| 27 | + """Test that query_entities accepts query without cursor.""" |
| 28 | + # Should not raise ValueError for missing cursor |
| 29 | + # Will raise NotImplementedError since method is not implemented yet |
| 30 | + with pytest.raises(NotImplementedError, match="not implemented yet"): |
| 31 | + arkiv_client_http.arkiv.query_entities(query="SELECT *") |
| 32 | + |
| 33 | + def test_query_entities_accepts_cursor_only(self, arkiv_client_http: Arkiv) -> None: |
| 34 | + """Test that query_entities accepts cursor without query.""" |
| 35 | + # Create a dummy cursor (opaque string) |
| 36 | + cursor = Cursor("dummy_cursor_value") |
| 37 | + |
| 38 | + # Should not raise ValueError for missing query |
| 39 | + # Will raise NotImplementedError since method is not implemented yet |
| 40 | + with pytest.raises(NotImplementedError, match="not implemented yet"): |
| 41 | + arkiv_client_http.arkiv.query_entities(cursor=cursor) |
| 42 | + |
| 43 | + def test_query_entities_both_query_and_cursor_not_allowed( |
| 44 | + self, arkiv_client_http: Arkiv |
| 45 | + ) -> None: |
| 46 | + """Test that query_entities rejects both query and cursor (mutually exclusive).""" |
| 47 | + cursor = Cursor("dummy_cursor_value") |
| 48 | + |
| 49 | + # Should raise ValueError when both are provided |
| 50 | + with pytest.raises(ValueError, match="Cannot provide both query and cursor"): |
| 51 | + arkiv_client_http.arkiv.query_entities(query="SELECT *", cursor=cursor) |
| 52 | + |
| 53 | + def test_query_entities_with_all_parameters( |
| 54 | + self, arkiv_client_http: Arkiv |
| 55 | + ) -> None: |
| 56 | + """Test that query_entities accepts all parameters.""" |
| 57 | + # Should not raise ValueError |
| 58 | + # Will raise NotImplementedError since method is not implemented yet |
| 59 | + with pytest.raises(NotImplementedError, match="not implemented yet"): |
| 60 | + arkiv_client_http.arkiv.query_entities( |
| 61 | + query="SELECT * WHERE owner = '0x1234'", |
| 62 | + limit=50, |
| 63 | + at_block=1000, |
| 64 | + ) |
| 65 | + |
| 66 | + def test_query_entities_with_cursor_and_parameters( |
| 67 | + self, arkiv_client_http: Arkiv |
| 68 | + ) -> None: |
| 69 | + """Test that query_entities accepts cursor with other parameters (which are ignored).""" |
| 70 | + cursor = Cursor("dummy_cursor_value") |
| 71 | + |
| 72 | + # Should not raise ValueError |
| 73 | + # Will raise NotImplementedError since method is not implemented yet |
| 74 | + with pytest.raises(NotImplementedError, match="not implemented yet"): |
| 75 | + arkiv_client_http.arkiv.query_entities( |
| 76 | + cursor=cursor, |
| 77 | + limit=100, # Ignored when cursor is provided |
| 78 | + at_block=1000, # Ignored when cursor is provided |
| 79 | + ) |
0 commit comments