source: main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests/test_payment.py @ 12248

Last change on this file since 12248 was 12154, checked in by uli, 10 years ago

Fix test.

File size: 2.7 KB
Line 
1## $Id$
2##
3## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18import datetime
19import re
20import unittest
21from zope.interface.verify import verifyClass, verifyObject
22from waeup.ikoba.payments.interfaces import (
23    IPayment, STATE_UNPAID, STATE_PAID, STATE_FAILED,
24    )
25from waeup.ikoba.payments.payment import Payment
26
27
28class PaymentTests(unittest.TestCase):
29
30    def test_iface(self):
31        # Payments fullfill any interface contracts
32        obj = Payment()
33        verifyClass(IPayment, Payment)
34        verifyObject(IPayment, obj)
35
36    def test_payment_id_unique(self):
37        # we get unique payment ids
38        p1, p2 = Payment(), Payment()
39        id1, id2 = p1.payment_id, p2.payment_id
40        assert id1 != id2
41
42    def test_payment_id_format(self):
43        # payment ids have a special format: "PAY_<32 hex digits>"
44        id1 = Payment().payment_id
45        assert isinstance(id1, basestring)
46        assert re.match('PAY_[0-9a-f]{32}', id1)
47
48    def test_initial_state_is_unpaid(self):
49        # the initial state of payments is <unpaid>
50        p1 = Payment()
51        assert p1.state == STATE_UNPAID
52
53    def test_approve(self):
54        # we can approve payments
55        p1 = Payment()
56        p1.approve()
57        assert p1.state == STATE_PAID
58        assert p1.payment_date is not None
59        assert isinstance(p1.payment_date, datetime.datetime)
60
61    def test_approve_datetime_given(self):
62        # we can give a datetime
63        p1 = Payment()
64        some_datetime = datetime.datetime(2014, 1, 1, 0, 0, 0)
65        p1.approve(payment_date=some_datetime)
66        assert p1.payment_date == some_datetime
67
68    def test_approve_datetime_automatic(self):
69        # if we do not give a datetime, current one will be used
70        current = datetime.datetime.utcnow()
71        p1 = Payment()
72        p1.approve()
73        assert p1.payment_date >= current
74
75    def test_mark_failed(self):
76        # we can mark payments as failed
77        p1 = Payment()
78        p1.mark_failed()
79        assert p1.state == STATE_FAILED
Note: See TracBrowser for help on using the repository browser.