Exemple #1
0
def test_update():
    """
    """
    account = {
        'account_name': 'update',
        'start_on': '2021-05-03 00:00:00',
        'end_on': '2031-12-31 00:00:00',
    }
    Account.create(account, 999)
    account_created1 = Account.search('update', 999)
    print(account_created1)

    search_cond = {
        'account_name': 'update',
        'start_on': '2021-05-03 00:00:00',
        'end_on': '2031-12-31 00:00:00',
    }
    account_created = Account.search('update', 999)[0].toDict()
    assert account_created['account_name'] == 'update'
    assert account_created['start_on'] == '2021-05-03 00:00:00'
    assert account_created['end_on'] == '2031-12-31 00:00:00'

    account = {'id': account_updated['id'], 'end_ion': '2035-12-31 12:00:00'}
    assert Account.update(account, 999) == True
    search_cond = {'account_name': 'update', 'end_on': '2035-12-31 12:00:00'}
    account_updated = Account.search(search_cond, 999)[0].toDict()
    assert account_updated['account_name'] == 'update'
    assert account_updated['start_on'] == '2021-05-03 00:00:00'
    assert account_updated['end_on'] == '2035-12-31 00:00:00'
Exemple #2
0
def test_create():
    """
    """
    account = {
        'account_name': 'flask sv',
        'start_on': '2021-05-05 00:00:00',
        'end_on': '2030-12-31 00:00:00',
    }

    Account.create(account, 999)
Exemple #3
0
    def add(self):
        Account.create(name=self._view.name, address=self._view.address,
                       password=self._view.password,
                       imap_host=self._view.imap_host,
                       imap_port=self._view.imap_port,
                       imap_ssl=self._view.imap_ssl,
                       smtp_host=self._view.smtp_host,
                       smtp_port=self._view.smtp_port,
                       smtp_ssl=self._view.smtp_ssl)
        
        self._view.accept()

        if self._main_controller:
            self._main_controller.update_accounts()
Exemple #4
0
def createAccount():
    form = forms.AccountCreationForm()
    if form.validate_on_submit():
        account = Account.create(form.firstname.data, form.lastname.data, form.promo.data, form.number.data)

        if form.balance.data is not None and form.balance.data != 0:
            Transaction.add(account.id, form.balance.data)

        return account.serialize()
    else:
        raise MissingFieldsError(form.errors.keys())
Exemple #5
0
    def get_or_create_account(self, currency, user_id):
        from model import Account

        account = self.get_account(currency)
        if account:
            return account

        account = Account.create(currency, self, user_id)
        self.accounts.append(account)
        db.session.flush()
        return account
Exemple #6
0
    def new_customer(cls, email, password, creator_id, detailed_info=None, comment="New customer",
                     withdraw_period=None, make_prod=False, customer_type=None, promo_code=None, locale=None):
        from model import Tariff, Account, CustomerHistory

        customer = cls()
        customer.email = email
        customer.password = cls.password_hashing(password) if password else ""
        customer.deleted = None
        customer.created = utcnow().datetime
        customer.email_confirmed = False
        customer.blocked = False
        customer.customer_mode = cls.CUSTOMER_PRODUCTION_MODE if make_prod else cls.CUSTOMER_TEST_MODE
        customer.customer_type = customer_type if customer_type else cls.CUSTOMER_TYPE_PRIVATE_PERSON
        customer.withdraw_period = withdraw_period or conf.customer.default_withdraw_period
        customer.auto_withdraw_enabled = conf.payments.auto_withdraw_enable
        customer.auto_withdraw_balance_limit = conf.payments.auto_withdraw_balance_limit
        customer.auto_withdraw_amount = conf.payments.auto_withdraw_amount
        customer.locale = locale or conf.customer.default_locale
        customer.os_dashboard = conf.customer.default_openstack_dashboard

        default_tariff = Tariff.get_default().first()
        if not default_tariff:
            default_tariff = Tariff.query.filter_by(mutable=False).first() or Tariff.query.filter_by().first()
            if not default_tariff:
                raise errors.TariffNotFound()
        customer.tariff_id = default_tariff.tariff_id
        customer.balance_limit = conf.customer.balance_limits.get(default_tariff.currency,
                                                                  conf.customer.balance_limits.default)
        db.session.add(customer)
        db.session.flush()

        customer.init_subscriptions()
        template = 'customer' if make_prod else 'test_customer'
        customer.quota_init(template)
        customer.accounts.append(Account.create(default_tariff.currency, customer, creator_id, comment))

        if promo_code is not None:
            PromoCode.new_code(promo_code, customer.customer_id)

        CustomerHistory.new_customer(customer, creator_id, comment)
        if detailed_info:
            customer.create_info(customer.customer_type, detailed_info)
        auto_report_task = ScheduledTask(cls.AUTO_REPORT_TASK, customer.customer_id, customer.withdraw_period)
        db.session.add(auto_report_task)

        logbook.info("New customer created: {}", customer)
        if not make_prod:
            currency = customer.tariff.currency.upper()
            initial_balance = conf.customer.test_customer.balance.get(currency)
            logbook.debug("Initial balance for customer {}: {} {}", customer, initial_balance, currency)
            if initial_balance:
                customer.modify_balance(Decimal(initial_balance), currency, None, "Initial test balance")

        return customer
Exemple #7
0
 def create_account(self):
     account = Account.create()
     self.session['account_id'] = account.key.id()
     return account