Update tests

This commit is contained in:
Evan Cordell 2017-04-05 13:27:31 -04:00
parent 9515f18fb6
commit 1a78722521
6 changed files with 54 additions and 42 deletions

View file

@ -5,6 +5,7 @@ from endpoints.api.team import OrganizationTeamSyncing
from endpoints.api.test.shared import client_with_identity, conduct_api_call
from endpoints.api.superuser import SuperUserRepositoryBuildLogs, SuperUserRepositoryBuildResource
from endpoints.api.superuser import SuperUserRepositoryBuildStatus
from endpoints.api.signing import RepositorySignatures
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
TEAM_PARAMS = {'orgname': 'buynlarge', 'teamname': 'owners'}
@ -35,6 +36,11 @@ BUILD_PARAMS = {'build_uuid': 'test-1234'}
(SuperUserRepositoryBuildResource, 'GET', BUILD_PARAMS, None, 'freshuser', 403),
(SuperUserRepositoryBuildResource, 'GET', BUILD_PARAMS, None, 'reader', 403),
(SuperUserRepositoryBuildResource, 'GET', BUILD_PARAMS, None, 'devtable', 404),
(RepositorySignatures, 'GET', 401, None, None),
(RepositorySignatures, 'GET', 403, 'freshuser', None),
(RepositorySignatures, 'GET', 403, 'reader', None),
(RepositorySignatures, 'GET', 404, 'devtable', None),
])
def test_api_security(resource, method, params, body, identity, expected, client):
with client_with_identity(identity, client) as cl:

View file

@ -0,0 +1,43 @@
from collections import Counter
import pytest
from endpoints.api.test.shared import client_with_identity, conduct_api_call
from endpoints.api.signing import RepositorySignatures
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
from mock import patch
VALID_TARGETS = {
'latest': {
'hashes': {
'sha256': 'mLmxwTyUrqIRDaz8uaBapfrp3GPERfsDg2kiMujlteo='
},
'length': 1500
},
'test_tag': {
'hashes': {
'sha256': '1234123'
},
'length': 50
}
}
def tags_equal(expected, actual):
expected_tags = expected.get('tags')
actual_tags = actual.get('tags')
if expected_tags and actual_tags:
return Counter(expected_tags) == Counter(actual_tags)
return expected == actual
@pytest.mark.parametrize('targets,expected', [
(VALID_TARGETS, {'tags':['latest', 'test_tag']}),
({'bad': 'tags'}, ({'tags': ['bad']})),
({}, ({'tags': None})),
(None, ({'tags': None})), # API returns None on exceptions
])
def test_get_signatures(targets, expected, client):
with patch('endpoints.api.signing.tuf_metadata_api') as mock_tuf:
mock_tuf.get_default_tags.return_value = (targets, False)
with client_with_identity('devtable', client) as cl:
params = {'repository': 'devtable/repo'}
assert tags_equal(expected, conduct_api_call(cl, RepositorySignatures, 'GET', params, None, 200).json)