Skip to content

Commit 657dff4

Browse files
author
matmoncon
committed
test: update tests to new method params and rename exception
1 parent 326f4cd commit 657dff4

20 files changed

+75
-33
lines changed

tests/integration/test_node_model_count.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
from pyneo4j_ogm.core.client import Pyneo4jClient
8-
from pyneo4j_ogm.exceptions import NoResultsFound
8+
from pyneo4j_ogm.exceptions import UnexpectedEmptyResult
99
from tests.fixtures.db_setup import Coffee, client, session, setup_test_data
1010

1111
pytest_plugins = ("pytest_asyncio",)
@@ -26,5 +26,5 @@ async def test_count_no_query_result(client: Pyneo4jClient):
2626

2727
with patch.object(client, "cypher") as mock_cypher:
2828
mock_cypher.return_value = [[], []]
29-
with pytest.raises(NoResultsFound):
29+
with pytest.raises(UnexpectedEmptyResult):
3030
await Coffee.count({"milk": True})

tests/integration/test_node_model_create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing_extensions import LiteralString
1010

1111
from pyneo4j_ogm.core.client import Pyneo4jClient
12-
from pyneo4j_ogm.exceptions import NoResultsFound
12+
from pyneo4j_ogm.exceptions import UnexpectedEmptyResult
1313
from tests.fixtures.db_setup import Coffee, client, session
1414

1515
pytest_plugins = ("pytest_asyncio",)
@@ -66,5 +66,5 @@ async def test_create_no_result(client: Pyneo4jClient):
6666

6767
node = Coffee(flavor="Mocha", sugar=True, milk=True, note={"roast": "dark"})
6868

69-
with pytest.raises(NoResultsFound):
69+
with pytest.raises(UnexpectedEmptyResult):
7070
await node.create()

tests/integration/test_node_model_delete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing_extensions import LiteralString
1010

1111
from pyneo4j_ogm.core.client import Pyneo4jClient
12-
from pyneo4j_ogm.exceptions import NoResultsFound
12+
from pyneo4j_ogm.exceptions import UnexpectedEmptyResult
1313
from tests.fixtures.db_setup import CoffeeShop, client, session
1414

1515
pytest_plugins = ("pytest_asyncio",)
@@ -51,5 +51,5 @@ async def test_delete_no_result(client: Pyneo4jClient):
5151
with patch.object(client, "cypher") as mock_cypher:
5252
mock_cypher.return_value = ([], [])
5353

54-
with pytest.raises(NoResultsFound):
54+
with pytest.raises(UnexpectedEmptyResult):
5555
await node.delete()

tests/integration/test_node_model_delete_many.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing_extensions import LiteralString
1010

1111
from pyneo4j_ogm.core.client import Pyneo4jClient
12-
from pyneo4j_ogm.exceptions import NoResultsFound
12+
from pyneo4j_ogm.exceptions import UnexpectedEmptyResult
1313
from tests.fixtures.db_setup import CoffeeShop, client, session, setup_test_data
1414

