Ignore:
Timestamp:
31 Mar 2011, 10:10:11 (14 years ago)
Author:
uli
Message:

Add tests for applicant login in functional site.

File:
1 edited

Legend:

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

    r5895 r5906  
    2626import tempfile
    2727import unittest
     28from datetime import datetime
    2829from zope.app.testing.functional import FunctionalTestCase
    2930from zope.app.testing.functional import HTTPCaller as http
     
    3738class LoginTest(FunctionalTestCase):
    3839    # Here we check login view of applicants containers.
     40    #
     41    # Tests in here do only cover login attempts without any PINs
     42    # created before.
    3943   
    4044    layer = FunctionalLayer
     
    119123        self.assertTrue('666' in self.browser.contents)
    120124        return
     125
     126class LoginTestWithPINs(LoginTest):
     127    # Here we check login view of applicants containers with PINs provided.
     128
     129    # As setting up pins is time-consuming we only set them up when
     130    # really needed (i.e. in this separate TestCase).
     131   
     132    layer = FunctionalLayer
     133
     134    def setUp(self):
     135        super(LoginTestWithPINs, self).setUp()
     136
     137        # Create 5 access codes with prefix 'FOO' and cost 9.99 each
     138        pin_container = self.getRootFolder()['app']['accesscodes']
     139        pin_container.createBatch(
     140            datetime.now(), 'some_userid', 'APP', 9.99, 5)
     141        pins = pin_container[pin_container.keys()[0]].entries()
     142        self.pins = [x.representation for x in pins]
     143        self.existing_pin = self.pins[0]
     144        parts = self.existing_pin.split('-')[1:]
     145        self.existing_series, self.existing_number = parts
     146        self.browser.handleErrors = False
    121147       
     148    def tearDown(self):
     149        super(LoginTestWithPINs, self).tearDown()
     150
     151    def test_anonymous_valid_login(self):
     152        self.browser.open(self.login_path)
     153        # Enter some value we can look for after submit
     154        ac_series = self.browser.getControl(name="form.ac_series")
     155        ac_series.value = self.existing_series
     156        ac_number = self.browser.getControl(name="form.ac_number")
     157        ac_number.value = self.existing_number
     158        self.browser.getControl(name="SUBMIT").click()
     159        self.assertEqual(self.browser.contents, 12)
     160        self.assertTrue(self.browser.url != self.login_path)
     161       
     162        return
     163
     164   
    122165def suite():
    123166    suite = unittest.TestSuite()
    124167    for testcase in [
    125168        LoginTest,
     169        LoginTestWithPINs,
    126170            ]:
    127171        suite.addTests(unittest.makeSuite(testcase))
Note: See TracChangeset for help on using the changeset viewer.