Skip to content

Commit 1a1360a

Browse files
authored
Merge pull request #138 from 1Password/jill/fix-load-dict-type
fix: return type annotation for load_dict
2 parents 6a913d3 + 9fd569a commit 1a1360a

2 files changed

Lines changed: 50 additions & 5 deletions

File tree

src/onepasswordconnectsdk/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ def get_client_args(self, base_url: str, headers: Dict[str, str], timeout: float
4949
'headers': headers,
5050
'timeout': timeout,
5151
}
52-
52+
5353
# Set verify from ca_file first
5454
if self.ca_file:
5555
args['verify'] = self.ca_file
56-
56+
5757
# Allow httpx_options (including verify) to override
5858
args.update(self.httpx_options)
59-
59+
6060
return args
6161

6262

@@ -100,7 +100,7 @@ def load_dict(client: "Client", config: dict):
100100
"""
101101

102102
items: dict = {}
103-
config_values: Dict[str, str] = {}
103+
config_values: Dict[str, Optional[str]] = {}
104104

105105
for field, tags in config.items():
106106
item_tag = tags.get(ITEM_TAG)
@@ -236,7 +236,7 @@ def _set_values_for_item(
236236
section_id = field.section.id
237237
except AttributeError:
238238
section_id = None
239-
239+
240240
if field.label == path_parts[1]:
241241
if (
242242
section_id is None

src/tests/test_config.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ def test_load_dict(respx_mock):
7373
assert config_with_values['password'] == PASSWORD_VALUE
7474

7575

76+
def test_load_dict_empty_field_returns_none(respx_mock):
77+
config_dict = {
78+
"username": {
79+
"opitem": ITEM_NAME1,
80+
"opfield": ".username",
81+
"opvault": VAULT_ID
82+
},
83+
"empty": {
84+
"opitem": ITEM_NAME1,
85+
"opfield": ".empty_field",
86+
"opvault": VAULT_ID
87+
}
88+
}
89+
90+
respx_mock.get(f"v1/vaults/{VAULT_ID}/items?filter=title eq \"{ITEM_NAME1}\"").mock(
91+
return_value=Response(200, json=[item_with_empty_field]))
92+
respx_mock.get(f"v1/vaults/{VAULT_ID}/items/{ITEM_ID1}").mock(
93+
return_value=Response(200, json=item_with_empty_field))
94+
95+
config_with_values = onepasswordconnectsdk.load_dict(SS_CLIENT, config_dict)
96+
97+
assert config_with_values['username'] == USERNAME_VALUE
98+
assert config_with_values['empty'] is None
99+
100+
76101
item = {
77102
"id": ITEM_ID1,
78103
"title": ITEM_NAME1,
@@ -103,6 +128,26 @@ def test_load_dict(respx_mock):
103128
]
104129
}
105130

131+
item_with_empty_field = {
132+
"id": ITEM_ID1,
133+
"title": ITEM_NAME1,
134+
"vault": {
135+
"id": VAULT_ID
136+
},
137+
"category": "LOGIN",
138+
"fields": [
139+
{
140+
"id": "username",
141+
"label": "username",
142+
"value": USERNAME_VALUE
143+
},
144+
{
145+
"id": "empty_field",
146+
"label": "empty_field"
147+
}
148+
]
149+
}
150+
106151
item2 = {
107152
"id": ITEM_ID2,
108153
"title": ITEM_NAME2,

0 commit comments

Comments
 (0)