def test_multiple_adapters_store_and_retrieve(mock_response, db_filename): adapter1 = SQLiteAdapter(db_filename) adapter2 = SQLiteAdapter(db_filename) adapter1.store(mock_response) data = adapter2.get_by_resource_server() assert data == mock_response.by_resource_server
def test_multiple_adapters_store_and_retrieve_different_namespaces( mock_response, db_filename): adapter1 = SQLiteAdapter(db_filename, namespace="foo") adapter2 = SQLiteAdapter(db_filename, namespace="bar") adapter1.store(mock_response) data = adapter2.get_by_resource_server() assert data == {}
def test_remove_tokens(mock_response): adapter = SQLiteAdapter(MEMORY_DBNAME) adapter.store(mock_response) removed = adapter.remove_tokens_for_resource_server("resource_server_1") assert removed data = adapter.get_by_resource_server() assert data == { "resource_server_2": mock_response.by_resource_server["resource_server_2"] } removed = adapter.remove_tokens_for_resource_server("resource_server_1") assert not removed
def test_store_and_refresh(mock_response, mock_refresh_response): adapter = SQLiteAdapter(MEMORY_DBNAME) adapter.store(mock_response) # rs1 and rs2 data was stored correctly data = adapter.get_token_data("resource_server_1") assert data["access_token"] == "access_token_1" data = adapter.get_token_data("resource_server_2") assert data["access_token"] == "access_token_2" # "refresh" happens, this should change rs2 but not rs1 adapter.store(mock_refresh_response) data = adapter.get_token_data("resource_server_1") assert data["access_token"] == "access_token_1" data = adapter.get_token_data("resource_server_2") assert data["access_token"] == "access_token_2_refreshed"
def test_iter_namespaces(mock_response, db_filename): foo_adapter = SQLiteAdapter(db_filename, namespace="foo") bar_adapter = SQLiteAdapter(db_filename, namespace="bar") baz_adapter = SQLiteAdapter(db_filename, namespace="baz") for adapter in [foo_adapter, bar_adapter, baz_adapter]: assert list(adapter.iter_namespaces()) == [] assert list( adapter.iter_namespaces(include_config_namespaces=True)) == [] foo_adapter.store(mock_response) for adapter in [foo_adapter, bar_adapter, baz_adapter]: assert list(adapter.iter_namespaces()) == ["foo"] assert list(adapter.iter_namespaces( include_config_namespaces=True)) == ["foo"] bar_adapter.store(mock_response) for adapter in [foo_adapter, bar_adapter, baz_adapter]: assert set(adapter.iter_namespaces()) == {"foo", "bar"} assert set( adapter.iter_namespaces(include_config_namespaces=True)) == { "foo", "bar", } baz_adapter.store_config("some_conf", {}) for adapter in [foo_adapter, bar_adapter, baz_adapter]: assert set(adapter.iter_namespaces()) == {"foo", "bar"} assert set( adapter.iter_namespaces(include_config_namespaces=True)) == { "foo", "bar", "baz", }
def test_store_and_retrieve(mock_response): adapter = SQLiteAdapter(MEMORY_DBNAME) adapter.store(mock_response) data = adapter.get_by_resource_server() assert data == mock_response.by_resource_server