File: test_sqlite_adapter.py

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (38 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pytest

from globus_sdk.token_storage.legacy import SQLiteAdapter


def test_sqlite_reading_bad_config():
    adapter = SQLiteAdapter(":memory:")
    # inject bad data (array, needs to be dict)
    # store_config does not check the input type, just uses json.dumps()
    adapter.store_config("foo_conf", [])

    with pytest.raises(ValueError, match="reading config data and got non-dict result"):
        adapter.read_config("foo_conf")
    adapter.close()


def test_sqlite_reading_bad_token_data():
    adapter = SQLiteAdapter(":memory:")
    # inject bad data (array, needs to be dict)
    adapter._connection.execute(
        """\
INSERT INTO token_storage(namespace, resource_server, token_data_json)
VALUES (?, ?, ?)""",
        (adapter.namespace, "foo_rs", "[]"),
    )
    with pytest.raises(
        ValueError, match="data error: token data was not saved as a dict"
    ):
        adapter.get_token_data("foo_rs")
    adapter.close()


def test_sqliteadapter_passes_connect_params():
    with pytest.raises(TypeError):
        SQLiteAdapter(":memory:", connect_params={"invalid_kwarg": True})

    adapter = SQLiteAdapter(":memory:", connect_params={"timeout": 10})
    adapter.close()