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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
import uuid
import pytest
from globus_sdk.scopes import Scope
def test_scope_with_dependency_leaves_original_unchanged():
s1 = Scope(uuid.uuid1().hex)
s2 = Scope("s2")
s3 = s1.with_dependency(s2)
assert s1.scope_string == s3.scope_string
assert len(s1.dependencies) == 0
assert len(s3.dependencies) == 1
def test_scope_with_dependencies_leaves_original_unchanged():
s1 = Scope(uuid.uuid1().hex)
s2 = Scope("s2")
s3 = Scope("s3")
s4 = s1.with_dependencies((s2, s3))
assert s1.scope_string == s4.scope_string
assert len(s1.dependencies) == 0
assert len(s4.dependencies) == 2
def test_scope_with_optional_leaves_original_unchanged():
s1 = Scope(uuid.uuid1().hex)
s2 = s1.with_optional(True)
s3 = s2.with_optional(False)
assert s1.scope_string == s2.scope_string == s3.scope_string
assert len(s1.dependencies) == 0
assert len(s2.dependencies) == 0
assert len(s3.dependencies) == 0
assert not s1.optional
assert s2.optional
assert not s3.optional
def test_scope_with_string_dependency_gets_typeerror():
s = Scope("x")
with pytest.raises(
TypeError,
match=r"Scope\.with_dependency\(\) takes a Scope as its input\. Got: 'str'",
):
s.with_dependency("y")
def test_scope_with_string_dependencies_gets_typeerror():
s = Scope("x")
with pytest.raises(
TypeError,
match=(
r"Scope\.with_dependencies\(\) takes an iterable of Scopes as its input\. "
"At position 0, got: 'str'"
),
):
s.with_dependencies(["y"])
def test_scope_with_mixed_dependencies_gets_typeerror():
s = Scope("x")
with pytest.raises(
TypeError,
match=(
r"Scope\.with_dependencies\(\) takes an iterable of Scopes as its input\. "
"At position 1, got: 'str'"
),
):
s.with_dependencies([Scope("y"), "z"])
|