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 75 76 77 78 79 80 81 82 83 84 85
|
from globus_sdk import LocalGlobusConnectServer
def test_info_dict_from_nonexistent_file_is_none(tmp_path):
info_path = tmp_path / "info.json"
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict is None
def test_info_dict_from_non_json_file_is_none(tmp_path):
info_path = tmp_path / "info.json"
info_path.write_text("{")
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict is None
def test_info_dict_from_non_json_object_file_is_none(tmp_path):
info_path = tmp_path / "info.json"
info_path.write_text("[]")
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict is None
def test_info_dict_from_non_unicode_file_is_none(tmp_path):
info_path = tmp_path / "info.json"
info_path.write_bytes(b'{"foo":"{' + bytes.fromhex("1BAD DEC0DE") + b'}"}')
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict is None
def test_info_dict_from_empty_json_file_is_okay_but_has_no_properties(tmp_path):
info_path = tmp_path / "info.json"
info_path.write_text("{}")
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict is not None
assert gcs.endpoint_id is None
assert gcs.domain_name is None
def test_info_dict_can_load_endpoint_id(tmp_path):
info_path = tmp_path / "info.json"
info_path.write_text('{"endpoint_id": "foo"}')
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict is not None
assert gcs.endpoint_id == "foo"
def test_info_dict_can_load_domain(tmp_path):
info_path = tmp_path / "info.json"
info_path.write_text('{"domain_name": "foo"}')
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict is not None
assert gcs.domain_name == "foo"
def test_endpoint_id_property_ignores_non_str_value(tmp_path):
info_path = tmp_path / "info.json"
info_path.write_text('{"endpoint_id": 1}')
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict is not None
assert gcs.endpoint_id is None
def test_domain_name_property_ignores_non_str_value(tmp_path):
info_path = tmp_path / "info.json"
info_path.write_text('{"domain_name": ["foo"]}')
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict is not None
assert gcs.domain_name is None
def test_info_dict_can_reload_with_deleter(tmp_path):
info_path = tmp_path / "info.json"
info_path.write_text('{"foo": "bar"}')
# initial load okay
gcs = LocalGlobusConnectServer(info_path=info_path)
assert gcs.info_dict == {"foo": "bar"}
# update the data on disk
info_path.write_text('{"bar": "baz"}')
# data unchanged on the instance
assert gcs.info_dict == {"foo": "bar"}
# clear and reload updates the data
del gcs.info_dict
assert gcs.info_dict == {"bar": "baz"}
|