Exemple #1
0
def has_available_transactions(account):
    """Returns True if the account has not exceeded the number of payed
    transactions allowed this month"""
    statistics = get_or_create_transaction_statistic(account)
    transactions_allowed = account.subscription.get_feature(
        'transactions_per_month')
    return transactions_allowed is None or statistics.amount < transactions_allowed
Exemple #2
0
def account_statistics(client_id=None, account_id=None):
    """Returns general account statistics"""
    account = lookup_account_by_name(account_id)
    if client_id is not None:
        require_account_owner(client_id, account)

    transaction_stats = get_or_create_transaction_statistic(account)
    transactions_allowed = account.subscription.get_feature(
        'transactions_per_month') or -1
    return dict(total_sold=total_tickets(account),
                transactions_this_month=transaction_stats.amount,
                transactions_allowed=transactions_allowed)
Exemple #3
0
 def test_more_than_all_transactions_used_up_require(self):
     stat = get_or_create_transaction_statistic(self.account)
     stat.amount = FreeSubscriptionPlan.transactions_per_month + 1
     self.assertRaises(ex.SubscriptionError, require_available_transactions, self.account)    
Exemple #4
0
 def test_available_transactions_left_require(self):
     stat = get_or_create_transaction_statistic(self.account)
     stat.amount = FreeSubscriptionPlan.transactions_per_month - 1
     self.assertIsNone(require_available_transactions(self.account))
Exemple #5
0
 def test_more_than_all_transactions_used_up(self):
     stat = get_or_create_transaction_statistic(self.account)
     stat.amount = FreeSubscriptionPlan.transactions_per_month + 1
     self.assertFalse(has_available_transactions(self.account))            
Exemple #6
0
 def test_available_transactions_left(self):
     stat = get_or_create_transaction_statistic(self.account)
     stat.amount = FreeSubscriptionPlan.transactions_per_month - 1
     self.assertTrue(has_available_transactions(self.account))
Exemple #7
0
 def test_add_free_tickets_when_no_transaction_available(self):
     order = start_order(self.user, self.account)
     get_or_create_transaction_statistic(self.account).amount = 500
     add_tickets(order, self.free_tickettype.id, 5)
Exemple #8
0
 def test_add_tickets_when_no_transactions_available(self):
     order = start_order(self.user, self.account)
     get_or_create_transaction_statistic(self.account).amount = 500
     self.assertRaises(ex.SubscriptionError, add_tickets, order,
                       self.tickettype.id, 5)
Exemple #9
0
 def test_increment_account(self):
     increment_transaction_count(self.account, 5)
     stats = get_or_create_transaction_statistic(self.account)
     self.assertEqual(stats.amount, 5)
Exemple #10
0
 def test_duplicate_creation(self):
     stat1 = get_or_create_transaction_statistic(self.account)
     stat2 = get_or_create_transaction_statistic(self.account)
     self.assertEqual(stat1, stat2)
Exemple #11
0
 def test_create_transaction_statistic(self):
     stat = get_or_create_transaction_statistic(self.account)
     self.assertEqual(stat.year, datetime.date.today().year)
     self.assertEqual(stat.month, datetime.date.today().month)