1515
pytest_plugins = ("pytest_asyncio",)
@@ -61,5 +61,5 @@ async def test_delete_many_no_results(client: Pyneo4jClient, session: AsyncSessi
6161
with patch.object(client, "cypher") as mock_cypher:
6262
mock_cypher.return_value = [[], []]
6363

64-
with pytest.raises(NoResultsFound):
64+
with pytest.raises(UnexpectedEmptyResult):
6565
await CoffeeShop.delete_many({"tags": {"$in": ["oh-no"]}})

tests/integration/test_node_model_delete_one.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from neo4j.graph import Node
88
from typing_extensions import LiteralString
99

10-
from pyneo4j_ogm.exceptions import InvalidFilters, NoResultsFound
10+
from pyneo4j_ogm.exceptions import InvalidFilters, NoResultFound, UnexpectedEmptyResult
1111
from tests.fixtures.db_setup import CoffeeShop, client, session, setup_test_data
1212

1313
pytest_plugins = ("pytest_asyncio",)
@@ -36,6 +36,9 @@ async def test_delete_one_no_match(session: AsyncSession, setup_test_data):
3636
results = await CoffeeShop.delete_one({"tags": {"$in": ["oh-no"]}})
3737
assert results == 0
3838

39+
with pytest.raises(NoResultFound):
40+
await CoffeeShop.delete_one({"tags": {"$in": ["oh-no"]}}, raise_on_empty=True)
41+
3942
results = await session.run(
4043
cast(
4144
LiteralString,

tests/integration/test_node_model_find_one.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from neo4j.graph import Graph, Node
88

99
from pyneo4j_ogm.core.client import Pyneo4jClient
10-
from pyneo4j_ogm.exceptions import InvalidFilters, UnregisteredModel
10+
from pyneo4j_ogm.exceptions import InvalidFilters, NoResultFound, UnregisteredModel
1111
from tests.fixtures.db_setup import (
1212
Coffee,
1313
Consumed,
@@ -38,6 +38,9 @@ async def test_find_one_no_match(setup_test_data):
3838

3939
assert found_node is None
4040

41+
with pytest.raises(NoResultFound):
42+
await Developer.find_one({"my_prop": "non-existent"}, raise_on_empty=True)
43+
4144

4245
async def test_find_one_raw_result(client: Pyneo4jClient):
4346
await client.register_models([Developer])

tests/integration/test_node_model_refresh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing_extensions import LiteralString
1010

1111
from pyneo4j_ogm.core.client import Pyneo4jClient
12-
from pyneo4j_ogm.exceptions import NoResultsFound
12+
from pyneo4j_ogm.exceptions import UnexpectedEmptyResult
1313
from tests.fixtures.db_setup import CoffeeShop, client, session
1414

1515
pytest_plugins = ("pytest_asyncio",)
@@ -56,5 +56,5 @@ async def test_refresh_no_result(client: Pyneo4jClient):
5656
with patch.object(client, "cypher") as mock_cypher:
5757
mock_cypher.return_value = ([], [])
5858

59-
with pytest.raises(NoResultsFound):
59+
with pytest.raises(UnexpectedEmptyResult):
6060
await node.refresh()

tests/integration/test_node_model_update.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing_extensions import LiteralString
1010

1111
from pyneo4j_ogm.core.client import Pyneo4jClient
12-
from pyneo4j_ogm.exceptions import NoResultsFound
12+
from pyneo4j_ogm.exceptions import UnexpectedEmptyResult
1313
from tests.fixtures.db_setup import CoffeeShop, client, session
1414

1515
pytest_plugins = ("pytest_asyncio",)
@@ -56,6 +56,6 @@ async def test_update_no_result(client: Pyneo4jClient):
5656
with patch.object(client, "cypher") as mock_cypher:
5757
mock_cypher.return_value = ([], [])
5858

59-
with pytest.raises(NoResultsFound):
59+
with pytest.raises(UnexpectedEmptyResult):
6060
node.rating = 2
6161
await node.update()

tests/integration/test_node_model_update_one.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing_extensions import LiteralString
1010

1111
from pyneo4j_ogm.core.client import Pyneo4jClient
12-
from pyneo4j_ogm.exceptions import InvalidFilters
12+
from pyneo4j_ogm.exceptions import InvalidFilters, NoResultFound
1313
from tests.fixtures.db_setup import Developer, client, session, setup_test_data
1414

1515
pytest_plugins = ("pytest_asyncio",)
@@ -79,6 +79,9 @@ async def test_update_one_no_match(setup_test_data):
7979

8080
assert updated_node is None
8181

82+
with pytest.raises(NoResultFound):
83+
await Developer.update_one({"age": 50}, {"uid": 99999}, raise_on_empty=True)
84+
8285

8386
async def test_update_one_missing_filters(client: Pyneo4jClient):
8487
await client.register_models([Developer])

tests/integration/test_relationship_model_count.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
from pyneo4j_ogm.core.client import Pyneo4jClient
8-
from pyneo4j_ogm.exceptions import NoResultsFound
8+
from pyneo4j_ogm.exceptions import UnexpectedEmptyResult
99
from tests.fixtures.db_setup import WorkedWith, client, session, setup_test_data
1010

1111
pytest_plugins = ("pytest_asyncio",)
@@ -30,5 +30,5 @@ async def test_count_no_query_result(client: Pyneo4jClient, setup_test_data):
3030

3131
with patch.object(client, "cypher") as mock_cypher:
3232
mock_cypher.return_value = [[], []]
33-
with pytest.raises(NoResultsFound):
33+
with pytest.raises(UnexpectedEmptyResult):
3434
await WorkedWith.count({})

0 commit comments

Comments
 (0)