source: main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_browser.py @ 12774

Last change on this file since 12774 was 12767, checked in by Henrik Bettermann, 10 years ago

Rename templates folder.

File size: 3.7 KB
Line 
1## $Id: test_browser.py 12762 2015-03-14 13:49:29Z henrik $
2##
3## Copyright (C) 2015 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##
18"""
19Test the payments-related UI components.
20"""
21
22import os
23from decimal import Decimal
24from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
25from waeup.ikoba.payments.payment import Payment
26from waeup.ikoba.payments.interfaces import IPayer, IPayable
27from waeup.ikoba.browser.tests.test_pdf import samples_dir
28from waeup.ikoba.products.productoptions import ProductOption
29from waeup.ikoba.customers.tests.test_browser import CustomersFullSetup
30
31
32class PaymentsUITests(CustomersFullSetup):
33    # Tests for payments related views and pages
34
35    layer = FunctionalLayer
36
37    def setup_payment(self):
38        payer = IPayer(self.customer)
39        payable = IPayable(self.contract)
40        self.payment = Payment(payer, payable)
41        self.payment.gateway_service = 'demo_creditcard'
42        self.app['payments'][self.payment.payment_id] = self.payment
43        self.payments_path = 'http://localhost/app/payments'
44
45    def add_product_option(self, contract):
46        prodoption = ProductOption()
47        prodoption.title = u'Any product option'
48        prodoption.fee = Decimal('88.8')
49        prodoption.currency = 'EUR'
50        contract.product_options = [prodoption, ]
51
52    def test_manage_payments(self):
53
54        self.add_product_option(self.contract)
55        self.setup_payment()
56        # Managers can access the pages of payments section
57        # and can remove payments
58        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
59        self.browser.open('http://localhost/app')
60        self.assertEqual(self.browser.headers['Status'], '200 Ok')
61        self.browser.getLink("Payments").click()
62        self.assertEqual(self.browser.url, self.payments_path)
63        self.browser.getLink("Manage").click()
64        self.assertEqual(self.browser.url, self.payments_path + '/manage')
65        # Payment can be found
66        self.browser.getControl("Find payment(s)").click()
67        self.assertTrue('Empty search string' in self.browser.contents)
68        self.browser.getControl(name="searchtype").value = ['payment_id']
69        self.browser.getControl(name="searchterm").value = self.payment.payment_id
70        self.browser.getControl("Find payment(s)").click()
71        self.assertTrue(
72            '<a href="http://localhost/app/customers/K1000000/contracts/CON1">'
73            in self.browser.contents)
74        # Payments can be removed
75        ctrl = self.browser.getControl(name='entries')
76        ctrl.getControl(value=self.payment.payment_id).selected = True
77        self.browser.getControl("Remove selected", index=0).click()
78        self.assertTrue('Successfully removed' in self.browser.contents)
79        # All actions are being logged
80        logfile = os.path.join(
81            self.app['datacenter'].storage, 'logs', 'payments.log')
82        logcontent = open(logfile).read()
83        self.assertTrue(
84            'INFO - zope.mgr - payments.browser.PaymentsContainerManagePage - removed: %s'
85            % self.payment.payment_id in logcontent)
Note: See TracBrowser for help on using the repository browser.