Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 8468)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 8471)
@@ -1483,7 +1483,7 @@
         self.assertTrue('Successfully removed' in self.browser.contents)
 
-        # The new SFE-0 pin can be used for starting course registration
+        # The new SFE-0 pin can be used for starting new session
         self.browser.open(self.studycourse_path)
-        self.browser.getLink('Start course registration').click()
+        self.browser.getLink('Start session').click()
         pin = self.app['accesscodes']['SFE-0'].keys()[0]
         parts = pin.split('-')[1:]
@@ -1491,8 +1491,97 @@
         self.browser.getControl(name="ac_series").value = sfeseries
         self.browser.getControl(name="ac_number").value = sfenumber
-        self.browser.getControl("Start course registration now").click()
-        self.assertMatches('...Course registration has been started...',
+        self.browser.getControl("Start now").click()
+        self.assertMatches('...Session started...',
                            self.browser.contents)
         self.assertTrue(self.student.state == 'school fee paid')
+        return
+
+    def test_postgraduate_payments(self):
+        self.certificate.study_mode = 'pg_ft'
+        self.certificate.start_level = 999
+        self.certificate.end_level = 999
+        self.student['studycourse'].current_level = 999
+        # Login
+        self.browser.open(self.login_path)
+        self.browser.getControl(name="form.login").value = self.student_id
+        self.browser.getControl(name="form.password").value = 'spwd'
+        self.browser.getControl("Login").click()
+        # Students can add online school fee payment tickets.
+        IWorkflowState(self.student).setState('cleared')
+        self.browser.open(self.payments_path)
+        self.browser.getControl("Add online payment ticket").click()
+        self.browser.getControl(name="form.p_category").value = ['schoolfee']
+        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 session and level are current ones.
+        # Postgrads have to school_fee_1.
+        self.assertEqual(self.student['payments'][value].amount_auth, 40000.0)
+        self.assertEqual(self.student['payments'][value].p_session, 2004)
+        self.assertEqual(self.student['payments'][value].p_level, 999)
+
+        # We simulate the approval
+        self.assertEqual(len(self.app['accesscodes']['SFE-0']),0)
+        self.browser.open(self.browser.url + '/fake_approve')
+        self.assertMatches('...Successful payment...',
+                          self.browser.contents)
+
+        # The new SFE-0 pin can be used for starting session
+        self.browser.open(self.studycourse_path)
+        self.browser.getLink('Start session').click()
+        pin = self.app['accesscodes']['SFE-0'].keys()[0]
+        parts = pin.split('-')[1:]
+        sfeseries, sfenumber = parts
+        self.browser.getControl(name="ac_series").value = sfeseries
+        self.browser.getControl(name="ac_number").value = sfenumber
+        self.browser.getControl("Start now").click()
+        self.assertMatches('...Session started...',
+                           self.browser.contents)
+        self.assertTrue(self.student.state == 'school fee paid')
+
+        # Postgrad students do not need to register courses the
+        # can just pay for the next session.
+        self.browser.open(self.payments_path)
+        # Remove first payment to be sure that we access the right ticket
+        del self.student['payments'][value]
+        self.browser.getControl("Add online payment ticket").click()
+        self.browser.getControl(name="form.p_category").value = ['schoolfee']
+        self.browser.getControl("Create ticket").click()
+        ctrl = self.browser.getControl(name='val_id')
+        value = ctrl.options[0]
+        self.browser.getLink(value).click()
+        # Payment session has increased by one, payment level remains the same.
+        # Returning Postgraduates have to pay school_fee_2.
+        self.assertEqual(self.student['payments'][value].amount_auth, 20000.0)
+        self.assertEqual(self.student['payments'][value].p_session, 2005)
+        self.assertEqual(self.student['payments'][value].p_level, 999)
+
+        # Student is still in old session
+        self.assertEqual(self.student.current_session, 2004)
+
+        # We do not need to pay the ticket if any other
+        # SFE pin is provided
+        pin_container = self.app['accesscodes']
+        pin_container.createBatch(
+            datetime.utcnow(), 'some_userid', 'SFE', 9.99, 1)
+        pin = pin_container['SFE-1'].values()[0].representation
+        sfeseries, sfenumber = pin.split('-')[1:]
+        # The new SFE-1 pin can be used for starting new session
+        self.browser.open(self.studycourse_path)
+        self.browser.getLink('Start session').click()
+        self.browser.getControl(name="ac_series").value = sfeseries
+        self.browser.getControl(name="ac_number").value = sfenumber
+        self.browser.getControl("Start now").click()
+        self.assertMatches('...Session started...',
+                           self.browser.contents)
+        self.assertTrue(self.student.state == 'school fee paid')
+        # Student is in new session
+        self.assertEqual(self.student.current_session, 2005)
+        self.assertEqual(self.student['studycourse'].current_level, 999)
         return
 
