Ignore:
Timestamp:
14 Nov 2011, 11:03:00 (13 years ago)
Author:
Henrik Bettermann
Message:

Add tests (test coverage of viewlets.py now 100%).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7109 r7110  
    362362        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    363363        self.browser.open(self.edit_clearance_student_path)
     364        # No birth certificate has been uploaded yet
     365        # Browsing the link shows a placerholder image
     366        self.browser.open('birth_certificate.jpg')
     367        self.assertEqual(
     368            self.browser.headers['content-type'], 'image/jpeg')
     369        self.assertEqual(len(self.browser.contents), PH_LEN)
    364370        # Create a pseudo image file and select it to be uploaded in form
    365371        # as birth certificate
     372        self.browser.open(self.edit_clearance_student_path)
    366373        pseudo_image = StringIO('I pretend to be a graphics file')
    367374        ctrl = self.browser.getControl(name='birth_certificate')
     
    371378        self.browser.getControl("Save (no upload)").click() # submit form
    372379        self.assertFalse(
    373             '<a target="image" href="birth_certificate.jpg">' in self.browser.contents)
     380            '<a target="image" href="birth_certificate.jpg">'
     381            in self.browser.contents)
    374382        # ... but the Upload submit button does
    375383        pseudo_image = StringIO('I pretend to be a graphics file')
     
    397405        self.assertTrue(
    398406            'Uploaded file is too big' in self.browser.contents)
     407        # File names must meet several conditions
     408        pseudo_image = StringIO('I pretend to be a graphics file')
     409        ctrl = self.browser.getControl(name='birth_certificate')
     410        file_ctrl = ctrl.mech_control
     411        file_ctrl.add_file(pseudo_image, filename='my.photo.jpg')
     412        self.browser.getControl("Upload").click()
     413        self.assertTrue('File name contains more than one dot'
     414            in self.browser.contents)
     415        ctrl = self.browser.getControl(name='birth_certificate')
     416        file_ctrl = ctrl.mech_control
     417        file_ctrl.add_file(pseudo_image, filename='myphoto')
     418        self.browser.getControl("Upload").click()
     419        self.assertTrue('File name has no extension' in self.browser.contents)
     420        ctrl = self.browser.getControl(name='birth_certificate')
     421        file_ctrl = ctrl.mech_control
     422        file_ctrl.add_file(pseudo_image, filename='myphoto.bmp')
     423        self.browser.getControl("Upload").click()
     424        self.assertTrue('.jpg file extension expected' in self.browser.contents)
     425        # Managers can delete files
     426        self.browser.getControl("Delete").click()
     427        self.assertTrue(
     428            'File birth_certificate.jpg deleted'
     429            in self.browser.contents)
    399430
    400431    def test_manage_course_lists(self):
     
    406437        self.browser.getLink("Manage").click()
    407438        self.assertTrue('Manage study course' in self.browser.contents)
    408         # Before we can select a level, the certificate must be selected and saved
     439        # Before we can select a level, the certificate must
     440        # be selected and saved
    409441        self.browser.getControl(name="form.certificate").value = ['CERT1']
    410442        self.browser.getControl(name="form.current_session").value = ['2004']
     
    422454        self.assertMatches('...This level exists...', self.browser.contents)
    423455        self.browser.getControl("Remove selected").click()
    424         self.assertMatches('...No study level selected...', self.browser.contents)
     456        self.assertMatches(
     457            '...No study level selected...', self.browser.contents)
    425458        self.browser.getControl(name="val_id").value = ['100']
    426459        self.browser.getControl("Remove selected").click()
     
    433466        # Managers can view and manage course lists
    434467        self.browser.getLink("100").click()
    435         self.assertMatches('...: Study Level 100 (Year 1)...', self.browser.contents)
     468        self.assertMatches(
     469            '...: Study Level 100 (Year 1)...', self.browser.contents)
    436470        self.browser.getLink("Manage").click()
    437471        self.browser.getControl(name="form.level_session").value = ['2002']
     
    476510        self.browser.getControl(name="transition").value = ['clear']
    477511        self.browser.getControl("Save").click()
    478         self.browser.getControl(name="transition").value = ['pay_first_school_fee']
     512        self.browser.getControl(
     513            name="transition").value = ['pay_first_school_fee']
    479514        self.browser.getControl("Save").click()
    480515        self.browser.getControl(name="transition").value = ['reset6']
Note: See TracChangeset for help on using the changeset viewer.