Skip to content

Commit

Permalink
[test/api] fix api tests with jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
adfaure committed Nov 15, 2023
1 parent 01e1da4 commit 3f8d296
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 93 deletions.
2 changes: 1 addition & 1 deletion oar/api/routers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .. import API_VERSION
from ..auth import get_user
from ..dependencies import get_config, get_logger
from ..dependencies import get_config
from . import TimestampRoute

router = APIRouter(
Expand Down
2 changes: 2 additions & 0 deletions oar/api/routers/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ def delete(
config: Configuration = Depends(get_config),
):
# TODO Get and return error codes ans messages
# os.environ["OARDO_USER"] = user

if array:
cmd_ret = oardel(
db, config, None, None, None, None, job_id, None, None, None, user, False
Expand Down
2 changes: 1 addition & 1 deletion oar/cli/oardel.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def oardel(
for job_id in job_ids:
# TODO array of errors and error messages
cmd_ret.info("Deleting the job = {} ...".format(job_id))
error = frag_job(session, job_id)
error = frag_job(session, job_id, user=user)
error_msg = ""
if error == -1:
error_msg = "Cannot frag {} ; You are not the right user.".format(
Expand Down
18 changes: 16 additions & 2 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import oar.lib.tools # for monkeypatching
from oar.api.app import create_app
from oar.api.dependencies import get_db
from oar.lib.access_token import create_access_token

# from oar.lib import db
from oar.lib.database import ephemeral_session
Expand All @@ -33,11 +34,24 @@ def assign_node_list(nodes): # TODO TOREPLACE

@pytest.fixture()
def fastapi_app(setup_config):
config, _, engine = setup_config
app = create_app(config=config, engine=engine)
config, logger, engine = setup_config

app = create_app(config=config, engine=engine, logger=logger)
yield app


@pytest.fixture()
def user_tokens(setup_config):
config, _, _ = setup_config
tokens = {}

tokens["user1"] = create_access_token({"user": "user1"}, config)
tokens["bob"] = create_access_token({"user": "bob"}, config)
tokens["oar"] = create_access_token({"user": "oar"}, config)

yield tokens


@pytest.fixture(scope="function")
def client(fastapi_app, minimal_db_initialization, setup_config):
config, _, db = setup_config
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def test_app_frontend_version(client, setup_config):

def test_app_frontend_whoami(client, setup_config):
config, _, db = setup_config

res = client.get("/whoami")
print(res.json())
assert res.status_code == 200 and "api_timestamp" in res.json()
assert res.json()["authenticated_user"] is None
assert res.status_code == 403


def test_app_frontend_timezone(client, setup_config):
Expand Down
Loading

0 comments on commit 3f8d296

Please sign in to comment.