Changeset 11977 for main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests
- Timestamp:
- 17 Nov 2014, 06:29:21 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_authentication.py
r11972 r11977 237 237 self.assertRaises( 238 238 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 498 498 'mrofficer - customers.browser.LoginAsCustomerStep1 - K1000000 - ' 499 499 'temp_password generated: %s' % temp_password in logcontent) 500 501 class 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 643 class 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
Note: See TracChangeset for help on using the changeset viewer.