Ignore:
Timestamp:
17 Nov 2014, 06:29:21 (10 years ago)
Author:
Henrik Bettermann
Message:

Add more tests and solve problems which are unveiled thy these tests.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/pages.py

    r11975 r11977  
    262262    login_button = label
    263263
     264    def _comment(self, customer):
     265        return getattr(customer, 'suspended_comment', None)
     266
    264267    def update(self, SUBMIT=None, camefrom=None):
    265268        self.camefrom = camefrom
     
    16131616    def _searchUser(self, identifier, email):
    16141617        # Search customer
    1615         #cat = queryUtility(ICatalog, name='customers_catalog')
    1616         #results = cat.searchResults(
    1617             #reg_number=(identifier, identifier),
    1618         #    email=(email,email))
    1619         #for result in results:
    1620         #    if result.customer_id == identifier or \
    1621         #        result.reg_number == identifier or \
    1622         #        result.matric_number == identifier:
    1623         #        return result
     1618        cat = queryUtility(ICatalog, name='customers_catalog')
     1619        results = cat.searchResults(
     1620            reg_number=(identifier, identifier),
     1621            email=(email,email))
     1622        for result in results:
     1623            if result.customer_id == identifier \
     1624                or result.reg_number == identifier:
     1625                return result
    16241626        # Search portal user
    16251627        user = grok.getSite()['users'].get(identifier, None)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r11971 r11977  
    4242from waeup.ikoba.browser.breadcrumbs import Breadcrumb
    4343from waeup.ikoba.browser.interfaces import ICaptchaManager
     44from waeup.ikoba.mandates.mandate import PasswordMandate
    4445from waeup.ikoba.utils.helpers import get_current_principal, to_timezone, now
    4546from waeup.ikoba.customers.interfaces import (
    46     ICustomer, ICustomersContainer, ICustomerRequestPW
     47    ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils
    4748    )
    4849from waeup.ikoba.customers.catalog import search
     
    507508        self._redirect(email=email_sent, password=password,
    508509            customer_id=customer.customer_id)
    509         ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
     510        ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','')
    510511        self.context.logger.info(
    511512            '%s - %s (%s) - %s' % (ob_class, number, customer.customer_id, email_sent))
     
    567568    """
    568569    grok.context(ICustomer)
    569     grok.name('change_password')
     570    grok.name('changepassword')
    570571    grok.require('waeup.handleCustomer')
    571     grok.template('change_password')
     572    grok.template('changepassword')
    572573    label = _('Change password')
    573574    pnav = 4
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser_templates/changepassword.pt

    r11971 r11977  
    22      i18n:domain="waeup.kofa" enctype="multipart/form-data">
    33
    4   <input type="hidden" name="student_id" value=""
    5          tal:attributes="value context/student_id" />
     4  <input type="hidden" name="customer_id" value=""
     5         tal:attributes="value context/customer_id" />
    66
    77  <table class="form-table">
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_authentication.py

    r11972 r11977  
    237237        self.assertRaises(
    238238            Unauthorized,
    239             self.browser.open, self.customer_path + '/change_password')
    240         return
     239            self.browser.open, self.customer_path + '/changepassword')
     240        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r11975 r11977  
    498498            'mrofficer - customers.browser.LoginAsCustomerStep1 - K1000000 - '
    499499            'temp_password generated: %s' % temp_password in logcontent)
     500
     501class CustomerUITests(CustomersFullSetup):
     502    # Tests for Customer class views and pages
     503
     504    def test_customer_change_password(self):
     505        # Customers can change the password
     506        self.customer.personal_updated = datetime.utcnow()
     507        self.browser.open(self.login_path)
     508        self.browser.getControl(name="form.login").value = self.customer_id
     509        self.browser.getControl(name="form.password").value = 'spwd'
     510        self.browser.getControl("Login").click()
     511        self.assertEqual(self.browser.url, self.customer_path)
     512        self.assertTrue('You logged in' in self.browser.contents)
     513        # Change password
     514        self.browser.getLink("Change password").click()
     515        self.browser.getControl(name="change_password").value = 'pw'
     516        self.browser.getControl(
     517            name="change_password_repeat").value = 'pw'
     518        self.browser.getControl("Save").click()
     519        self.assertTrue('Password must have at least' in self.browser.contents)
     520        self.browser.getControl(name="change_password").value = 'new_password'
     521        self.browser.getControl(
     522            name="change_password_repeat").value = 'new_passssword'
     523        self.browser.getControl("Save").click()
     524        self.assertTrue('Passwords do not match' in self.browser.contents)
     525        self.browser.getControl(name="change_password").value = 'new_password'
     526        self.browser.getControl(
     527            name="change_password_repeat").value = 'new_password'
     528        self.browser.getControl("Save").click()
     529        self.assertTrue('Password changed' in self.browser.contents)
     530        # We are still logged in. Changing the password hasn't thrown us out.
     531        self.browser.getLink("Base Data").click()
     532        self.assertEqual(self.browser.url, self.customer_path)
     533        # We can logout
     534        self.browser.getLink("Logout").click()
     535        self.assertTrue('You have been logged out' in self.browser.contents)
     536        self.assertEqual(self.browser.url, 'http://localhost/app/index')
     537        # We can login again with the new password
     538        self.browser.getLink("Login").click()
     539        self.browser.open(self.login_path)
     540        self.browser.getControl(name="form.login").value = self.customer_id
     541        self.browser.getControl(name="form.password").value = 'new_password'
     542        self.browser.getControl("Login").click()
     543        self.assertEqual(self.browser.url, self.customer_path)
     544        self.assertTrue('You logged in' in self.browser.contents)
     545        return
     546
     547    def test_customer_upload_passport(self):
     548        # Customer cant login if their password is not set
     549        IWorkflowInfo(self.customer).fireTransition('start')
     550        self.browser.open(self.login_path)
     551        self.browser.getControl(name="form.login").value = self.customer_id
     552        self.browser.getControl(name="form.password").value = 'spwd'
     553        self.browser.getControl("Login").click()
     554        self.assertMatches(
     555            '...You logged in...', self.browser.contents)
     556        # Admitted customer can upload a passport picture
     557        self.browser.open(self.customer_path + '/change_portrait')
     558        ctrl = self.browser.getControl(name='passportuploadedit')
     559        file_obj = open(SAMPLE_IMAGE, 'rb')
     560        file_ctrl = ctrl.mech_control
     561        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
     562        self.browser.getControl(
     563            name='upload_passportuploadedit').click()
     564        self.assertTrue(
     565            'src="http://localhost/app/customers/K1000000/passport.jpg"'
     566            in self.browser.contents)
     567
     568    def test_customer_login(self):
     569        # Customer cant login if their password is not set
     570        self.customer.password = None
     571        self.browser.open(self.login_path)
     572        self.browser.getControl(name="form.login").value = self.customer_id
     573        self.browser.getControl(name="form.password").value = 'spwd'
     574        self.browser.getControl("Login").click()
     575        self.assertTrue(
     576            'You entered invalid credentials.' in self.browser.contents)
     577        # We set the password again
     578        IUserAccount(
     579            self.app['customers'][self.customer_id]).setPassword('spwd')
     580        # Customers can't login if their account is suspended/deactivated
     581        self.customer.suspended = True
     582        self.browser.open(self.login_path)
     583        self.browser.getControl(name="form.login").value = self.customer_id
     584        self.browser.getControl(name="form.password").value = 'spwd'
     585        self.browser.getControl("Login").click()
     586        self.assertMatches(
     587            '...<div class="alert alert-warning">'
     588            'Your account has been deactivated.</div>...', self.browser.contents)
     589        # If suspended_comment is set this message will be flashed instead
     590        self.customer.suspended_comment = u'Aetsch baetsch!'
     591        self.browser.getControl(name="form.login").value = self.customer_id
     592        self.browser.getControl(name="form.password").value = 'spwd'
     593        self.browser.getControl("Login").click()
     594        self.assertMatches(
     595            '...<div class="alert alert-warning">Aetsch baetsch!</div>...',
     596            self.browser.contents)
     597        self.customer.suspended = False
     598        # Customers can't login if a temporary password has been set and
     599        # is not expired
     600        self.app['customers'][self.customer_id].setTempPassword(
     601            'anybody', 'temp_spwd')
     602        self.browser.open(self.login_path)
     603        self.browser.getControl(name="form.login").value = self.customer_id
     604        self.browser.getControl(name="form.password").value = 'spwd'
     605        self.browser.getControl("Login").click()
     606        self.assertMatches(
     607            '...Your account has been temporarily deactivated...',
     608            self.browser.contents)
     609        # The customer can login with the temporary password
     610        self.browser.open(self.login_path)
     611        self.browser.getControl(name="form.login").value = self.customer_id
     612        self.browser.getControl(name="form.password").value = 'temp_spwd'
     613        self.browser.getControl("Login").click()
     614        self.assertMatches(
     615            '...You logged in...', self.browser.contents)
     616        # Customer can view the base data
     617        self.browser.open(self.customer_path)
     618        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     619        self.assertEqual(self.browser.url, self.customer_path)
     620        # When the password expires ...
     621        delta = timedelta(minutes=11)
     622        self.app['customers'][self.customer_id].temp_password[
     623            'timestamp'] = datetime.utcnow() - delta
     624        self.app['customers'][self.customer_id]._p_changed = True
     625        # ... the customer will be automatically logged out
     626        self.assertRaises(
     627            Unauthorized, self.browser.open, self.customer_path)
     628        # Then the customer can login with the original password
     629        self.browser.open(self.login_path)
     630        self.browser.getControl(name="form.login").value = self.customer_id
     631        self.browser.getControl(name="form.password").value = 'spwd'
     632        self.browser.getControl("Login").click()
     633        self.assertMatches(
     634            '...You logged in...', self.browser.contents)
     635
     636    def test_change_password_request(self):
     637        self.browser.open('http://localhost/app/changepw')
     638        self.browser.getControl(name="form.identifier").value = '123'
     639        self.browser.getControl(name="form.email").value = 'aa@aa.ng'
     640        self.browser.getControl("Send login credentials").click()
     641        self.assertTrue('An email with' in self.browser.contents)
     642
     643class CustomerRequestPWTests(CustomersFullSetup):
     644    # Tests for customer registration
     645
     646    layer = FunctionalLayer
     647
     648    def test_request_pw(self):
     649        # Customer with wrong number can't be found.
     650        self.browser.open('http://localhost/app/requestpw')
     651        self.browser.getControl(name="form.firstname").value = 'Anna'
     652        self.browser.getControl(name="form.number").value = 'anynumber'
     653        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     654        self.browser.getControl("Send login credentials").click()
     655        self.assertTrue('No customer record found.'
     656            in self.browser.contents)
     657        # Anonymous is not informed that firstname verification failed.
     658        # It seems that the record doesn't exist.
     659        self.browser.open('http://localhost/app/requestpw')
     660        self.browser.getControl(name="form.firstname").value = 'Johnny'
     661        self.browser.getControl(name="form.number").value = '123'
     662        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     663        self.browser.getControl("Send login credentials").click()
     664        self.assertTrue('No customer record found.'
     665            in self.browser.contents)
     666        # Even with the correct firstname we can't register if a
     667        # password has been set and used.
     668        self.browser.getControl(name="form.firstname").value = 'Anna'
     669        self.browser.getControl(name="form.number").value = '123'
     670        self.browser.getControl("Send login credentials").click()
     671        self.assertTrue('Your password has already been set and used.'
     672            in self.browser.contents)
     673        self.browser.open('http://localhost/app/requestpw')
     674        self.app['customers'][self.customer_id].password = None
     675        # The firstname field, used for verification, is not case-sensitive.
     676        self.browser.getControl(name="form.firstname").value = 'aNNa'
     677        self.browser.getControl(name="form.number").value = '123'
     678        self.browser.getControl(name="form.email").value = 'new@yy.zz'
     679        self.browser.getControl("Send login credentials").click()
     680        # Yeah, we succeded ...
     681        self.assertTrue('Your password request was successful.'
     682            in self.browser.contents)
     683        # ... and  customer can be found in the catalog via the email address
     684        cat = queryUtility(ICatalog, name='customers_catalog')
     685        results = list(
     686            cat.searchResults(
     687            email=('new@yy.zz', 'new@yy.zz')))
     688        self.assertEqual(self.customer,results[0])
     689        logfile = os.path.join(
     690            self.app['datacenter'].storage, 'logs', 'main.log')
     691        logcontent = open(logfile).read()
     692        self.assertTrue('zope.anybody - customers.browser.CustomerRequestPasswordPage - '
     693                        '123 (K1000000) - new@yy.zz' in logcontent)
     694        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py

    r11967 r11977  
    234234        return "return window.confirm(%s);" % _(
    235235            "'A history message will be added. Are you sure?'")
     236
     237class CustomerPasswordActionButton(ManageActionButton):
     238    grok.order(2)
     239    grok.context(ICustomer)
     240    grok.view(CustomerBaseDisplayFormPage)
     241    grok.require('waeup.handleCustomer')
     242    icon = 'actionicon_key.png'
     243    text = _('Change password')
     244    target = 'changepassword'
Note: See TracChangeset for help on using the changeset viewer.