Пример #1
0
 def test_stop_not_recording(self):
     try:
         replaylib.stop_record_obj()
     except replaylib.StateError:
         pass
     else:
         raise AssertionError("stop recording without start should fail")
Пример #2
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
Пример #3
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()
Пример #4
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()
Пример #5
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()
Пример #6
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
Пример #7
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
Пример #8
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
Пример #9
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