Skip to content

Commit

Permalink
Fix tests to run under responses
Browse files Browse the repository at this point in the history
  • Loading branch information
sirosen committed Sep 29, 2021
1 parent 048e5a8 commit 713da21
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/commands/test_show_index.py
Expand Up @@ -26,6 +26,6 @@ def test_collection_show(run_line):
}
"""
)
last_req = responses.calls[-1]
last_req = responses.calls[-1].request
assert last_req.method == "GET"
assert last_req.path == path
assert last_req.path_url == path
54 changes: 54 additions & 0 deletions tests/conftest.py
@@ -1,10 +1,13 @@
import os
import shlex
import time
from unittest import mock

import click
import pytest
import responses
from click.testing import CliRunner
from globus_sdk_tokenstorage import SQLiteAdapter

from globus_search_cli import cli_root

Expand All @@ -27,6 +30,57 @@ def mocked_responses(monkeypatch):
responses.reset()


def _mock_token_response_data(rs_name, scope, token_blob=None):
if token_blob is None:
token_blob = rs_name.split(".")[0]
return {
"scope": scope,
"refresh_token": f"{token_blob}RT",
"access_token": f"{token_blob}AT",
"token_type": "bearer",
"expires_at_seconds": int(time.time()) + 120,
"resource_server": rs_name,
}


@pytest.fixture
def mock_login_token_response():
mock_token_res = mock.Mock()
mock_token_res.by_resource_server = {
"auth.globus.org": _mock_token_response_data(
"auth.globus.org",
"openid profile email "
"urn:globus:auth:scope:auth.globus.org:view_identity_set",
),
"search.api.globus.org": _mock_token_response_data(
"search.api.globus.org",
"urn:globus:auth:scope:search.api.globus.org:all",
),
}
return mock_token_res


@pytest.fixture
def test_token_storage(mock_login_token_response):
"""Put memory-backed sqlite token storage in place for the testsuite to use."""
mockstore = SQLiteAdapter(":memory:")
mockstore.store_config(
"auth_client_data",
{"client_id": "fakeClientIDString", "client_secret": "fakeClientSecret"},
)
mockstore.store(mock_login_token_response)
return mockstore


@pytest.fixture(autouse=True)
def patch_tokenstorage(monkeypatch, test_token_storage):
monkeypatch.setattr(
"globus_search_cli.config.token_storage_adapter._instance",
test_token_storage,
raising=False,
)


@pytest.fixture
def run_line(monkeypatch):
"""
Expand Down

0 comments on commit 713da21

Please sign in to comment.