## $Id: test_browser.py 12821 2015-03-24 08:57:25Z uli $ ## ## Copyright (C) 2015 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """ Test the payments-related UI components. """ import os from decimal import Decimal from waeup.ikoba.testing import FunctionalLayer from waeup.ikoba.payments.payment import Payment from waeup.ikoba.payments.interfaces import IPayer, IPayable from waeup.ikoba.products.productoptions import ProductOption from waeup.ikoba.customers.tests.test_browser import CustomersFullSetup class PaymentsUITests(CustomersFullSetup): # Tests for payments related views and pages layer = FunctionalLayer def setup_payment(self): payer = IPayer(self.customer) payable = IPayable(self.contract) self.payment = Payment(payer, payable) self.payment.gateway_service = 'demo_creditcard' self.app['payments'][self.payment.payment_id] = self.payment self.payments_path = 'http://localhost/app/payments' def add_product_option(self, contract): prodoption = ProductOption() prodoption.title = u'Any product option' prodoption.fee = Decimal('88.8') prodoption.currency = 'EUR' contract.product_options = [prodoption, ] def test_overview_payments(self): # we can get a payments overview self.add_product_option(self.contract) self.setup_payment() self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') self.browser.open('http://localhost/app/payments') self.browser.getControl("Find payment(s)").click() self.assertTrue('Empty search string' in self.browser.contents) self.browser.getControl(name="searchtype").value = ['payment_id'] self.browser.getControl( name="searchterm").value = self.payment.payment_id self.browser.getControl("Find payment(s)").click() self.assertTrue(self.payment.title in self.browser.contents) def test_manage_payments(self): # we can manage (at least: remove) payments as a manager self.add_product_option(self.contract) self.setup_payment() self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') self.browser.open('http://localhost/app') self.assertEqual(self.browser.headers['Status'], '200 Ok') self.browser.getLink("Payments").click() self.assertEqual(self.browser.url, self.payments_path) self.browser.getLink("Manage").click() self.assertEqual(self.browser.url, self.payments_path + '/manage') # Payment can be found self.browser.getControl("Find payment(s)").click() self.assertTrue('Empty search string' in self.browser.contents) self.browser.getControl(name="searchtype").value = ['payment_id'] self.browser.getControl( name="searchterm").value = self.payment.payment_id self.browser.getControl("Find payment(s)").click() self.assertTrue(self.payment.title in self.browser.contents) ctrl = self.browser.getControl(name='entries') ctrl.getControl(value=self.payment.payment_id).selected = True self.browser.getControl("Remove selected", index=0).click() self.assertTrue('Successfully removed' in self.browser.contents) # All actions are being logged logfile = os.path.join( self.app['datacenter'].storage, 'logs', 'payments.log') logcontent = open(logfile).read() self.assertTrue( ('INFO - zope.mgr - payments.browser.' 'PaymentsContainerManagePage - removed: %s') % self.payment.payment_id in logcontent)