Index: main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py	(revision 16058)
+++ main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py	(revision 16059)
@@ -1661,4 +1661,5 @@
         mandate.params['name'] = u'John Referee'
         mandate.params['email'] = 'aa@aa.aa'
+        mandate.params['applicant_id'] = self.applicant.applicant_id
         mandate.params[
             'redirect_path'] = '/applicants/%s/%s/addrefereereport' % (
@@ -1692,4 +1693,5 @@
             in self.browser.contents)
         self.assertEqual(self.browser.url, 'http://localhost/app')
+        return
 
     def test_add_and_view_reports(self):
@@ -1697,7 +1699,8 @@
         mandate.params['name'] = u'John Referee'
         mandate.params['email'] = 'aa@aa.aa'
-        mandate.params[
-            'redirect_path'] = '/applicants/%s/%s/addrefereereport' % (
+        mandate.params['applicant_id'] = self.applicant.applicant_id
+        mandate.params['redirect_path'] = '/applicants/%s/%s/addrefereereport' % (
                 container_name_1, self.applicant.application_number)
+        mandate.params['redirect_path2'] = ''
         self.app['mandates'].addMandate(mandate)
         self.assertEqual(len(self.app['mandates'].keys()), 1)
@@ -1712,9 +1715,20 @@
         self.browser.getControl(name="form.email").value = 'bb@bb.bb'
         self.browser.getControl("Submit").click()
-        self.assertTrue('Referee report has been saved' in self.browser.contents)
-        self.assertEqual(self.browser.url, 'http://localhost/app')
+        # Referee wil be redirected to a pdf file
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertEqual(self.browser.headers['Content-Type'],
+                         'application/pdf')
+        path = os.path.join(samples_dir(), 'referee_report.pdf')
+        open(path, 'wb').write(self.browser.contents)
+        print "Sample PDF referee_report.pdf written to %s" % path
         # Report has been created
         self.assertEqual(len(self.applicant.refereereports), 1)
         report = self.applicant.refereereports[0]
+        # Referee can use mandate again to download the pdf report
+        self.browser.open('http://localhost/app/mandate?mandate_id=%s'
+            % mandate.mandate_id)
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertEqual(self.browser.headers['Content-Type'],
+                         'application/pdf')
         # Managers can view the report
         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
@@ -1725,5 +1739,5 @@
         self.assertTrue('John Referee' in self.browser.contents)
         # Managers can download a pdf slip
-        self.browser.getLink("Download report").click()
+        self.browser.getLink("Download referee report").click()
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
         self.assertEqual(self.browser.headers['Content-Type'],
@@ -1732,5 +1746,23 @@
         open(path, 'wb').write(self.browser.contents)
         print "Sample PDF referee_report_slip.pdf written to %s" % path
-        # Report creation is logged
+        # Mandate is not deleted ...
+        self.assertEqual(len(self.app['mandates'].keys()), 1)
+        # ... but redirect_path2 attribute has been set
+        redirect_path2 = '/applicants/%s/%s/%s/referee_report.pdf' % (
+                container_name_1,
+                self.applicant.application_number,
+                report.r_id)
+        self.assertEqual(
+            self.app['mandates'].values()[0].params['redirect_path2'],
+            redirect_path2)
+        # Managers can delete referee reports
+        self.browser.open(self.manage_path)
+        self.browser.getLink("%s" % report.r_id).click()
+        self.assertEqual(len(self.applicant.refereereports), 1)
+        self.browser.getLink("Delete").click()
+        self.assertEqual(len(self.applicant.refereereports), 0)
+        self.assertTrue('Referee report removed.' in self.browser.contents)
+        self.assertEqual(self.browser.url, self.view_path)
+        # Report creation and deletion is logged
         logfile = os.path.join(
             self.app['datacenter'].storage, 'logs', 'applicants.log')
@@ -1739,8 +1771,10 @@
             'zope.anybody - applicants.browser.RefereeReportAddFormPage - '
             '%s - added: %s\n' % (self.applicant.applicant_id, report.r_id)
-            in logcontent
-            )
-        # Mandate is deleted
-        self.assertEqual(len(self.app['mandates'].keys()), 0)
+            in logcontent)
+        self.assertTrue(
+            'zope.mgr - applicants.browser.RemoveRefereeReportPage - '
+            '%s - removed: %s\n' % (self.applicant.applicant_id, report.r_id)
+            in logcontent)
+        return
 
     def test_final_submit_with_referees(self):
