## $Id: tests.py 7929 2012-03-20 15:21:01Z henrik $
##
## Copyright (C) 2011 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
##
from hurry.workflow.interfaces import IWorkflowState
from waeup.kofa.students.tests.test_browser import StudentsFullSetup
from waeup.custom.testing import FunctionalLayer

class EtranzactTests(StudentsFullSetup):
    """Tests foreTranzact payment gateway.
    """

    layer = FunctionalLayer

    CONFIRMATION_NO = '500856521315472785095'

    def test_etranzact_query_history(self):

        # Managers can add online payment tickets
        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
        self.browser.open(self.payments_student_path)
        IWorkflowState(self.student).setState('cleared')
        self.browser.open(self.payments_student_path + '/addop')
        self.browser.getControl("Create ticket").click()
        self.assertMatches('...ticket created...',
                           self.browser.contents)
        ctrl = self.browser.getControl(name='val_id')
        value = ctrl.options[0]
        self.browser.getLink(value).click()
        self.assertMatches('...Amount Authorized...',
                           self.browser.contents)
        payment_url = self.browser.url
        
        self.browser.open(payment_url + '/query_history?confirmation_number=%s'
            % self.CONFIRMATION_NO)
        self.assertMatches('...Wrong amount...',
                          self.browser.contents)

        self.student['payments'][value].amount_auth = self.student[
            'payments'][value].r_amount_approved
        self.browser.open(payment_url + '/query_history?confirmation_number=%s'
            % self.CONFIRMATION_NO)
        self.assertMatches('...Wrong transaction id...',
                          self.browser.contents)
