Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: replace unpacking usage with dict.update #151

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/posit/connect/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,17 @@ def update(self, *args, **kwargs) -> None:

def update(self, *args, **kwargs) -> None:
"""Update the permission."""
body = dict(*args, **kwargs)
body = {
"principal_guid": self.principal_guid,
"principal_type": self.principal_type,
"role": self.role,
}
body.update(*args, **kwargs)
path = f"v1/content/{self.content_guid}/permissions/{self.id}"
url = urls.append_path(self.config.url, path)
response = self.session.put(
url,
json={
"principal_guid": self.principal_guid,
"principal_type": self.principal_type,
"role": self.role,
# shorthand to overwrite the above fields with method arguments
**body,
},
json=body,
)
super().update(**response.json())

Expand Down
4 changes: 3 additions & 1 deletion tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ def test_update(self):
assert content.guid == guid

new_name = "New Name"
fake_content = load_mock(f"v1/content/{guid}.json")
fake_content.update(name=new_name)
responses.patch(
f"https://connect.example/__api__/v1/content/{guid}",
json={**load_mock(f"v1/content/{guid}.json"), "name": new_name},
json=fake_content,
)

content.update(name=new_name)
Expand Down
8 changes: 3 additions & 5 deletions tests/posit/connect/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,15 @@ def test_role_update(self):

id = "94"
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"
fake_permission = {
**load_mock(f"v1/content/{content_guid}/permissions/{id}.json"),
"role": old_role,
}
fake_permission = load_mock(f"v1/content/{content_guid}/permissions/{id}.json")
fake_permission.update(role=new_role)

# define api behavior
id = random.randint(0, 100)
content_guid = str(uuid.uuid4())
responses.put(
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}",
json={**fake_permission, "role": new_role},
json=fake_permission,
match=[
matchers.json_params_matcher(
{
Expand Down
37 changes: 25 additions & 12 deletions tests/posit/connect/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,24 @@ def test_default(self):

@responses.activate
def test_params(self):
# validate input params are propagated to the query params
params = {"key1": "value1", "key2": "value2", "key3": "value3"}
responses.get(
mock_get = responses.get(
"https://connect.example/__api__/v1/users",
match=[
responses.matchers.query_param_matcher(
{"page_size": 500, "page_number": 1, **params}
{
"page_size": 500,
"page_number": 1,
"key1": "value1",
"key2": "value2",
"key3": "value3",
}
)
],
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(**params)
responses.assert_call_count(
"https://connect.example/__api__/v1/users?key1=value1&key2=value2&key3=value3&page_number=1&page_size=500",
1,
)
con.users.find_one(key1="value1", key2="value2", key3="value3")
assert mock_get.call_count == 1

@responses.activate
def test_empty_results(self):
Expand Down Expand Up @@ -366,7 +367,13 @@ def test_params(self):
"https://connect.example/__api__/v1/users",
match=[
responses.matchers.query_param_matcher(
{"page_size": 500, "page_number": 1, **params}
{
"page_size": 500,
"page_number": 1,
"key1": "value1",
"key2": "value2",
"key3": "value3",
}
)
],
json=load_mock("v1/users?page_number=1&page_size=500.jsonc"),
Expand All @@ -375,13 +382,19 @@ def test_params(self):
"https://connect.example/__api__/v1/users",
match=[
responses.matchers.query_param_matcher(
{"page_size": 500, "page_number": 2, **params}
{
"page_size": 500,
"page_number": 2,
"key1": "value1",
"key2": "value2",
"key3": "value3",
}
)
],
json=load_mock("v1/users?page_number=2&page_size=500.jsonc"),
)
con = Client(api_key="12345", url="https://connect.example/")
con.users.find(**params)
con.users.find_one(key1="value1", key2="value2", key3="value3")
responses.assert_call_count(
"https://connect.example/__api__/v1/users?key1=value1&key2=value2&key3=value3&page_number=1&page_size=500",
1,
Expand Down
Loading