File: test_token_storage.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 (51 lines) | stat: -rw-r--r-- 1,673 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
39
40
41
42
43
44
45
46
47
48
49
50
51
import pytest

from globus_sdk import GlobusSDKUsageError
from globus_sdk.token_storage.base import _slugify_app_name


@pytest.mark.parametrize(
    "app_name, expected_slug",
    (
        ("Globus CLI v3.30.0", "globus-cli-v3-30-0"),
        ("my-cool-app", "my-cool-app"),
        ("jonathan", "jonathan"),
    ),
)
def test_app_name_slugification_of_basic_app_names(app_name, expected_slug):
    actual_slug = _slugify_app_name(app_name)
    assert actual_slug == expected_slug


def test_app_name_slugification_replaces_reserved_characters():
    app_name = 'glob<>:"/\\|?*us'
    expected = "glob+++++++++us"
    actual_slug = _slugify_app_name(app_name)
    assert actual_slug == expected


def test_app_name_slugification_removes_control_characters():
    app_name = "glob\0\n\t\rus"
    expected = "globus"
    actual_slug = _slugify_app_name(app_name)
    assert actual_slug == expected


def test_app_name_slugification_rejects_empty_name():
    with pytest.raises(GlobusSDKUsageError, match="name results in the empty string"):
        _slugify_app_name("\n\t\r")


@pytest.mark.parametrize("app_name", ("CON", "PRN\n", "nul", "LPT9", "COM1"))
def test_app_name_slugification_rejects_reserved_names(app_name):
    # # https://stackoverflow.com/a/31976060
    with pytest.raises(GlobusSDKUsageError, match="reserved filename"):
        _slugify_app_name(app_name)


def test_app_name_allows_reserved_name_prefixes():
    # Prefix of app name ("CON") is reserved, but the slugified name is not.
    app_name = "Continuous Deployment App"
    expected = "continuous-deployment-app"
    actual_slug = _slugify_app_name(app_name)
    assert actual_slug == expected