예제 #1
0
def test_persist_set_attr_dict(jsonpath):
    mydict = persist(jsonpath)

    mydict["_path"] = "foo"
    mydict["a"] = "b"

    newdict = persist(jsonpath)
    assert newdict.a == "b"
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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
예제 #6
0
def test_persist_default_persists(jsonpath):
    persist(jsonpath, {'a': 'b'})
    new = persist(jsonpath)
    assert new['a'] == 'b'
예제 #7
0
def test_persist_override_default2(jsonpath):
    mydict = persist(jsonpath, {'a': 'a'})
    mydict['a'] = 'b'
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
예제 #8
0
def test_persist_get_attr_dict(jsonpath):
    mydict = persist(jsonpath)

    assert mydict.path == jsonpath
    assert mydict.__getattr__('path') == jsonpath
예제 #9
0
def test_persist_is_dict(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    assert mydict['a'] == 'b'
예제 #10
0
def test_persist_setdefault(jsonpath):
    mydict = persist(jsonpath)
    mydict.setdefault("a", "b")
    new = persist(jsonpath, {"a": "c"})
    assert new["a"] == "b"
예제 #11
0
def test_persist_default_persists(jsonpath):
    persist(jsonpath, {'a': 'b'})
    new = persist(jsonpath)
    assert new['a'] == 'b'
예제 #12
0
def test_persist_persist_setattr(jsonpath):
    mydict = persist(jsonpath)
    mydict.a = 'b'
    new = persist(jsonpath)
    assert new['a'] == 'b'
예제 #13
0
def test_persist_is_dict(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    assert mydict['a'] == 'b'
예제 #14
0
def test_persist_setdefault(jsonpath):
    mydict = persist(jsonpath)
    mydict.setdefault('a', 'b')
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
예제 #15
0
def test_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    assert mydict.a == 'b'
예제 #16
0
def test_persist_update(jsonpath):
    mydict = persist(jsonpath, {'a': 'a'})
    mydict.update({'a': 'b'})
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
예제 #17
0
def test_persist_override_default2(jsonpath):
    mydict = persist(jsonpath, {'a': 'a'})
    mydict['a'] = 'b'
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
예제 #18
0
def test_persist_override_default(jsonpath):
    persist(jsonpath, {'a': 'b'})
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
예제 #19
0
def test_persist_setdefault(jsonpath):
    mydict = persist(jsonpath)
    mydict.setdefault('a', 'b')
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
예제 #20
0
def test_persist_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    new = persist(jsonpath)
    assert new.a == 'b'
예제 #21
0
def test_persist_persist_setattr(jsonpath):
    mydict = persist(jsonpath)
    mydict.a = 'b'
    new = persist(jsonpath)
    assert new['a'] == 'b'
예제 #22
0
def test_persist_persist_setattr(jsonpath):
    mydict = persist(jsonpath)
    mydict.a = "b"
    new = persist(jsonpath)
    assert new["a"] == "b"
예제 #23
0
def test_persist_update(jsonpath):
    mydict = persist(jsonpath, {"a": "a"})
    mydict.update({"a": "b"})
    new = persist(jsonpath, {"a": "c"})
    assert new["a"] == "b"
예제 #24
0
def test_persist_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    new = persist(jsonpath)
    assert new.a == 'b'
예제 #25
0
def test_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict["a"] = "b"
    assert mydict.a == "b"
예제 #26
0
def test_persist_default(jsonpath):
    mydict = persist(jsonpath, {'a': 'b'})
    assert mydict['a'] == 'b'
예제 #27
0
def test_persist_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict["a"] = "b"
    new = persist(jsonpath)
    assert new.a == "b"
예제 #28
0
def test_persist_file_format(jsonpath):
    mydict = persist(jsonpath)
    mydict["a"] = "b"

    expected = '{\n  "a": "b"\n}'
    assert open(jsonpath, "r").read() == expected
예제 #29
0
def test_persist_file_format(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'

    expected = '{\n  "a": "b"\n}'
    assert open(jsonpath, 'r').read() == expected
예제 #30
0
def test_persist_get_attr_dict(jsonpath):
    mydict = persist(jsonpath)

    assert mydict.path == jsonpath
    assert mydict.__getattr__('path') == jsonpath
예제 #31
0
def test_persist_set_attr_dict(jsonpath):
    mydict = persist(jsonpath)

    mydict.path = jsonpath
예제 #32
0
def test_persist_is_dict(jsonpath):
    mydict = persist(jsonpath)
    mydict["a"] = "b"
    assert mydict["a"] == "b"
예제 #33
0
def test_persist_default(jsonpath):
    mydict = persist(jsonpath, {'a': 'b'})
    assert mydict['a'] == 'b'
예제 #34
0
def test_persist_default(jsonpath):
    mydict = persist(jsonpath, {"a": "b"})
    assert mydict["a"] == "b"
예제 #35
0
def test_persist_override_default(jsonpath):
    persist(jsonpath, {'a': 'b'})
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
예제 #36
0
def test_persist_default_persists(jsonpath):
    persist(jsonpath, {"a": "b"})
    new = persist(jsonpath)
    assert new["a"] == "b"
예제 #37
0
def test_persist_update(jsonpath):
    mydict = persist(jsonpath, {'a': 'a'})
    mydict.update({'a': 'b'})
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
예제 #38
0
def test_persist_file_format(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'

    expected = '{\n  "a": "b"\n}'
    assert open(jsonpath, 'r').read() == expected
예제 #39
0
def test_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    assert mydict.a == 'b'
예제 #40
0
def test_persist_override_default2(jsonpath):
    mydict = persist(jsonpath, {"a": "a"})
    mydict["a"] = "b"
    new = persist(jsonpath, {"a": "c"})
    assert new["a"] == "b"
예제 #41
0
def test_persist_override_default(jsonpath):
    persist(jsonpath, {"a": "b"})
    new = persist(jsonpath, {"a": "c"})
    assert new["a"] == "b"
예제 #42
0
def test_persist_set_attr_dict(jsonpath):
    mydict = persist(jsonpath)

    mydict.path = jsonpath