def test_persist_set_attr_dict(jsonpath): mydict = persist(jsonpath) mydict["_path"] = "foo" mydict["a"] = "b" newdict = persist(jsonpath) assert newdict.a == "b"
def load_data(): if os.path.isfile(BOOT_CONF_PATH): try: dest = shutil.copyfile(BOOT_CONF_PATH, CONF_PATH) print("Boot config file copied:", dest) os.remove(BOOT_CONF_PATH) except: print("Error occurred while copying file.") conf = Config( CONF_PATH, defaults={ 'ap_name': 'comitup-<nnn>', 'ap_password': '', 'web_service': '', 'service_name': 'comitup', 'external_callback': '/usr/local/bin/comitup-callback', }, ) data = persist.persist( PERSIST_PATH, {'id': str(random.randrange(1000, 9999))}, ) return (conf, data)
def load_data(): conf = config.Config( CONF_PATH, defaults={ 'base_name': 'comitup', 'web_service': '', 'external_callback': '/usr/local/bin/comitup-callback', }, ) data = persist.persist( PERSIST_PATH, {'id': str(random.randrange(1000, 9999))}, ) return (conf, data)
def load_data(): if os.path.isfile(BOOT_CONF_PATH): try: dest = shutil.copyfile(BOOT_CONF_PATH, CONF_PATH) print("Boot config file copied:", dest) log.info("Boot config file copied: {}".format(dest)) os.remove(BOOT_CONF_PATH) except Exception: print("Error occurred while copying file.") log.error("Error occurred while copying file.") conf = Config( CONF_PATH, defaults={ 'ap_name': DEFAULT_AP, 'ap_password': '', 'web_service': '', 'service_name': 'comitup', 'external_callback': '/usr/local/bin/comitup-callback', }, ) data = persist.persist( PERSIST_PATH, {'id': str(random.randrange(1000, 9999))}, ) spec = re.search(REGEX_APNAME_ID, conf.ap_name) if spec is not None: # if spec is '<nnn...' data already includes 'id' random number # get MAC or SerialNumber if required if spec.group().startswith('<M'): data['mac'] = _get_mac() if spec.group().startswith('<s'): data['sn']: _getserial() log.debug(data) return (conf, data)
def load_data() -> Tuple[Config, persist.persist]: global data_cache if not data_cache: if os.path.isfile(BOOT_CONF_PATH): try: dest = shutil.copyfile(BOOT_CONF_PATH, CONF_PATH) print("Boot config file copied:", dest) os.remove(BOOT_CONF_PATH) except Exception: print("Error occurred while copying file.") conf = Config( CONF_PATH, defaults={ "ap_name": "comitup-<nnn>", "ap_password": "", "web_service": "", "service_name": "comitup", "external_callback": "/usr/local/bin/comitup-callback", "verbose": "0", "enable_appliance_mode": "1", "primary_wifi_device": "", "enable_nuke": "0", "ipv6_link_local": 1, }, ) data = persist.persist( PERSIST_PATH, {"id": str(random.randrange(1000, 9999))}, ) data_cache = (conf, data) return data_cache
def test_persist_default_persists(jsonpath): persist(jsonpath, {'a': 'b'}) new = persist(jsonpath) assert new['a'] == 'b'
def test_persist_override_default2(jsonpath): mydict = persist(jsonpath, {'a': 'a'}) mydict['a'] = 'b' new = persist(jsonpath, {'a': 'c'}) assert new['a'] == 'b'
def test_persist_get_attr_dict(jsonpath): mydict = persist(jsonpath) assert mydict.path == jsonpath assert mydict.__getattr__('path') == jsonpath
def test_persist_is_dict(jsonpath): mydict = persist(jsonpath) mydict['a'] = 'b' assert mydict['a'] == 'b'
def test_persist_setdefault(jsonpath): mydict = persist(jsonpath) mydict.setdefault("a", "b") new = persist(jsonpath, {"a": "c"}) assert new["a"] == "b"
def test_persist_persist_setattr(jsonpath): mydict = persist(jsonpath) mydict.a = 'b' new = persist(jsonpath) assert new['a'] == 'b'
def test_persist_setdefault(jsonpath): mydict = persist(jsonpath) mydict.setdefault('a', 'b') new = persist(jsonpath, {'a': 'c'}) assert new['a'] == 'b'
def test_persist_getattr(jsonpath): mydict = persist(jsonpath) mydict['a'] = 'b' assert mydict.a == 'b'
def test_persist_update(jsonpath): mydict = persist(jsonpath, {'a': 'a'}) mydict.update({'a': 'b'}) new = persist(jsonpath, {'a': 'c'}) assert new['a'] == 'b'
def test_persist_override_default(jsonpath): persist(jsonpath, {'a': 'b'}) new = persist(jsonpath, {'a': 'c'}) assert new['a'] == 'b'
def test_persist_persist_getattr(jsonpath): mydict = persist(jsonpath) mydict['a'] = 'b' new = persist(jsonpath) assert new.a == 'b'
def test_persist_persist_setattr(jsonpath): mydict = persist(jsonpath) mydict.a = "b" new = persist(jsonpath) assert new["a"] == "b"
def test_persist_update(jsonpath): mydict = persist(jsonpath, {"a": "a"}) mydict.update({"a": "b"}) new = persist(jsonpath, {"a": "c"}) assert new["a"] == "b"
def test_persist_getattr(jsonpath): mydict = persist(jsonpath) mydict["a"] = "b" assert mydict.a == "b"
def test_persist_default(jsonpath): mydict = persist(jsonpath, {'a': 'b'}) assert mydict['a'] == 'b'
def test_persist_persist_getattr(jsonpath): mydict = persist(jsonpath) mydict["a"] = "b" new = persist(jsonpath) assert new.a == "b"
def test_persist_file_format(jsonpath): mydict = persist(jsonpath) mydict["a"] = "b" expected = '{\n "a": "b"\n}' assert open(jsonpath, "r").read() == expected
def test_persist_file_format(jsonpath): mydict = persist(jsonpath) mydict['a'] = 'b' expected = '{\n "a": "b"\n}' assert open(jsonpath, 'r').read() == expected
def test_persist_set_attr_dict(jsonpath): mydict = persist(jsonpath) mydict.path = jsonpath
def test_persist_is_dict(jsonpath): mydict = persist(jsonpath) mydict["a"] = "b" assert mydict["a"] == "b"
def test_persist_default(jsonpath): mydict = persist(jsonpath, {"a": "b"}) assert mydict["a"] == "b"
def test_persist_default_persists(jsonpath): persist(jsonpath, {"a": "b"}) new = persist(jsonpath) assert new["a"] == "b"
def test_persist_override_default2(jsonpath): mydict = persist(jsonpath, {"a": "a"}) mydict["a"] = "b" new = persist(jsonpath, {"a": "c"}) assert new["a"] == "b"
def test_persist_override_default(jsonpath): persist(jsonpath, {"a": "b"}) new = persist(jsonpath, {"a": "c"}) assert new["a"] == "b"