Refactor tests, no g required
This commit is contained in:
parent
43dd974dca
commit
21d969d309
1 changed files with 10 additions and 6 deletions
|
@ -1,8 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
from flask import g
|
from flask_principal import Identity, Principal
|
||||||
from flask_principal import Identity
|
|
||||||
|
|
||||||
from endpoints.v2.v2auth import get_tuf_root
|
from endpoints.v2.v2auth import get_tuf_root
|
||||||
from auth import permissions
|
from auth import permissions
|
||||||
|
@ -25,6 +24,12 @@ def read_identity(namespace, reponame):
|
||||||
identity.provides.add(permissions._OrganizationRepoNeed(namespace, 'read'))
|
identity.provides.add(permissions._OrganizationRepoNeed(namespace, 'read'))
|
||||||
return identity
|
return identity
|
||||||
|
|
||||||
|
def app_with_principal():
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
app.config.update(SECRET_KEY='secret', TESTING=True)
|
||||||
|
principal = Principal(app)
|
||||||
|
return app, principal
|
||||||
|
|
||||||
@pytest.mark.parametrize('identity,expected', [
|
@pytest.mark.parametrize('identity,expected', [
|
||||||
(Identity('anon'), 'quay'),
|
(Identity('anon'), 'quay'),
|
||||||
(read_identity("namespace", "repo"), 'quay'),
|
(read_identity("namespace", "repo"), 'quay'),
|
||||||
|
@ -35,9 +40,8 @@ def read_identity(namespace, reponame):
|
||||||
(write_identity("namespace", "repo"), 'signer'),
|
(write_identity("namespace", "repo"), 'signer'),
|
||||||
])
|
])
|
||||||
def test_get_tuf_root(identity, expected):
|
def test_get_tuf_root(identity, expected):
|
||||||
app = flask.Flask(__name__)
|
app, principal = app_with_principal()
|
||||||
|
|
||||||
with app.test_request_context('/'):
|
with app.test_request_context('/'):
|
||||||
g.identity = identity
|
principal.set_identity(identity)
|
||||||
actual = get_tuf_root("namespace", "repo")
|
actual = get_tuf_root("namespace", "repo")
|
||||||
assert actual == expected, "should be %s, but was %s" % (expected, actual)
|
assert actual == expected, "should be %s, but was %s" % (expected, actual)
|
||||||
|
|
Reference in a new issue