コード例 #1
0
    def test_004(self):
        '''
        Sets up and executes test on MockRequestWrapper and MockResponseObject
        which are tested in this file only.
        These are really a library that allow PageRequest.py
        to run integration tests.
        '''
        # Test setup and initialization
        mock_site = "localtestsite.com"
        mock_request = MockRequestWrapper(mock_site)
        mock_response = mock_request.make_request()

        # Tests
        self.assertEqual(mock_response.text, "<html>")
        self.assertNotEqual(mock_response.text, "</html>")
        self.assertEqual(mock_response.content, b"<html>")
        self.assertNotEqual(mock_response.content, b"</html>")
コード例 #2
0
    def test_005(self):
        '''
        Tests that we can hit a local site, which provides mock html
        '''

        mock_site = "http://www.localtestsite.com/mysite.html"
        mock_request = MockRequestWrapper(mock_site)
        mock_response = mock_request.make_request()

        curpath = os.getcwd()
        newpath = curpath + '/tests/example-sites/'

        testfile = newpath + 'mysite.html'
        with open(testfile, 'r') as testhtml:
            test_response_data = testhtml.read()

        self.assertEqual(mock_response.text, test_response_data)
        self.assertEqual(mock_response.content, test_response_data.encode())