Пример #1
0
 def test_grace(self):
     acc = Account()
     assert not acc.graced
     acc.grace(why="just because", untilWhen=duckbill.TODAY+7)
     assert acc.graced
     acc.gracePeriods[0].expires = duckbill.TODAY
     assert not acc.graced
Пример #2
0
    def test_findUsersForAccount(self):

        a = Account()
        u1 = self.clerk.store(User(account=a))
        u2 = self.clerk.store(User(account=Account()))
        u3 = self.clerk.store(User(account=a))

        users = self.bwg.findUsersForAccount(a)
        assert users == [u1, u3]
Пример #3
0
    def test_findDueAccounts(self):

        # one due today, one tomorrow, one today but versionhost
        a = self.clerk.store(Account(account='a', nextDue=TODAY))
        b = self.clerk.store(Account(account='b', nextDue=TODAY + 1))
        c = self.clerk.store(
            Account(account='c', nextDue=TODAY, brand="versionhost"))

        due = self.bwg.findDueAccounts()
        assert due == [a]
Пример #4
0
    def oldAccount(self):
        acc = Account()
        acc.events << Event(event="charge", amount=10, posted="1/1/2002")
        acc.events << Event(event="charge", amount=10, posted="2/1/2002")
        acc.events << Event(event="credit", amount=5,  posted="2/2/2002")

        acc.events << Event(event="charge", amount=10, posted="3/1/2002")
        acc.events << Event(event="charge", amount=10, posted="4/1/2002")
        acc.events << Event(event="credit", amount=20, posted="4/2/2002")
        acc.events << Event(event="charge", amount=10, posted="5/1/2002")

        assert acc.balance() == 25
        return acc
Пример #5
0
    def test_chargeAccounts(self):

        plan = Plan(bandquota=GIGA)
        u1 = User(plan=plan, account=Account(), username="******")
        u1.usage << Usage(whichday=TODAY - 1, traffic=1 * GIGA)
        u1.usage << Usage(whichday=TODAY - 2, traffic=1 * GIGA)
        u1 = self.clerk.store(u1)
        self.bwg.chargeAccounts(TODAY)
        self.assertEquals(self.rate, u1.account.balance())
        assert u1.account.events[0].note == "bandwidth overage [ftempy]"

        u2 = self.clerk.store(User(plan=plan, account=Account()))
        self.bwg.chargeAccounts(TODAY)
        assert u2.account.balance() == 0
        assert len(u2.account.events) == 0  # don't want $0.00 charges
Пример #6
0
    def test_close(self):
        acc = Account()
        sub = Subscription()
        old = Subscription(status="closed", closed="1/1/2004")
        acc.subscriptions << old
        acc.subscriptions << sub
        assert acc.closed is None
        assert sub.closed is None
        acc.close("closed for nonpayment")
        assert acc.status == "closed"
        assert sub.status == "closed"
        assert acc.closed == duckbill.TODAY
        assert sub.closed == duckbill.TODAY
        assert old.closed == "1/1/2004"

        evt = acc.events[-1]
        assert evt.event == "close"
        assert evt.note == "closed for nonpayment"
Пример #7
0
 def test_cardinfo(self):
     acc = Account()        
     assert str(acc.cardinfo) == ""
     acc.cardinfo.owner="fred tempy"
     self.assertRaises(Exception, str, acc.cardinfo)
     acc.cardinfo.number = "1234"
     acc.cardinfo.expire = "today"
     import duckbill.config
     duckbill.config.GNUPG_RECIPIENT="*****@*****.**"
     assert str(acc.cardinfo).count("BEGIN PGP")
Пример #8
0
 def test_onDue(self):
     """
     onDue should post a charge and update nextDue.
     """
     self.sub = fakeSubscription()
     a = Account()
     self.sub.account = a
     self.sub.service = "service"
     self.sub.username = "******"
     self.sub.nextDue = CUSTOMER_SIGNUP_DATE
     assert len(a.events) == 0
     self.sub.catchup()
     assert len(a.events) == 1
     assert a.events[0].posted == CUSTOMER_SIGNUP_DATE
     assert a.events[0].maturity == SECOND_STATEMENT_DATE
     assert a.events[0].note == "1-month service [username]"
     assert self.sub.nextDue == SECOND_STATEMENT_DATE, self.sub.nextDue
Пример #9
0
    def test_BadPastDue(self):
        """
        This was a bug I noticed in the receivables page.
        """
        acc = Account()

        acc.events << Event(event="charge", amount=20, posted="09/15/2002")
        acc.events << Event(event="charge", amount= 4, posted="09/16/2002")
        acc.events << Event(event="payment", amount=20,posted="09/19/2002")
        
        assert acc.balance() == 4, acc.balance()
        self.assertEquals(acc.amountPastDue("09/20/2002"), 4)
        aging = acc.aging()
        assert len(aging)==1
        assert aging[0].value == 4
Пример #10
0
    def toDuckbill(self):
        """
        Returns a duckbill Account with the appropriate
        Subscriptions and Events. 
        """
        a = Account(fname=self.fname,
                    lname=self.lname,
                    email=self.email,
                    company=self.company,
                    phone=self.phone,
                    address1=self.addr1,
                    address2=self.addr2,
                    city=self.city,
                    state=self.state,
                    postal=self.postal,
                    countryCD=self.country,
                    account=self.username,
                    nextDue=Date("today") + 30,
                    brand=self.brand)

        s = Subscription(
            username=self.username,
            service=self.plan,
            rate=self.calcRate(),
            cycLen=self.cycLen,

            # thirty day free trial
            nextDue=Date("today") + 30)

        e = Event(event="note",
                  posted=Date("today"),
                  amount=0,
                  note="30 day free trial")

        a.subscriptions << s
        a.events << e

        return a
Пример #11
0
def unearned(events, cutoff=Date("today")):
    a = Account()
    for e in events:
        a.events << e
    return a.unearnedIncome(cutoff)
Пример #12
0
 def setUp(self):
     self.acc = Account()
Пример #13
0
 def test_account(self):
     u = User()
     u.account = Account()