예제 #1
0
 def test_already_playing(self):
     replaylib.start_playback_obj(replaylib.ReplayData())
     try:
         replaylib.start_playback_obj(replaylib.ReplayData())
     except replaylib.StateError:
         pass
     else:
         raise AssertionError("playback 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 _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
예제 #4
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()
예제 #5
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()
예제 #6
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()
예제 #7
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
예제 #8
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
예제 #9
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
예제 #10
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