|
18 | 18 | import mock # python < 3.3
|
19 | 19 |
|
20 | 20 |
|
21 |
| -def requires_python_version(major, minor, reason=None): |
| 21 | +def min_python_version(major, minor, reason=None): |
22 | 22 | if reason is None:
|
23 |
| - reason = "Requires Python {}.{}".format(major, minor) |
| 23 | + reason = "Requires Python {}.{} or higher".format(major, minor) |
24 | 24 | return pytest.mark.skipif(sys.version_info < (major, minor), reason=reason)
|
25 | 25 |
|
26 | 26 |
|
| 27 | +def max_python_version(major, minor, reason=None): |
| 28 | + if reason is None: |
| 29 | + reason = "Requires Python {}.{} or lower".format(major, minor) |
| 30 | + return pytest.mark.skipif(sys.version_info > (major, minor), reason=reason) |
| 31 | + |
| 32 | + |
27 | 33 | @pytest.mark.asyncio
|
28 | 34 | async def test_basic(sentry_init, aiohttp_client, capture_events):
|
29 | 35 | sentry_init(integrations=[AioHttpIntegration()])
|
@@ -544,7 +550,7 @@ async def handler(request):
|
544 | 550 | )
|
545 | 551 |
|
546 | 552 |
|
547 |
| -@requires_python_version(3, 8, "GraphQL aiohttp integration requires py>=3.8") |
| 553 | +@min_python_version(3, 8, "GraphQL aiohttp integration requires py>=3.8") |
548 | 554 | @pytest.mark.asyncio
|
549 | 555 | async def test_graphql_get_client_error_captured(
|
550 | 556 | sentry_init, capture_events, aiohttp_raw_server, aiohttp_client
|
@@ -594,7 +600,7 @@ async def handler(request):
|
594 | 600 | )
|
595 | 601 |
|
596 | 602 |
|
597 |
| -@requires_python_version(3, 8, "GraphQL aiohttp integration requires py>=3.8") |
| 603 | +@min_python_version(3, 8, "GraphQL aiohttp integration requires py>=3.8") |
598 | 604 | @pytest.mark.asyncio
|
599 | 605 | async def test_graphql_post_client_error_captured(
|
600 | 606 | sentry_init, capture_events, aiohttp_client, aiohttp_raw_server
|
@@ -654,3 +660,85 @@ async def handler(request):
|
654 | 660 | event["exception"]["values"][0]["value"]
|
655 | 661 | == "GraphQL request failed, name: AddPet, type: mutation"
|
656 | 662 | )
|
| 663 | + |
| 664 | + |
| 665 | +@max_python_version(3, 7, "No GraphQL aiohttp integration for py<=3.7") |
| 666 | +@pytest.mark.asyncio |
| 667 | +async def test_graphql_get_client_error_not_captured( |
| 668 | + sentry_init, capture_events, aiohttp_raw_server, aiohttp_client |
| 669 | +): |
| 670 | + """Test that firing GraphQL requests works, there will just be no event.""" |
| 671 | + sentry_init(integrations=[AioHttpIntegration()]) |
| 672 | + |
| 673 | + graphql_response = { |
| 674 | + "data": None, |
| 675 | + "errors": [ |
| 676 | + { |
| 677 | + "message": "some error", |
| 678 | + "locations": [{"line": 2, "column": 3}], |
| 679 | + "path": ["pet"], |
| 680 | + } |
| 681 | + ], |
| 682 | + } |
| 683 | + |
| 684 | + async def handler(request): |
| 685 | + return json_response(graphql_response) |
| 686 | + |
| 687 | + raw_server = await aiohttp_raw_server(handler) |
| 688 | + events = capture_events() |
| 689 | + |
| 690 | + client = await aiohttp_client(raw_server) |
| 691 | + response = await client.get( |
| 692 | + "/graphql", params={"query": "query GetPet {pet{name}}"} |
| 693 | + ) |
| 694 | + |
| 695 | + assert response.status == 200 |
| 696 | + assert await response.json() == graphql_response |
| 697 | + assert not events |
| 698 | + |
| 699 | + |
| 700 | +@max_python_version(3, 7, "No GraphQL aiohttp integration for py<=3.7") |
| 701 | +@pytest.mark.asyncio |
| 702 | +async def test_graphql_post_client_error_not_captured( |
| 703 | + sentry_init, capture_events, aiohttp_client, aiohttp_raw_server |
| 704 | +): |
| 705 | + """Test that firing GraphQL requests works, there will just be no event.""" |
| 706 | + sentry_init(integrations=[AioHttpIntegration()]) |
| 707 | + |
| 708 | + graphql_request = { |
| 709 | + "query": dedent( |
| 710 | + """ |
| 711 | + mutation AddPet ($name: String!) { |
| 712 | + addPet(name: $name) { |
| 713 | + id |
| 714 | + name |
| 715 | + } |
| 716 | + } |
| 717 | + """ |
| 718 | + ), |
| 719 | + "variables": { |
| 720 | + "name": "Lucy", |
| 721 | + }, |
| 722 | + } |
| 723 | + graphql_response = { |
| 724 | + "data": None, |
| 725 | + "errors": [ |
| 726 | + { |
| 727 | + "message": "already have too many pets", |
| 728 | + "locations": [{"line": 1, "column": 1}], |
| 729 | + } |
| 730 | + ], |
| 731 | + } |
| 732 | + |
| 733 | + async def handler(request): |
| 734 | + return json_response(graphql_response) |
| 735 | + |
| 736 | + raw_server = await aiohttp_raw_server(handler) |
| 737 | + events = capture_events() |
| 738 | + |
| 739 | + client = await aiohttp_client(raw_server) |
| 740 | + response = await client.post("/graphql", json=graphql_request) |
| 741 | + |
| 742 | + assert response.status == 200 |
| 743 | + assert await response.json() == graphql_response |
| 744 | + assert not events |
0 commit comments