From ca94ffd816098ba2ebdb8ae62933d13d4ece0f03 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Fri, 8 Nov 2024 12:02:22 -0500 Subject: [PATCH] Fix lints --- .../posit/connect/external/test_databricks.py | 3 +- .../posit/connect/metrics/test_shiny_usage.py | 112 ++++---- tests/posit/connect/metrics/test_usage.py | 240 +++++++++--------- tests/posit/connect/metrics/test_visits.py | 114 +++++---- .../posit/connect/oauth/test_associations.py | 4 +- .../posit/connect/oauth/test_integrations.py | 6 +- tests/posit/connect/oauth/test_oauth.py | 4 +- tests/posit/connect/test_bundles.py | 12 +- tests/posit/connect/test_client.py | 1 + tests/posit/connect/test_groups.py | 4 +- tests/posit/connect/test_permissions.py | 12 +- tests/posit/connect/test_tasks.py | 73 +++--- tests/posit/connect/test_users.py | 8 +- tests/posit/connect/test_vanities.py | 8 +- 14 files changed, 321 insertions(+), 280 deletions(-) diff --git a/tests/posit/connect/external/test_databricks.py b/tests/posit/connect/external/test_databricks.py index 777ff757..05c9c670 100644 --- a/tests/posit/connect/external/test_databricks.py +++ b/tests/posit/connect/external/test_databricks.py @@ -6,12 +6,13 @@ from posit.connect import Client from posit.connect.external.databricks import ( CredentialsProvider, + CredentialsStrategy, PositCredentialsProvider, PositCredentialsStrategy, ) -class mock_strategy: +class mock_strategy(CredentialsStrategy): def auth_type(self) -> str: return "local" diff --git a/tests/posit/connect/metrics/test_shiny_usage.py b/tests/posit/connect/metrics/test_shiny_usage.py index 549f197e..01988a21 100644 --- a/tests/posit/connect/metrics/test_shiny_usage.py +++ b/tests/posit/connect/metrics/test_shiny_usage.py @@ -6,15 +6,19 @@ from posit.connect.metrics import shiny_usage from posit.connect.resources import ResourceParameters +from posit.connect.urls import Url -from ..api import load_mock +from ..api import load_mock, load_mock_dict class TestShinyUsageEventAttributes: + @classmethod def setup_class(cls): + results = load_mock_dict("v1/instrumentation/shiny/usage?limit=500.json")["results"] + assert isinstance(results, list) cls.event = shiny_usage.ShinyUsageEvent( mock.Mock(), - **load_mock("v1/instrumentation/shiny/usage?limit=500.json")["results"][0], + **results[0], ) def test_content_guid(self): @@ -37,34 +41,34 @@ class TestShinyUsageFind: @responses.activate def test(self): # behavior - mock_get = [None] * 2 - mock_get[0] = responses.get( - "https://connect.example/__api__/v1/instrumentation/shiny/usage", - json=load_mock("v1/instrumentation/shiny/usage?limit=500.json"), - match=[ - matchers.query_param_matcher( - { - "limit": 500, - }, - ), - ], - ) - - mock_get[1] = responses.get( - "https://connect.example/__api__/v1/instrumentation/shiny/usage", - json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), - match=[ - matchers.query_param_matcher( - { - "next": "23948901087", - "limit": 500, - }, - ), - ], - ) + mock_get = [ + responses.get( + "https://connect.example/__api__/v1/instrumentation/shiny/usage", + json=load_mock("v1/instrumentation/shiny/usage?limit=500.json"), + match=[ + matchers.query_param_matcher( + { + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/shiny/usage", + json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), + match=[ + matchers.query_param_matcher( + { + "next": "23948901087", + "limit": 500, + }, + ), + ], + ), + ] # setup - params = ResourceParameters(requests.Session(), "https://connect.example/__api__") + params = ResourceParameters(requests.Session(), Url("https://connect.example/__api__")) # invoke events = shiny_usage.ShinyUsage(params).find() @@ -79,34 +83,34 @@ class TestShinyUsageFindOne: @responses.activate def test(self): # behavior - mock_get = [None] * 2 - mock_get[0] = responses.get( - "https://connect.example/__api__/v1/instrumentation/shiny/usage", - json=load_mock("v1/instrumentation/shiny/usage?limit=500.json"), - match=[ - matchers.query_param_matcher( - { - "limit": 500, - }, - ), - ], - ) - - mock_get[1] = responses.get( - "https://connect.example/__api__/v1/instrumentation/shiny/usage", - json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), - match=[ - matchers.query_param_matcher( - { - "next": "23948901087", - "limit": 500, - }, - ), - ], - ) + mock_get = [ + responses.get( + "https://connect.example/__api__/v1/instrumentation/shiny/usage", + json=load_mock("v1/instrumentation/shiny/usage?limit=500.json"), + match=[ + matchers.query_param_matcher( + { + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/shiny/usage", + json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), + match=[ + matchers.query_param_matcher( + { + "next": "23948901087", + "limit": 500, + }, + ), + ], + ), + ] # setup - params = ResourceParameters(requests.Session(), "https://connect.example/__api__") + params = ResourceParameters(requests.Session(), Url("https://connect.example/__api__")) # invoke event = shiny_usage.ShinyUsage(params).find_one() diff --git a/tests/posit/connect/metrics/test_usage.py b/tests/posit/connect/metrics/test_usage.py index fc5fe052..1a47e09b 100644 --- a/tests/posit/connect/metrics/test_usage.py +++ b/tests/posit/connect/metrics/test_usage.py @@ -7,20 +7,26 @@ from posit import connect from posit.connect.metrics import shiny_usage, usage, visits -from ..api import load_mock +from ..api import load_mock, load_mock_dict class TestUsageEventFromEvent: def test(self): with pytest.raises(TypeError): - usage.UsageEvent.from_event(None) + usage.UsageEvent.from_event( + None # pyright: ignore[reportArgumentType] + ) class TestUsageEventFromVisitEvent: + @classmethod def setup_class(cls): + results = load_mock_dict("v1/instrumentation/content/visits?limit=500.json")["results"] + assert isinstance(results, list) + visit_event = visits.VisitEvent( mock.Mock(), - **load_mock("v1/instrumentation/content/visits?limit=500.json")["results"][0], + **results[0], ) cls.view_event = usage.UsageEvent.from_visit_event(visit_event) @@ -53,10 +59,13 @@ def test_path(self): class TestUsageEventFromShinyUsageEvent: + @classmethod def setup_class(cls): + results = load_mock_dict("v1/instrumentation/shiny/usage?limit=500.json")["results"] + assert isinstance(results, list) visit_event = shiny_usage.ShinyUsageEvent( mock.Mock(), - **load_mock("v1/instrumentation/shiny/usage?limit=500.json")["results"][0], + **results[0], ) cls.view_event = usage.UsageEvent.from_shiny_usage_event(visit_event) @@ -92,57 +101,56 @@ class TestUsageFind: @responses.activate def test(self): # behavior - mock_get = [None] * 4 - - mock_get[0] = responses.get( - "https://connect.example/__api__/v1/instrumentation/content/visits", - json=load_mock("v1/instrumentation/content/visits?limit=500.json"), - match=[ - matchers.query_param_matcher( - { - "limit": 500, - }, + mock_get = [ + responses.get( + "https://connect.example/__api__/v1/instrumentation/content/visits", + json=load_mock("v1/instrumentation/content/visits?limit=500.json"), + match=[ + matchers.query_param_matcher( + { + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/content/visits", + json=load_mock( + "v1/instrumentation/content/visits?limit=500&next=23948901087.json" ), - ], - ) - - mock_get[1] = responses.get( - "https://connect.example/__api__/v1/instrumentation/content/visits", - json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"), - match=[ - matchers.query_param_matcher( - { - "next": "23948901087", - "limit": 500, - }, - ), - ], - ) - - mock_get[2] = responses.get( - "https://connect.example/__api__/v1/instrumentation/shiny/usage", - json=load_mock("v1/instrumentation/shiny/usage?limit=500.json"), - match=[ - matchers.query_param_matcher( - { - "limit": 500, - }, - ), - ], - ) - - mock_get[3] = responses.get( - "https://connect.example/__api__/v1/instrumentation/shiny/usage", - json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), - match=[ - matchers.query_param_matcher( - { - "next": "23948901087", - "limit": 500, - }, - ), - ], - ) + match=[ + matchers.query_param_matcher( + { + "next": "23948901087", + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/shiny/usage", + json=load_mock("v1/instrumentation/shiny/usage?limit=500.json"), + match=[ + matchers.query_param_matcher( + { + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/shiny/usage", + json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), + match=[ + matchers.query_param_matcher( + { + "next": "23948901087", + "limit": 500, + }, + ), + ], + ), + ] # setup c = connect.Client("https://connect.example", "12345") @@ -162,57 +170,56 @@ class TestUsageFindOne: @responses.activate def test(self): # behavior - mock_get = [None] * 4 - - mock_get[0] = responses.get( - "https://connect.example/__api__/v1/instrumentation/content/visits", - json=load_mock("v1/instrumentation/content/visits?limit=500.json"), - match=[ - matchers.query_param_matcher( - { - "limit": 500, - }, - ), - ], - ) - - mock_get[1] = responses.get( - "https://connect.example/__api__/v1/instrumentation/content/visits", - json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"), - match=[ - matchers.query_param_matcher( - { - "next": "23948901087", - "limit": 500, - }, + mock_get = [ + responses.get( + "https://connect.example/__api__/v1/instrumentation/content/visits", + json=load_mock("v1/instrumentation/content/visits?limit=500.json"), + match=[ + matchers.query_param_matcher( + { + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/content/visits", + json=load_mock( + "v1/instrumentation/content/visits?limit=500&next=23948901087.json" ), - ], - ) - - mock_get[2] = responses.get( - "https://connect.example/__api__/v1/instrumentation/shiny/usage", - json=load_mock("v1/instrumentation/shiny/usage?limit=500.json"), - match=[ - matchers.query_param_matcher( - { - "limit": 500, - }, - ), - ], - ) - - mock_get[3] = responses.get( - "https://connect.example/__api__/v1/instrumentation/shiny/usage", - json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), - match=[ - matchers.query_param_matcher( - { - "next": "23948901087", - "limit": 500, - }, - ), - ], - ) + match=[ + matchers.query_param_matcher( + { + "next": "23948901087", + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/shiny/usage", + json=load_mock("v1/instrumentation/shiny/usage?limit=500.json"), + match=[ + matchers.query_param_matcher( + { + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/shiny/usage", + json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), + match=[ + matchers.query_param_matcher( + { + "next": "23948901087", + "limit": 500, + }, + ), + ], + ), + ] # setup c = connect.Client("https://connect.example", "12345") @@ -231,18 +238,19 @@ def test(self): @responses.activate def test_none(self): # behavior - mock_get = [None] * 2 - - # return an empty result set to push through the iterator - mock_get[0] = responses.get( - "https://connect.example/__api__/v1/instrumentation/content/visits", - json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"), - ) - - mock_get[1] = responses.get( - "https://connect.example/__api__/v1/instrumentation/shiny/usage", - json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), - ) + mock_get = [ + # return an empty result set to push through the iterator + responses.get( + "https://connect.example/__api__/v1/instrumentation/content/visits", + json=load_mock( + "v1/instrumentation/content/visits?limit=500&next=23948901087.json" + ), + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/shiny/usage", + json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"), + ), + ] # setup c = connect.Client("https://connect.example", "12345") diff --git a/tests/posit/connect/metrics/test_visits.py b/tests/posit/connect/metrics/test_visits.py index 3dee9d43..a8c12449 100644 --- a/tests/posit/connect/metrics/test_visits.py +++ b/tests/posit/connect/metrics/test_visits.py @@ -6,15 +6,21 @@ from posit.connect.metrics import visits from posit.connect.resources import ResourceParameters +from posit.connect.urls import Url -from ..api import load_mock +from ..api import load_mock, load_mock_dict class TestVisitAttributes: + @classmethod def setup_class(cls): + results = load_mock_dict("v1/instrumentation/content/visits?limit=500.json")["results"] + assert isinstance(results, list) + first_result_dict = results[0] + assert isinstance(first_result_dict, dict) cls.visit = visits.VisitEvent( mock.Mock(), - **load_mock("v1/instrumentation/content/visits?limit=500.json")["results"][0], + **first_result_dict, ) def test_content_guid(self): @@ -46,34 +52,36 @@ class TestVisitsFind: @responses.activate def test(self): # behavior - mock_get = [None] * 2 - mock_get[0] = responses.get( - "https://connect.example/__api__/v1/instrumentation/content/visits", - json=load_mock("v1/instrumentation/content/visits?limit=500.json"), - match=[ - matchers.query_param_matcher( - { - "limit": 500, - }, + mock_get = [ + responses.get( + "https://connect.example/__api__/v1/instrumentation/content/visits", + json=load_mock("v1/instrumentation/content/visits?limit=500.json"), + match=[ + matchers.query_param_matcher( + { + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/content/visits", + json=load_mock( + "v1/instrumentation/content/visits?limit=500&next=23948901087.json" ), - ], - ) - - mock_get[1] = responses.get( - "https://connect.example/__api__/v1/instrumentation/content/visits", - json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"), - match=[ - matchers.query_param_matcher( - { - "next": "23948901087", - "limit": 500, - }, - ), - ], - ) + match=[ + matchers.query_param_matcher( + { + "next": "23948901087", + "limit": 500, + }, + ), + ], + ), + ] # setup - params = ResourceParameters(requests.Session(), "https://connect.example/__api__") + params = ResourceParameters(requests.Session(), Url("https://connect.example/__api__")) # invoke events = visits.Visits(params).find() @@ -88,34 +96,36 @@ class TestVisitsFindOne: @responses.activate def test(self): # behavior - mock_get = [None] * 2 - mock_get[0] = responses.get( - "https://connect.example/__api__/v1/instrumentation/content/visits", - json=load_mock("v1/instrumentation/content/visits?limit=500.json"), - match=[ - matchers.query_param_matcher( - { - "limit": 500, - }, + mock_get = [ + responses.get( + "https://connect.example/__api__/v1/instrumentation/content/visits", + json=load_mock("v1/instrumentation/content/visits?limit=500.json"), + match=[ + matchers.query_param_matcher( + { + "limit": 500, + }, + ), + ], + ), + responses.get( + "https://connect.example/__api__/v1/instrumentation/content/visits", + json=load_mock( + "v1/instrumentation/content/visits?limit=500&next=23948901087.json" ), - ], - ) - - mock_get[1] = responses.get( - "https://connect.example/__api__/v1/instrumentation/content/visits", - json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"), - match=[ - matchers.query_param_matcher( - { - "next": "23948901087", - "limit": 500, - }, - ), - ], - ) + match=[ + matchers.query_param_matcher( + { + "next": "23948901087", + "limit": 500, + }, + ), + ], + ), + ] # setup - params = ResourceParameters(requests.Session(), "https://connect.example/__api__") + params = ResourceParameters(requests.Session(), Url("https://connect.example/__api__")) # invoke event = visits.Visits(params).find_one() diff --git a/tests/posit/connect/oauth/test_associations.py b/tests/posit/connect/oauth/test_associations.py index 7ea13a70..5f26f9cb 100644 --- a/tests/posit/connect/oauth/test_associations.py +++ b/tests/posit/connect/oauth/test_associations.py @@ -5,14 +5,14 @@ from posit.connect.client import Client from posit.connect.oauth.associations import Association -from ..api import load_mock +from ..api import load_mock, load_mock_list class TestAssociationAttributes: @classmethod def setup_class(cls): guid = "22644575-a27b-4118-ad06-e24459b05126" - fake_items = load_mock(f"v1/oauth/integrations/{guid}/associations.json") + fake_items = load_mock_list(f"v1/oauth/integrations/{guid}/associations.json") assert len(fake_items) == 1 fake_item = fake_items[0] diff --git a/tests/posit/connect/oauth/test_integrations.py b/tests/posit/connect/oauth/test_integrations.py index 37e7382a..3f136f4e 100644 --- a/tests/posit/connect/oauth/test_integrations.py +++ b/tests/posit/connect/oauth/test_integrations.py @@ -3,7 +3,7 @@ from posit.connect.client import Client -from ..api import load_mock +from ..api import load_mock, load_mock_dict class TestIntegrationDelete: @@ -50,7 +50,7 @@ def test(self): new_name = "New Name" - fake_integration = load_mock(f"v1/oauth/integrations/{guid}.json") + fake_integration = load_mock_dict(f"v1/oauth/integrations/{guid}.json") fake_integration.update(name=new_name) assert fake_integration["name"] == new_name @@ -69,7 +69,7 @@ class TestIntegrationsCreate: def test(self): # data guid = "22644575-a27b-4118-ad06-e24459b05126" - fake_integration = load_mock(f"v1/oauth/integrations/{guid}.json") + fake_integration = load_mock_dict(f"v1/oauth/integrations/{guid}.json") # behavior mock_create = responses.post( diff --git a/tests/posit/connect/oauth/test_oauth.py b/tests/posit/connect/oauth/test_oauth.py index fce2f42b..f233e0bb 100644 --- a/tests/posit/connect/oauth/test_oauth.py +++ b/tests/posit/connect/oauth/test_oauth.py @@ -25,4 +25,6 @@ def test_get_credentials(self): ) c = Client(api_key="12345", url="https://connect.example/") c.ctx.version = None - assert c.oauth.get_credentials("cit")["access_token"] == "viewer-token" + creds = c.oauth.get_credentials("cit") + assert "access_token" in creds + assert creds["access_token"] == "viewer-token" diff --git a/tests/posit/connect/test_bundles.py b/tests/posit/connect/test_bundles.py index 091cbbfe..9188d1a6 100644 --- a/tests/posit/connect/test_bundles.py +++ b/tests/posit/connect/test_bundles.py @@ -153,7 +153,9 @@ def test_output_as_io(self): # invoke file = io.BytesIO() - buffer = io.BufferedWriter(file) + buffer = io.BufferedWriter( + file # pyright: ignore[reportArgumentType] + ) bundle.download(buffer) buffer.seek(0) @@ -191,7 +193,9 @@ def test_invalid_arguments(self): # invoke with pytest.raises(TypeError): - bundle.download(None) + bundle.download( + None # pyright: ignore[reportArgumentType] + ) # assert assert mock_content_get.call_count == 1 @@ -279,7 +283,9 @@ def test_invalid_arguments(self): # invoke with pytest.raises(TypeError): - content.bundles.create(None) + content.bundles.create( + None # pyright: ignore[reportArgumentType] + ) class TestBundlesFind: diff --git a/tests/posit/connect/test_client.py b/tests/posit/connect/test_client.py index 88d6cecb..e6a07d3c 100644 --- a/tests/posit/connect/test_client.py +++ b/tests/posit/connect/test_client.py @@ -1,3 +1,4 @@ +# pyright: reportFunctionMemberAccess=false from unittest.mock import MagicMock, patch import pytest diff --git a/tests/posit/connect/test_groups.py b/tests/posit/connect/test_groups.py index 7d484b15..71954e56 100644 --- a/tests/posit/connect/test_groups.py +++ b/tests/posit/connect/test_groups.py @@ -3,7 +3,7 @@ from posit.connect.groups import Group -from .api import load_mock +from .api import load_mock_dict session = Mock() url = Mock() @@ -13,7 +13,7 @@ class TestGroupAttributes: @classmethod def setup_class(cls): guid = "6f300623-1e0c-48e6-a473-ddf630c0c0c3" - fake_item = load_mock(f"v1/groups/{guid}.json") + fake_item = load_mock_dict(f"v1/groups/{guid}.json") cls.item = Group(mock.Mock(), **fake_item) def test_guid(self): diff --git a/tests/posit/connect/test_permissions.py b/tests/posit/connect/test_permissions.py index bf9d9c25..0f3a390a 100644 --- a/tests/posit/connect/test_permissions.py +++ b/tests/posit/connect/test_permissions.py @@ -9,7 +9,7 @@ from posit.connect.resources import ResourceParameters from posit.connect.urls import Url -from .api import load_mock +from .api import load_mock, load_mock_dict, load_mock_list class TestPermissionDelete: @@ -26,7 +26,7 @@ def test(self): # setup params = ResourceParameters(requests.Session(), Url("https://connect.example/__api__")) - fake_permission = load_mock(f"v1/content/{content_guid}/permissions/{uid}.json") + fake_permission = load_mock_dict(f"v1/content/{content_guid}/permissions/{uid}.json") permission = Permission(params, **fake_permission) # invoke @@ -91,7 +91,7 @@ def test_role_update(self): uid = "94" content_guid = "f2f37341-e21d-3d80-c698-a935ad614066" - fake_permission = load_mock(f"v1/content/{content_guid}/permissions/{uid}.json") + fake_permission = load_mock_dict(f"v1/content/{content_guid}/permissions/{uid}.json") fake_permission.update(role=new_role) # define api behavior @@ -126,7 +126,7 @@ class TestPermissionsCount: def test(self): # test data content_guid = "f2f37341-e21d-3d80-c698-a935ad614066" - fake_permissions = load_mock(f"v1/content/{content_guid}/permissions.json") + fake_permissions = load_mock_list(f"v1/content/{content_guid}/permissions.json") # define api behavior responses.get( @@ -155,7 +155,7 @@ def test(self): principal_type = "user" role = "owner" fake_permission = { - **load_mock(f"v1/content/{content_guid}/permissions/{uid}.json"), + **load_mock_dict(f"v1/content/{content_guid}/permissions/{uid}.json"), "principal_guid": principal_guid, "principal_type": principal_type, "role": role, @@ -220,7 +220,7 @@ class TestPermissionsFindOne: def test(self): # test data content_guid = "f2f37341-e21d-3d80-c698-a935ad614066" - fake_permissions = load_mock(f"v1/content/{content_guid}/permissions.json") + fake_permissions = load_mock_list(f"v1/content/{content_guid}/permissions.json") # define api behavior responses.get( diff --git a/tests/posit/connect/test_tasks.py b/tests/posit/connect/test_tasks.py index 5d64bf1c..5de1d2cf 100644 --- a/tests/posit/connect/test_tasks.py +++ b/tests/posit/connect/test_tasks.py @@ -1,19 +1,20 @@ from unittest import mock import responses -from responses import matchers +from responses import BaseResponse, matchers from posit import connect from posit.connect import tasks -from .api import load_mock +from .api import load_mock_dict class TestTaskAttributes: + @classmethod def setup_class(cls): cls.task = tasks.Task( mock.Mock(), - **load_mock("v1/tasks/jXhOhdm5OOSkGhJw.json"), + **load_mock_dict("v1/tasks/jXhOhdm5OOSkGhJw.json"), ) def test_id(self): @@ -47,16 +48,16 @@ def test(self): uid = "jXhOhdm5OOSkGhJw" # behavior - mock_tasks_get = [0] * 2 - mock_tasks_get[0] = responses.get( - f"https://connect.example/__api__/v1/tasks/{uid}", - json={**load_mock(f"v1/tasks/{uid}.json"), "finished": False}, - ) - - mock_tasks_get[1] = responses.get( - f"https://connect.example/__api__/v1/tasks/{uid}", - json={**load_mock(f"v1/tasks/{uid}.json"), "finished": True}, - ) + mock_tasks_get = [ + responses.get( + f"https://connect.example/__api__/v1/tasks/{uid}", + json={**load_mock_dict(f"v1/tasks/{uid}.json"), "finished": False}, + ), + responses.get( + f"https://connect.example/__api__/v1/tasks/{uid}", + json={**load_mock_dict(f"v1/tasks/{uid}.json"), "finished": True}, + ), + ] # setup c = connect.Client("https://connect.example", "12345") @@ -77,17 +78,17 @@ def test_with_params(self): params = {"first": 10, "wait": 10} # behavior - mock_tasks_get = [0] * 2 - mock_tasks_get[0] = responses.get( - f"https://connect.example/__api__/v1/tasks/{uid}", - json={**load_mock(f"v1/tasks/{uid}.json"), "finished": False}, - ) - - mock_tasks_get[1] = responses.get( - f"https://connect.example/__api__/v1/tasks/{uid}", - json={**load_mock(f"v1/tasks/{uid}.json"), "finished": True}, - match=[matchers.query_param_matcher(params)], - ) + mock_tasks_get = [ + responses.get( + f"https://connect.example/__api__/v1/tasks/{uid}", + json={**load_mock_dict(f"v1/tasks/{uid}.json"), "finished": False}, + ), + responses.get( + f"https://connect.example/__api__/v1/tasks/{uid}", + json={**load_mock_dict(f"v1/tasks/{uid}.json"), "finished": True}, + match=[matchers.query_param_matcher(params)], + ), + ] # setup c = connect.Client("https://connect.example", "12345") @@ -109,16 +110,16 @@ def test(self): uid = "jXhOhdm5OOSkGhJw" # behavior - mock_tasks_get = [0] * 2 - mock_tasks_get[0] = responses.get( - f"https://connect.example/__api__/v1/tasks/{uid}", - json={**load_mock(f"v1/tasks/{uid}.json"), "finished": False}, - ) - - mock_tasks_get[1] = responses.get( - f"https://connect.example/__api__/v1/tasks/{uid}", - json={**load_mock(f"v1/tasks/{uid}.json"), "finished": True}, - ) + mock_tasks_get = [ + responses.get( + f"https://connect.example/__api__/v1/tasks/{uid}", + json={**load_mock_dict(f"v1/tasks/{uid}.json"), "finished": False}, + ), + responses.get( + f"https://connect.example/__api__/v1/tasks/{uid}", + json={**load_mock_dict(f"v1/tasks/{uid}.json"), "finished": True}, + ), + ] # setup c = connect.Client("https://connect.example", "12345") @@ -140,9 +141,9 @@ def test(self): uid = "jXhOhdm5OOSkGhJw" # behavior - mock_tasks_get = responses.get( + mock_tasks_get: BaseResponse = responses.get( f"https://connect.example/__api__/v1/tasks/{uid}", - json={**load_mock(f"v1/tasks/{uid}.json"), "finished": False}, + json={**load_mock_dict(f"v1/tasks/{uid}.json"), "finished": False}, ) # setup diff --git a/tests/posit/connect/test_users.py b/tests/posit/connect/test_users.py index 4c235465..68adbb3b 100644 --- a/tests/posit/connect/test_users.py +++ b/tests/posit/connect/test_users.py @@ -247,7 +247,7 @@ def test_params(self): json=load_mock("v1/users?page_number=1&page_size=500.jsonc"), ) con = Client(api_key="12345", url="https://connect.example/") - con.users.find_one(key1="value1", key2="value2", key3="value3") + con.users.find_one(key1="value1", key2="value2", key3="value3") # pyright: ignore[reportCallIssue] assert mock_get.call_count == 1 @responses.activate @@ -328,7 +328,7 @@ def test_params(self): json=load_mock("v1/users?page_number=2&page_size=500.jsonc"), ) con = Client(api_key="12345", url="https://connect.example/") - con.users.find_one(key1="value1", key2="value2", key3="value3") + con.users.find_one(key1="value1", key2="value2", key3="value3") # pyright: ignore[reportCallIssue] responses.assert_call_count( "https://connect.example/__api__/v1/users?key1=value1&key2=value2&key3=value3&page_number=1&page_size=500", 1, @@ -340,4 +340,6 @@ def test_params_not_dict_like(self): con = Client(api_key="12345", url="https://connect.example/") not_dict_like = "string" with pytest.raises(TypeError): - con.users.find(not_dict_like) + con.users.find( + not_dict_like # pyright: ignore[reportCallIssue] + ) diff --git a/tests/posit/connect/test_vanities.py b/tests/posit/connect/test_vanities.py index e77bfc54..cfa3dd4a 100644 --- a/tests/posit/connect/test_vanities.py +++ b/tests/posit/connect/test_vanities.py @@ -37,7 +37,13 @@ def test_destroy_calls_after_destroy_callback(self): url = Url(base_url) after_destroy = Mock() params = ResourceParameters(session, url) - vanity = Vanity(params, after_destroy=after_destroy, content_guid=content_guid) + vanity = Vanity( + params, + after_destroy=after_destroy, + content_guid=content_guid, + path=Mock(), + created_time=Mock(), + ) vanity.destroy()