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

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

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

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

    mydict.path = jsonpath