(self)
| 728 | self.assertStartsWith(location, 'https://pypi.org/') |
| 729 | |
| 730 | def test_get(self): |
| 731 | #constructs the path relative to the root directory of the HTTPServer |
| 732 | response = self.request(self.base_url + '/test') |
| 733 | self.check_status_and_reason(response, HTTPStatus.OK, data=self.data) |
| 734 | # check for trailing "/" which should return 404. See Issue17324 |
| 735 | response = self.request(self.base_url + '/test/') |
| 736 | self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) |
| 737 | response = self.request(self.base_url + '/test%2f') |
| 738 | self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) |
| 739 | response = self.request(self.base_url + '/test%2F') |
| 740 | self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) |
| 741 | response = self.request(self.base_url + '/') |
| 742 | self.check_status_and_reason(response, HTTPStatus.OK) |
| 743 | response = self.request(self.base_url + '%2f') |
| 744 | self.check_status_and_reason(response, HTTPStatus.OK) |
| 745 | response = self.request(self.base_url + '%2F') |
| 746 | self.check_status_and_reason(response, HTTPStatus.OK) |
| 747 | response = self.request(self.base_url) |
| 748 | self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) |
| 749 | self.assertEqual(response.getheader("Location"), self.base_url + "/") |
| 750 | self.assertEqual(response.getheader("Content-Length"), "0") |
| 751 | response = self.request(self.base_url + '/?hi=2') |
| 752 | self.check_status_and_reason(response, HTTPStatus.OK) |
| 753 | response = self.request(self.base_url + '?hi=1') |
| 754 | self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) |
| 755 | self.assertEqual(response.getheader("Location"), |
| 756 | self.base_url + "/?hi=1") |
| 757 | response = self.request('/ThisDoesNotExist') |
| 758 | self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) |
| 759 | response = self.request('/' + 'ThisDoesNotExist' + '/') |
| 760 | self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) |
| 761 | os.makedirs(os.path.join(self.tempdir, 'spam', 'index.html')) |
| 762 | response = self.request(self.base_url + '/spam/') |
| 763 | self.check_status_and_reason(response, HTTPStatus.OK) |
| 764 | |
| 765 | data = b"Dummy index file\r\n" |
| 766 | with open(os.path.join(self.tempdir_name, 'index.html'), 'wb') as f: |
| 767 | f.write(data) |
| 768 | response = self.request(self.base_url + '/') |
| 769 | self.check_status_and_reason(response, HTTPStatus.OK, data) |
| 770 | |
| 771 | # chmod() doesn't work as expected on Windows, and filesystem |
| 772 | # permissions are ignored by root on Unix. |
| 773 | if os.name == 'posix' and os.geteuid() != 0: |
| 774 | os.chmod(self.tempdir, 0) |
| 775 | try: |
| 776 | response = self.request(self.base_url + '/') |
| 777 | self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) |
| 778 | finally: |
| 779 | os.chmod(self.tempdir, 0o755) |
| 780 | |
| 781 | def test_head(self): |
| 782 | response = self.request( |
nothing calls this directly
no test coverage detected