Ejemplo n.º 1
0
 def test_stop_not_playing(self):
     try:
         replaylib.stop_playback()
     except replaylib.StateError:
         pass
     else:
         raise AssertionError("stop playback without start should fail")
Ejemplo n.º 2
0
 def test_recording(self):
     replaylib.start_playback(TEST_FILENAME)
     webf = urllib.urlopen('http://localhost:%d' % servers.PORT)
     fake = webf.read()
     webf.close()
     replaylib.stop_playback()
     assert fake == compare
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
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
Ejemplo n.º 11
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
Ejemplo n.º 12
0
 def report(self, stream):
     if self.playback_filename:
         replaylib.stop_playback()
     else:
         replaylib.stop_record(self.record_filename)