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

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

Add payment exporter.

  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1## $Id: test_browser.py 12777 2015-03-16 16:33:56Z 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
25from waeup.ikoba.payments.payment import Payment
26from waeup.ikoba.payments.interfaces import IPayer, IPayable
27from waeup.ikoba.products.productoptions import ProductOption
28from waeup.ikoba.customers.tests.test_browser import CustomersFullSetup
29
30
31class PaymentsUITests(CustomersFullSetup):
32    # Tests for payments related views and pages
33
34    layer = FunctionalLayer
35
36    def setup_payment(self):
37        payer = IPayer(self.customer)
38        payable = IPayable(self.contract)
39        self.payment = Payment(payer, payable)
40        self.payment.gateway_service = 'demo_creditcard'
41        self.app['payments'][self.payment.payment_id] = self.payment
42        self.payments_path = 'http://localhost/app/payments'
43
44    def add_product_option(self, contract):
45        prodoption = ProductOption()
46        prodoption.title = u'Any product option'
47        prodoption.fee = Decimal('88.8')
48        prodoption.currency = 'EUR'
49        contract.product_options = [prodoption, ]
50
51    def test_manage_payments(self):
52
53        self.add_product_option(self.contract)
54        self.setup_payment()
55        # Managers can access the pages of payments section
56        # and can remove payments
57        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
58        self.browser.open('http://localhost/app')
59        self.assertEqual(self.browser.headers['Status'], '200 Ok')
60        self.browser.getLink("Payments").click()
61        self.assertEqual(self.browser.url, self.payments_path)
62        self.browser.getLink("Manage").click()
63        self.assertEqual(self.browser.url, self.payments_path + '/manage')
64        # Payment can be found
65        self.browser.getControl("Find payment(s)").click()
66        self.assertTrue('Empty search string' in self.browser.contents)
67        self.browser.getControl(name="searchtype").value = ['payment_id']
68        self.browser.getControl(
69            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.'
85             'PaymentsContainerManagePage - removed: %s')
86            % self.payment.payment_id in logcontent)
Note: See TracBrowser for help on using the repository browser.