Exemplo n.º 1
0
def test_save_and_load_file():
    c1 = Config.from_dict(TEST_DICT)
    c1.save_to_file("/tmp/test.config")
    c2 = Config.from_file("/tmp/test.config")
    assert c1 == c2
    assert c2.key == "testAPIkey"
    assert c2.url == "https://myconservator.com"
    assert c2.max_retries == 2
Exemplo n.º 2
0
def edit_(name):
    config = Config.from_name(name)
    config_json = json.dumps(config.to_dict(), indent=2)
    value = click.edit(config_json)
    if value is not None:
        new_json = json.loads(value)
        new_config = Config.from_dict(new_json)
        new_config.save_to_named_config(name)
        click.echo(f"Edited {name}")
        return
    click.echo(f"No changes.")
Exemplo n.º 3
0
def conservator(empty_db):
    """
    Provides a Conservator connection to be used for testing.

    The Conservator's database will be empty except for users and organizations. This
    instance will have admin permissions, integration suites do not (currently) test
    permissions. It's assumed we can do anything.
    """
    # TODO: Initialize an organization, groups.
    organization = empty_db.organizations.find_one({})
    assert organization is not None, "Make sure conservator is initialized"
    if "TEST_API_KEY" in os.environ:
        api_key = os.environ["TEST_API_KEY"]
    else:
        api_key = secrets.token_urlsafe(16)
    if "TEST_ADMIN_EMAIL" in os.environ:
        admin_email = os.environ["TEST_ADMIN_EMAIL"]
    else:
        admin_email = "*****@*****.**"

    empty_db.users.insert_one({
        "_id": Conservator.generate_id(),
        "role": ADMIN_ROLE,
        "name": "admin user",
        "email": admin_email,
        "apiKey": api_key,
        "organizationId": organization["_id"],
    })
    config = Config(CONSERVATOR_API_KEY=api_key,
                    CONSERVATOR_URL=test_settings.conservator_url)
    print(
        f"Using key={api_key[0]}***{api_key[-1]}, email={admin_email} url={test_settings.conservator_url}"
    )
    yield Conservator(config)
Exemplo n.º 4
0
def test_defaults():
    c = Config.from_dict({
        "CONSERVATOR_API_KEY": "testAPIkey",
    })

    assert c.key == "testAPIkey"
    assert c.url == "https://flirconservator.com/"
    assert c.max_retries == 5
Exemplo n.º 5
0
 def create(config_name=None, save=True):
     """
     Returns a :class:`Conservator` using named config if given, and otherwise
     creates a default instance via `Conservator.default()`.
     """
     conservator = None
     if config_name:
         try:
             conservator = Conservator(Config.from_name(config_name))
         except AttributeError:
             raise RuntimeError(
                 f"Unknown/Invalid Conservator config '{config_name}'"
             ) from None
     else:
         conservator = Conservator.default(save=save)
     return conservator
Exemplo n.º 6
0
def create(name):
    config = Config.from_input()
    config.save_to_named_config(name)
Exemplo n.º 7
0
def set_default(name):
    config = Config.from_name(name)
    config.save_to_default_config()
    click.echo("Saved.")
Exemplo n.º 8
0
def list_():
    for name in Config.saved_config_names():
        click.echo(name)
Exemplo n.º 9
0
def view(name):
    config = Config.from_name(name)
    conservator = Conservator(config)
    click.echo(config)
    click.echo(f"Corresponds to email: {conservator.get_email()}")
Exemplo n.º 10
0
def delete(name):
    if click.confirm(
            "Are you sure? You can use conservator config edit to change individual values."
    ):
        Config.delete_saved_named_config(name)
Exemplo n.º 11
0
 def default(save=True):
     """
     Returns a :class:`Conservator` using :meth:`Config.default() <FLIR.conservator.config.Config.default>`.
     """
     return Conservator(Config.default(save=save))
Exemplo n.º 12
0
def test_from_dict():
    c = Config.from_dict(TEST_DICT)

    assert c.key == "testAPIkey"
    assert c.url == "https://myconservator.com"
    assert c.max_retries == 2