コード例 #1
0
    def run(self, name, backend):

        # Validate the parameters
        form = AddAccountForm(name=name, backend=backend)
        if not form.validate():
            self.err(**form.errors)
            return

        # Ask the user for the backend configuration options
        backend = Backend.get_backend(backend)
        config = {'backend': form.data['backend']}
        for field in backend.config_form():
            self.out((field.label.text, 'blue'))
            value = input('> ').strip()
            if value:
                config[field.name] = value

        # Validate the users configuration
        result = backend.validate_config(**config)
        if not result[0]:
            self.err('Invalid backend config:', **result[1])
            return

        # Create the new account
        account = Account(name=form.data['name'], backend=config)
        account.insert()

        self.out(('Account added: {0}'.format(account.api_key), 'bold_green'))
コード例 #2
0
def test_local_account(app):
    """Create a local account"""

    # Add the local account
    with open('tests/data/local.cfg') as f:
        config = json.load(f)

    account = Account(name='local', backend=config)
    account.insert()

    yield account

    # Purge the account
    account.purge()
コード例 #3
0
def test_backends(app):
    """Create accounts to support each backend"""

    # Add the test accounts for each backend
    accounts = []
    for backend in ['local', 's3']:

        with open('tests/data/{backend}.cfg'.format(backend=backend)) as f:
            config = json.load(f)

        account = Account(name=backend, backend=config)
        account.insert()
        accounts.append(account)

    yield accounts

    # Purge the accounts
    for account in accounts:
        account.purge()
コード例 #4
0
def test_accounts(app):
    """Load test accounts"""

    # Load the test account information
    with open('tests/data/accounts.json') as f:
        data = json.load(f)

    # Add the test accounts
    accounts = []
    for account_data in data:

        with open('tests/data/' + account_data['config_filepath']) as f:
            config = json.load(f)

        account = Account(name=account_data['name'], backend=config)
        account.insert()
        accounts.append(account)

    yield accounts

    # Purge the accounts
    for account in accounts:
        account.purge()