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

Last change on this file since 14395 was 12821, checked in by uli, 10 years ago

Add payment overview test, expect payment.title in payment pages.

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1## $Id: test_browser.py 12821 2015-03-24 08:57:25Z uli $
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_overview_payments(self):
52        # we can get a payments overview
53        self.add_product_option(self.contract)
54        self.setup_payment()
55        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
56        self.browser.open('http://localhost/app/payments')
57        self.browser.getControl("Find payment(s)").click()
58        self.assertTrue('Empty search string' in self.browser.contents)
59        self.browser.getControl(name="searchtype").value = ['payment_id']
60        self.browser.getControl(
61            name="searchterm").value = self.payment.payment_id
62        self.browser.getControl("Find payment(s)").click()
63        self.assertTrue(self.payment.title in self.browser.contents)
64
65    def test_manage_payments(self):
66        # we can manage (at least: remove) payments as a manager
67        self.add_product_option(self.contract)
68        self.setup_payment()
69        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
70        self.browser.open('http://localhost/app')
71        self.assertEqual(self.browser.headers['Status'], '200 Ok')
72        self.browser.getLink("Payments").click()
73        self.assertEqual(self.browser.url, self.payments_path)
74        self.browser.getLink("Manage").click()
75        self.assertEqual(self.browser.url, self.payments_path + '/manage')
76        # Payment can be found
77        self.browser.getControl("Find payment(s)").click()
78        self.assertTrue('Empty search string' in self.browser.contents)
79        self.browser.getControl(name="searchtype").value = ['payment_id']
80        self.browser.getControl(
81            name="searchterm").value = self.payment.payment_id
82        self.browser.getControl("Find payment(s)").click()
83        self.assertTrue(self.payment.title in self.browser.contents)
84        ctrl = self.browser.getControl(name='entries')
85        ctrl.getControl(value=self.payment.payment_id).selected = True
86        self.browser.getControl("Remove selected", index=0).click()
87        self.assertTrue('Successfully removed' in self.browser.contents)
88        # All actions are being logged
89        logfile = os.path.join(
90            self.app['datacenter'].storage, 'logs', 'payments.log')
91        logcontent = open(logfile).read()
92        self.assertTrue(
93            ('INFO - zope.mgr - payments.browser.'
94             'PaymentsContainerManagePage - removed: %s')
95            % self.payment.payment_id in logcontent)
Note: See TracBrowser for help on using the repository browser.