comparison test/test_liveserver.py @ 6754:bb04638dc78d

Test _generic.item.html to mke sure submit button displayed properly Login as admin and new fred user. Admin user should see submit button when viewing /status7. User fred should not see it. Both should see the word 'done-cbb' which is the name of status7. Chose that since done-cbb is unliely to occur naturally while unread (name of /status1) could occur by chance in the future.
author John Rouillard <rouilj@ieee.org>
date Tue, 05 Jul 2022 00:36:22 -0400
parents c63ddea96fcb
children d308fb5ba9b0
comparison
equal deleted inserted replaced
6753:2bca9fcef70d 6754:bb04638dc78d
1 import shutil, errno, pytest, json, gzip, os, re 1 import shutil, errno, pytest, json, gzip, os, re
2 2
3 from roundup import i18n 3 from roundup import i18n
4 from roundup import password
4 from roundup.anypy.strings import b2s 5 from roundup.anypy.strings import b2s
5 from roundup.cgi.wsgi_handler import RequestDispatcher 6 from roundup.cgi.wsgi_handler import RequestDispatcher
6 from .wsgi_liveserver import LiveServerTestCase 7 from .wsgi_liveserver import LiveServerTestCase
7 from . import db_test_base 8 from . import db_test_base
8 9
59 # set up and open a tracker 60 # set up and open a tracker
60 cls.instance = db_test_base.setupTracker(cls.dirname, cls.backend) 61 cls.instance = db_test_base.setupTracker(cls.dirname, cls.backend)
61 62
62 # open the database 63 # open the database
63 cls.db = cls.instance.open('admin') 64 cls.db = cls.instance.open('admin')
65
66 # add a user without edit access for status.
67 cls.db.user.create(username="fred", roles='User',
68 password=password.Password('sekrit'), address='fred@example.com')
64 69
65 # set the url the test instance will run at. 70 # set the url the test instance will run at.
66 cls.db.config['TRACKER_WEB'] = "http://localhost:9001/" 71 cls.db.config['TRACKER_WEB'] = "http://localhost:9001/"
67 # set up mailhost so errors get reported to debuging capture file 72 # set up mailhost so errors get reported to debuging capture file
68 cls.db.config.MAILHOST = "localhost" 73 cls.db.config.MAILHOST = "localhost"
912 "@action": "login"} 917 "@action": "login"}
913 f = session.post(self.url_base()+'/', data=login) 918 f = session.post(self.url_base()+'/', data=login)
914 # look for change in text in sidebar post login 919 # look for change in text in sidebar post login
915 self.assertIn('<b>Hello, admin</b>', f.text) 920 self.assertIn('<b>Hello, admin</b>', f.text)
916 921
922 def test__generic_item_template(self):
923 """Load /status1 object. Admin has edit rights so should see
924 a submit button. fred doesn't have edit rights
925 so should not have a submit button.
926 """
927 for user in ["admin", "fred"]:
928 # Set up session to manage cookies <insert blue monster here>
929 session = requests.Session()
930 session.headers.update({'Origin': self.url_base()})
931
932 # login using form
933 login = {"__login_name": user, '__login_password': 'sekrit',
934 "@action": "login"}
935 f = session.post(self.url_base()+'/', data=login)
936 # look for change in text in sidebar post login
937 self.assertIn('Hello, %s'%user, f.text)
938 f = session.post(self.url_base()+'/status7', data=login)
939 print(f.content)
940
941 # status1's name is unread
942 self.assertIn(b'done-cbb', f.content)
943
944 if user == 'admin':
945 self.assertIn(b'<input name="submit_button" type="submit" value="Submit Changes">', f.content)
946 else:
947 self.assertNotIn(b'<input name="submit_button" type="submit" value="Submit Changes">', f.content)
948
949
917 def test_new_issue_with_file_upload(self): 950 def test_new_issue_with_file_upload(self):
918 # Set up session to manage cookies <insert blue monster here> 951 # Set up session to manage cookies <insert blue monster here>
919 session = requests.Session() 952 session = requests.Session()
920 session.headers.update({'Origin': 'http://localhost:9001'}) 953 session.headers.update({'Origin': 'http://localhost:9001'})
921 954

Roundup Issue Tracker: http://roundup-tracker.org/