Esempio n. 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"
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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
Esempio n. 6
0
def test_persist_default_persists(jsonpath):
    persist(jsonpath, {'a': 'b'})
    new = persist(jsonpath)
    assert new['a'] == 'b'
Esempio n. 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'
Esempio n. 8
0
def test_persist_get_attr_dict(jsonpath):
    mydict = persist(jsonpath)

    assert mydict.path == jsonpath
    assert mydict.__getattr__('path') == jsonpath
Esempio n. 9
0
def test_persist_is_dict(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    assert mydict['a'] == 'b'
Esempio n. 10
0
def test_persist_setdefault(jsonpath):
    mydict = persist(jsonpath)
    mydict.setdefault("a", "b")
    new = persist(jsonpath, {"a": "c"})
    assert new["a"] == "b"
Esempio n. 11
0
def test_persist_default_persists(jsonpath):
    persist(jsonpath, {'a': 'b'})
    new = persist(jsonpath)
    assert new['a'] == 'b'
Esempio n. 12
0
def test_persist_persist_setattr(jsonpath):
    mydict = persist(jsonpath)
    mydict.a = 'b'
    new = persist(jsonpath)
    assert new['a'] == 'b'
Esempio n. 13
0
def test_persist_is_dict(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    assert mydict['a'] == 'b'
Esempio n. 14
0
def test_persist_setdefault(jsonpath):
    mydict = persist(jsonpath)
    mydict.setdefault('a', 'b')
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
Esempio n. 15
0
def test_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    assert mydict.a == 'b'
Esempio n. 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'
Esempio n. 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'
Esempio n. 18
0
def test_persist_override_default(jsonpath):
    persist(jsonpath, {'a': 'b'})
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
Esempio n. 19
0
def test_persist_setdefault(jsonpath):
    mydict = persist(jsonpath)
    mydict.setdefault('a', 'b')
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
Esempio n. 20
0
def test_persist_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    new = persist(jsonpath)
    assert new.a == 'b'
Esempio n. 21
0
def test_persist_persist_setattr(jsonpath):
    mydict = persist(jsonpath)
    mydict.a = 'b'
    new = persist(jsonpath)
    assert new['a'] == 'b'
Esempio n. 22
0
def test_persist_persist_setattr(jsonpath):
    mydict = persist(jsonpath)
    mydict.a = "b"
    new = persist(jsonpath)
    assert new["a"] == "b"
Esempio n. 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"
Esempio n. 24
0
def test_persist_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    new = persist(jsonpath)
    assert new.a == 'b'
Esempio n. 25
0
def test_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict["a"] = "b"
    assert mydict.a == "b"
Esempio n. 26
0
def test_persist_default(jsonpath):
    mydict = persist(jsonpath, {'a': 'b'})
    assert mydict['a'] == 'b'
Esempio n. 27
0
def test_persist_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict["a"] = "b"
    new = persist(jsonpath)
    assert new.a == "b"
Esempio n. 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
Esempio n. 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
Esempio n. 30
0
def test_persist_get_attr_dict(jsonpath):
    mydict = persist(jsonpath)

    assert mydict.path == jsonpath
    assert mydict.__getattr__('path') == jsonpath
Esempio n. 31
0
def test_persist_set_attr_dict(jsonpath):
    mydict = persist(jsonpath)

    mydict.path = jsonpath
Esempio n. 32
0
def test_persist_is_dict(jsonpath):
    mydict = persist(jsonpath)
    mydict["a"] = "b"
    assert mydict["a"] == "b"
Esempio n. 33
0
def test_persist_default(jsonpath):
    mydict = persist(jsonpath, {'a': 'b'})
    assert mydict['a'] == 'b'
Esempio n. 34
0
def test_persist_default(jsonpath):
    mydict = persist(jsonpath, {"a": "b"})
    assert mydict["a"] == "b"
Esempio n. 35
0
def test_persist_override_default(jsonpath):
    persist(jsonpath, {'a': 'b'})
    new = persist(jsonpath, {'a': 'c'})
    assert new['a'] == 'b'
Esempio n. 36
0
def test_persist_default_persists(jsonpath):
    persist(jsonpath, {"a": "b"})
    new = persist(jsonpath)
    assert new["a"] == "b"
Esempio n. 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'
Esempio n. 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
Esempio n. 39
0
def test_persist_getattr(jsonpath):
    mydict = persist(jsonpath)
    mydict['a'] = 'b'
    assert mydict.a == 'b'
Esempio n. 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"
Esempio n. 41
0
def test_persist_override_default(jsonpath):
    persist(jsonpath, {"a": "b"})
    new = persist(jsonpath, {"a": "c"})
    assert new["a"] == "b"
Esempio n. 42
0
def test_persist_set_attr_dict(jsonpath):
    mydict = persist(jsonpath)

    mydict.path = jsonpath