[12777] | 1 | ## $Id: test_browser.py 12821 2015-03-24 08:57:25Z uli $ |
---|
[12775] | 2 | ## |
---|
[12766] | 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. |
---|
[12775] | 8 | ## |
---|
[12766] | 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. |
---|
[12775] | 13 | ## |
---|
[12766] | 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 | """ |
---|
| 19 | Test the payments-related UI components. |
---|
| 20 | """ |
---|
| 21 | |
---|
| 22 | import os |
---|
| 23 | from decimal import Decimal |
---|
[12775] | 24 | from waeup.ikoba.testing import FunctionalLayer |
---|
[12766] | 25 | from waeup.ikoba.payments.payment import Payment |
---|
| 26 | from waeup.ikoba.payments.interfaces import IPayer, IPayable |
---|
| 27 | from waeup.ikoba.products.productoptions import ProductOption |
---|
| 28 | from waeup.ikoba.customers.tests.test_browser import CustomersFullSetup |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | class 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 | |
---|
[12821] | 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 | |
---|
[12766] | 65 | def test_manage_payments(self): |
---|
[12821] | 66 | # we can manage (at least: remove) payments as a manager |
---|
[12766] | 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'] |
---|
[12775] | 80 | self.browser.getControl( |
---|
| 81 | name="searchterm").value = self.payment.payment_id |
---|
[12766] | 82 | self.browser.getControl("Find payment(s)").click() |
---|
[12821] | 83 | self.assertTrue(self.payment.title in self.browser.contents) |
---|
[12766] | 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( |
---|
[12775] | 93 | ('INFO - zope.mgr - payments.browser.' |
---|
| 94 | 'PaymentsContainerManagePage - removed: %s') |
---|
[12766] | 95 | % self.payment.payment_id in logcontent) |
---|