Add tests for tuf metadata delete
This commit is contained in:
parent
abe6f40bc5
commit
68128b938b
1 changed files with 37 additions and 1 deletions
|
@ -69,4 +69,40 @@ def test_get_metadata_exception(connection_error, response_code, exception):
|
|||
tuf_api = api.TUFMetadataAPI(app, app.config, client=client)
|
||||
tags, expiration = tuf_api.get_default_tags_with_expiration('quay', 'quay')
|
||||
assert tags == None
|
||||
assert expiration == None
|
||||
assert expiration == None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('response_code,expected', [
|
||||
(200, True),
|
||||
(400, False),
|
||||
(401, False),
|
||||
])
|
||||
def test_delete_metadata(response_code, expected):
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(testconfig.TestConfig())
|
||||
client = mock.Mock()
|
||||
request = mock.Mock(status_code=response_code)
|
||||
client.request.return_value = request
|
||||
tuf_api = api.TUFMetadataAPI(app, app.config, client=client)
|
||||
response = tuf_api.delete_metadata('quay', 'quay')
|
||||
assert response == expected
|
||||
|
||||
@pytest.mark.parametrize('response_code,exception', [
|
||||
(200, requests.exceptions.Timeout),
|
||||
(200, requests.exceptions.ConnectionError),
|
||||
(200, requests.exceptions.RequestException),
|
||||
(200, ValueError),
|
||||
(500, api.Non200ResponseException(mock.Mock(status_code=500))),
|
||||
(400, api.Non200ResponseException(mock.Mock(status_code=400))),
|
||||
(401, api.Non200ResponseException(mock.Mock(status_code=401))),
|
||||
(404, api.Non200ResponseException(mock.Mock(status_code=404))),
|
||||
])
|
||||
def test_delete_metadata_exception(response_code, exception):
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(testconfig.TestConfig())
|
||||
request = mock.Mock(status_code=response_code)
|
||||
client = mock.Mock(request=request)
|
||||
client.request.side_effect = exception
|
||||
tuf_api = api.TUFMetadataAPI(app, app.config, client=client)
|
||||
response = tuf_api.delete_metadata('quay', 'quay')
|
||||
assert response == False
|
||||
|
|
Reference in a new issue