示例#1
0
 def test_already_recording(self):
     replaylib.start_record()
     try:
         replaylib.start_record()
     except replaylib.StateError:
         pass
     else:
         raise AssertionError("record twice should fail")
示例#2
0
 def test_record_while_playback(self):
     replaylib.start_playback_obj(replaylib.ReplayData())
     try:
         replaylib.start_record()
     except replaylib.StateError:
         pass
     else:
         raise AssertionError("record during playback should fail")
示例#3
0
 def setUp(self):
     global compare
     replaylib.start_record()
     webf = urllib.urlopen('http://localhost:%d' % servers.PORT)
     compare = webf.read()
     webf.close()
     replaylib.stop_record(TEST_FILENAME)
     PluginTester.setUp(self)
示例#4
0
    def test_with_file(self):
        replaylib.start_record()
        real = self._grab()
        replaylib.stop_record(TEST_FILENAME)
        replaylib.start_playback(TEST_FILENAME)
        fake = self._grab()
        replaylib.stop_playback()

        assert real == fake
示例#5
0
    def _with_actions(self, func):
        replaylib.start_record()
        real_compare = func()
        data = replaylib.stop_record_obj()

        replaylib.start_playback_obj(data)
        fake_compare = func()
        replaylib.stop_playback()

        assert real_compare == fake_compare
示例#6
0
 def test_content_type_header(self):
     replaylib.start_record()
     webf = self._urlopen()
     real = webf.info().getheader('Content-type')
     webf.close()
     data = replaylib.stop_record_obj()
     replaylib.start_playback_obj(data)
     webf = self._urlopen()
     fake = webf.info().getheader('Content-type')
     webf.close()
     replaylib.stop_playback()
示例#7
0
 def test_readline(self):
     replaylib.start_record()
     webf = self._urlopen()
     real = webf.readline()
     webf.close()
     data = replaylib.stop_record_obj()
     replaylib.start_playback_obj(data)
     webf = self._urlopen()
     fake = webf.readline()
     webf.close()
     replaylib.stop_playback()
示例#8
0
 def test_playback_unknown_request(self):
     replaylib.start_record()
     real = self._grab()
     data = replaylib.stop_record_obj()
     replaylib.start_playback_obj(data)
     try:
         fake = self._grab(params='post data')
     except replaylib.UnknownRequestError:
         pass
     else:
         raise AssertionError("unknown request should fail")
     replaylib.stop_playback()
示例#9
0
    def test_single(self):
        if not servers.SSL:
            raise SkipTest
        replaylib.start_record()
        webf = urllib.urlopen('https://localhost:%d' % servers.SECURE_PORT)
        real_compare = webf.read()
        webf.close()
        data = replaylib.stop_record_obj()

        replaylib.start_playback_obj(data)
        webf = urllib.urlopen('https://localhost:%d' % servers.SECURE_PORT)
        fake_compare = webf.read()
        webf.close()
        replaylib.stop_playback()

        assert real_compare == fake_compare
示例#10
0
    def test_read_partial(self):
        replaylib.start_record()
        conn = httplib.HTTPConnection('localhost:%d' % servers.PORT)
        conn.request("GET", "/")
        resp = conn.getresponse()
        real = resp.read(2)
        conn.close()
        data = replaylib.stop_record_obj()

        replaylib.start_playback_obj(data)
        conn = httplib.HTTPConnection('localhost:%d' % servers.PORT)
        conn.request("GET", "/")
        resp = conn.getresponse()
        fake = resp.read(2)
        conn.close()
        replaylib.stop_playback()

        assert real == fake
示例#11
0
    def test_getheader_with_httplib(self):
        replaylib.start_record()
        conn = httplib.HTTPConnection('localhost:%d' % servers.PORT)
        conn.request("GET", "/")
        resp = conn.getresponse()
        real = resp.getheader('Content-type')
        conn.close()
        data = replaylib.stop_record_obj()

        replaylib.start_playback_obj(data)
        conn = httplib.HTTPConnection('localhost:%d' % servers.PORT)
        conn.request("GET", "/")
        resp = conn.getresponse()
        fake = resp.getheader('Content-type')
        conn.close()
        replaylib.stop_playback()

        assert real == fake
示例#12
0
    def test_with_httplib(self):
        replaylib.start_record()
        conn = httplib.HTTPConnection('localhost:%d' % servers.PORT)
        conn.connect()
        conn.request("GET", "/")
        resp = conn.getresponse()
        real_body = resp.read()
        real_headers = resp.getheaders()
        conn.close()
        data = replaylib.stop_record_obj()

        replaylib.start_playback_obj(data)
        conn = httplib.HTTPConnection('localhost:%d' % servers.PORT)
        conn.connect()
        conn.request("GET", "/")
        resp = conn.getresponse()
        fake_body = resp.read()
        fake_headers = resp.getheaders()
        conn.close()
        replaylib.stop_playback()

        assert real_body == fake_body
        assert real_headers == fake_headers
示例#13
0
 def begin(self):
     if self.playback_filename:
         replaylib.start_playback(self.playback_filename)
     else:
         replaylib.start_record()