Ignore:
Timestamp:
24 Sep 2019, 17:21:28 (5 years ago)
Author:
Henrik Bettermann
Message:

Parents access implementation (part 1)

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_authentication.py

    r9334 r15606  
    8989        return None
    9090
     91    def getParentsPassword(self):
     92        parents_password_dict = getattr(self, 'parents_password', None)
     93        if parents_password_dict is not None:
     94            delta = timedelta(minutes=self.temp_password_minutes)
     95            now = datetime.utcnow()
     96            if now < parents_password_dict.get('timestamp') + delta:
     97                return parents_password_dict.get('password')
     98            else:
     99                # Unset temporary password if expired
     100                self.parents_password = None
     101        return None
     102
     103
    91104
    92105class MinimalPAU(PluggableAuthentication):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r15545 r15606  
    46714671            self.assertTrue(
    46724672                'Uploaded file contains illegal data' in self.browser.contents)
     4673
     4674class ParentsUITests(StudentsFullSetup):
     4675    # Tests for UI actions when acting as parents.
     4676
     4677    def test_login_as_parents(self):
     4678        # Sstudent login still works after all the changes made
     4679        self.browser.open(self.login_path)
     4680        self.browser.getControl(name="form.login").value = self.student_id
     4681        self.browser.getControl(name="form.password").value = 'spwd'
     4682        self.browser.getControl("Login").click()
     4683        self.assertTrue('You logged in' in self.browser.contents)
     4684        self.browser.open(self.edit_personal_path)
     4685        self.browser.getLink("Logout").click()
     4686        self.assertTrue('You have been logged out' in self.browser.contents)
     4687        # We set parents password
     4688        self.app['students'][self.student_id].setParentsPassword('ppwd')
     4689        self.browser.open(self.login_path)
     4690        # Student can't login with original password
     4691        self.browser.getControl(name="form.login").value = self.student_id
     4692        self.browser.getControl(name="form.password").value = 'spwd'
     4693        self.browser.getControl("Login").click()
     4694        self.assertEqual(self.browser.url, self.login_path)
     4695        self.assertTrue('Your account has been temporarily deactivated '
     4696            'because your parents have logged in.' in self.browser.contents)
     4697        # Parents can login with their password
     4698        self.browser.open(self.login_path)
     4699        self.browser.getControl(name="form.login").value = self.student_id
     4700        self.browser.getControl(name="form.password").value = 'ppwd'
     4701        self.browser.getControl("Login").click()
     4702        self.assertTrue(
     4703            'You logged in.' in self.browser.contents)
     4704        self.assertTrue(
     4705            '<a href="http://localhost/app/students/K1000000">Base Data</a>'
     4706            in self.browser.contents)
     4707        # They do not see all links ...
     4708        self.assertFalse(
     4709            '<a href="http://localhost/app/students/K1000000/history">History</a>'
     4710            in self.browser.contents)
     4711        # ... and can't change anything
     4712        self.assertRaises(
     4713            Unauthorized, self.browser.open, self.edit_personal_path)
     4714        # If the password has expired, parents are logged out and the
     4715        # student can login again with the original password
     4716        delta = timedelta(minutes=11)
     4717        self.app['students'][self.student_id].parents_password[
     4718            'timestamp'] = datetime.utcnow() - delta
     4719        self.app['students'][self.student_id]._p_changed = True
     4720        self.assertRaises(
     4721            Unauthorized, self.browser.open, self.student_path)
     4722        # Parents login is written to log file
     4723        logfile = os.path.join(
     4724            self.app['datacenter'].storage, 'logs', 'students.log')
     4725        logcontent = open(logfile).read()
     4726        self.assertTrue(
     4727            'K1000000 - browser.pages.LoginPage - K1000000 - Parents logged in'
     4728            in logcontent)
Note: See TracChangeset for help on using the changeset viewer.