Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroroiz committed Apr 17, 2024
1 parent 9761a24 commit 14159a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion confidant/routes/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def create_credential():
value = escape(value)
metadata[key] = value

documentation = escape(data.get('documentation'))
# TODO: fix documentation escape

sanitized_name = escape(data['name'])
cred = Credential(
Expand Down Expand Up @@ -845,6 +845,8 @@ def update_credential(id):
value = escape(value)
data['metadata'][key] = value

# TODO: fix documentation escape

update = {
'name': data.get('name', _cred.name),
'last_rotation_date': _cred.last_rotation_date,
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/confidant/routes/credentials_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,31 @@ def test_update_credential(mocker: MockerFixture, credential: Credential):
assert ret.status_code == 400
assert 'Credential Pairs cannot be empty.' == json_data['error']


# Credential name already exists (ie: query returns a value)
mocker.patch(
'confidant.routes.credentials.Credential.data_type_date_index.query',
return_value=[credential],
)
ret = app.test_client().put(
'/v1/credentials/123',
headers={"Content-Type": 'application/json'},
data=json.dumps({
'name': 'me',
'documentation': 'doc',
'credential_pairs': {'key': 'value'},
}),
)
json_data = json.loads(ret.data)
assert ret.status_code == 409
assert 'Name already exists' in json_data['error']

# All good
mocker.patch(
('confidant.routes.credentials.Credential'
'.data_type_date_index.query'),
return_value=[],
)
mocker.patch(
('confidant.routes.credentials.servicemanager'
'.pair_key_conflicts_for_services'),
Expand Down

0 comments on commit 14159a9

Please sign in to comment.