diff --git a/util/tufmetadata/test/test_tufmetadata.py b/util/tufmetadata/test/test_tufmetadata.py index f46097768..f0cec63b1 100644 --- a/util/tufmetadata/test/test_tufmetadata.py +++ b/util/tufmetadata/test/test_tufmetadata.py @@ -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 \ No newline at end of file + 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