comparison test/test_liveserver.py @ 8020:60c98a8a23bd

fix: make If-None-Match work for static file (@@file) case Found by Redbot testing.
author John Rouillard <rouilj@ieee.org>
date Sun, 02 Jun 2024 20:35:47 -0400
parents dd229bbdd32d
children 28aa76443f58
comparison
equal deleted inserted replaced
8019:16cc72cd9c17 8020:60c98a8a23bd
705 705
706 content = json.loads(f.content) 706 content = json.loads(f.content)
707 707
708 self.assertEqual(3, len(json.loads(f.content)['data']['collection'])) 708 self.assertEqual(3, len(json.loads(f.content)['data']['collection']))
709 709
710 def test_inm(self):
711 '''retrieve the user_utils.js file without an if-none-match etag
712 header, a bad if-none-match header and valid single and
713 multiple values.
714 '''
715 f = requests.get(self.url_base() + '/@@file/user_utils.js',
716 headers = { 'Accept-Encoding': 'gzip, foo',
717 'Accept': '*/*'})
718 print(f.status_code)
719 print(f.headers)
720
721 self.assertEqual(f.status_code, 200)
722 expected = { 'Content-Type': self.js_mime_type,
723 'Content-Encoding': 'gzip',
724 'Vary': 'Accept-Encoding',
725 }
726
727 # use dict comprehension to remove fields like date,
728 # etag etc. from f.headers.
729 self.assertDictEqual({ key: value for (key, value) in
730 f.headers.items() if key in expected },
731 expected)
732
733 # use etag in previous response
734 etag = f.headers['etag']
735 f = requests.get(self.url_base() + '/@@file/user_utils.js',
736 headers = { 'Accept-Encoding': 'gzip, foo',
737 'If-None-Match': etag,
738 'Accept': '*/*'})
739 print(f.status_code)
740 print(f.headers)
741
742 self.assertEqual(f.status_code, 304)
743 expected = { 'Vary': 'Accept-Encoding',
744 'Content-Length': '0',
745 'ETag': etag,
746 'Vary': 'Accept-Encoding'
747 }
748
749 # use dict comprehension to remove fields like date, server,
750 # etc. from f.headers.
751 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
752
753 # test again with etag supplied w/o content-encoding
754 # and multiple etags
755 self.assertTrue(etag.endswith('-gzip"'))
756
757 # keep etag intact. Used below.
758 base_etag = etag[:-6] + '"'
759
760 all_etags = (
761 '"a41932-8b5-664ce93d", %s", "a41932-8b5-664ce93d-br"' %
762 base_etag
763 )
764
765 f = requests.get(self.url_base() + '/@@file/user_utils.js',
766 headers = { 'Accept-Encoding': 'gzip, foo',
767 'If-None-Match': base_etag,
768 'Accept': '*/*'})
769 print(f.status_code)
770 print(f.headers)
771
772 self.assertEqual(f.status_code, 304)
773 expected = { 'Vary': 'Accept-Encoding',
774 'Content-Length': '0',
775 'ETag': base_etag,
776 'Vary': 'Accept-Encoding'
777 }
778
779 # use dict comprehension to remove fields like date, server,
780 # etc. from f.headers.
781 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
782
783
784 # test with bad etag
785 f = requests.get(self.url_base() + '/@@file/user_utils.js',
786 headers = { 'Accept-Encoding': 'gzip, foo',
787 'If-None-Match': '"a41932-8b5-664ce93d"',
788 'Accept': '*/*'})
789 print(f.status_code)
790 print(f.headers)
791
792 self.assertEqual(f.status_code, 200)
793 expected = { 'Content-Type': self.js_mime_type,
794 'ETag': etag,
795 'Content-Encoding': 'gzip',
796 'Vary': 'Accept-Encoding',
797 }
798
799 # use dict comprehension to remove fields like date, server,
800 # etc. from f.headers.
801 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
710 802
711 def test_ims(self): 803 def test_ims(self):
712 ''' retreive the user_utils.js file with old and new 804 ''' retrieve the user_utils.js file with old and new
713 if-modified-since timestamps. 805 if-modified-since timestamps.
714 ''' 806 '''
715 from datetime import datetime 807 from datetime import datetime
716 808
717 f = requests.get(self.url_base() + '/@@file/user_utils.js', 809 f = requests.get(self.url_base() + '/@@file/user_utils.js',

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