Example #1
0
    def test_ignore_content(self):
        s = flow.ServerPlaybackState(None, [], False, False, None, False, None,
                                     False)
        r = tutils.tflow(resp=True)
        r2 = tutils.tflow(resp=True)

        r.request.content = "foo"
        r2.request.content = "foo"
        assert s._hash(r) == s._hash(r2)
        r2.request.content = "bar"
        assert not s._hash(r) == s._hash(r2)

        # now ignoring content
        s = flow.ServerPlaybackState(None, [], False, False, None, True, None,
                                     False)
        r = tutils.tflow(resp=True)
        r2 = tutils.tflow(resp=True)
        r.request.content = "foo"
        r2.request.content = "foo"
        assert s._hash(r) == s._hash(r2)
        r2.request.content = "bar"
        assert s._hash(r) == s._hash(r2)
        r2.request.content = ""
        assert s._hash(r) == s._hash(r2)
        r2.request.content = None
        assert s._hash(r) == s._hash(r2)
Example #2
0
 def test_ignore_payload_params(self):
     s = flow.ServerPlaybackState(None, [], False, False, None, False,
                                  ["param1", "param2"], False)
     r = tutils.tflow(resp=True)
     r.request.headers["Content-Type"] = "application/x-www-form-urlencoded"
     r.request.content = "paramx=x&param1=1"
     r2 = tutils.tflow(resp=True)
     r2.request.headers[
         "Content-Type"] = "application/x-www-form-urlencoded"
     r2.request.content = "paramx=x&param1=1"
     # same parameters
     assert s._hash(r) == s._hash(r2)
     # ignored parameters !=
     r2.request.content = "paramx=x&param1=2"
     assert s._hash(r) == s._hash(r2)
     # missing parameter
     r2.request.content = "paramx=x"
     assert s._hash(r) == s._hash(r2)
     # ignorable parameter added
     r2.request.content = "paramx=x&param1=2"
     assert s._hash(r) == s._hash(r2)
     # not ignorable parameter changed
     r2.request.content = "paramx=y&param1=1"
     assert not s._hash(r) == s._hash(r2)
     # not ignorable parameter missing
     r2.request.content = "param1=1"
     assert not s._hash(r) == s._hash(r2)
Example #3
0
    def test_hash(self):
        s = flow.ServerPlaybackState(None, [], False, False)
        r = tutils.tflow()
        r2 = tutils.tflow()

        assert s._hash(r)
        assert s._hash(r) == s._hash(r2)
        r.request.headers["foo"] = ["bar"]
        assert s._hash(r) == s._hash(r2)
        r.request.path = "voing"
        assert s._hash(r) != s._hash(r2)
Example #4
0
    def test_ignore_host(self):
        s = flow.ServerPlaybackState(None, [], False, False, None, False, None,
                                     True)
        r = tutils.tflow(resp=True)
        r2 = tutils.tflow(resp=True)

        r.request.host = "address"
        r2.request.host = "address"
        assert s._hash(r) == s._hash(r2)
        r2.request.host = "wrong_address"
        assert s._hash(r) == s._hash(r2)
Example #5
0
    def test_load_with_nopop(self):
        r = tutils.tflow(resp=True)
        r.request.headers["key"] = ["one"]

        r2 = tutils.tflow(resp=True)
        r2.request.headers["key"] = ["two"]

        s = flow.ServerPlaybackState(None, [r, r2], False, True)

        assert s.count() == 2
        s.next_flow(r)
        assert s.count() == 2
Example #6
0
 def test_ignore_payload_wins_over_params(self):
     # NOTE: parameters are mutually exclusive in options
     s = flow.ServerPlaybackState(None, [], False, False, None, True,
                                  ["param1", "param2"], False)
     r = tutils.tflow(resp=True)
     r.request.headers["Content-Type"] = "application/x-www-form-urlencoded"
     r.request.content = "paramx=y"
     r2 = tutils.tflow(resp=True)
     r2.request.headers[
         "Content-Type"] = "application/x-www-form-urlencoded"
     r2.request.content = "paramx=x"
     # same parameters
     assert s._hash(r) == s._hash(r2)
Example #7
0
 def test_ignore_params(self):
     s = flow.ServerPlaybackState(None, [], False, False, ["param1", "param2"], False)
     r = tutils.tflow(resp=True)
     r.request.path="/test?param1=1"
     r2 = tutils.tflow(resp=True)
     r2.request.path="/test"
     assert s._hash(r) == s._hash(r2)
     r2.request.path="/test?param1=2"
     assert s._hash(r) == s._hash(r2)
     r2.request.path="/test?param2=1"
     assert s._hash(r) == s._hash(r2)
     r2.request.path="/test?param3=2"
     assert not s._hash(r) == s._hash(r2)
Example #8
0
    def test_headers(self):
        s = flow.ServerPlaybackState(["foo"], [], False, False)
        r = tutils.tflow(resp=True)
        r.request.headers["foo"] = ["bar"]
        r2 = tutils.tflow(resp=True)
        assert not s._hash(r) == s._hash(r2)
        r2.request.headers["foo"] = ["bar"]
        assert s._hash(r) == s._hash(r2)
        r2.request.headers["oink"] = ["bar"]
        assert s._hash(r) == s._hash(r2)

        r = tutils.tflow(resp=True)
        r2 = tutils.tflow(resp=True)
        assert s._hash(r) == s._hash(r2)
Example #9
0
 def test_ignore_payload_params_other_content_type(self):
     s = flow.ServerPlaybackState(None, [], False, False, None, False,
                                  ["param1", "param2"], False)
     r = tutils.tflow(resp=True)
     r.request.headers["Content-Type"] = "application/json"
     r.request.content = '{"param1":"1"}'
     r2 = tutils.tflow(resp=True)
     r2.request.headers["Content-Type"] = "application/json"
     r2.request.content = '{"param1":"1"}'
     # same content
     assert s._hash(r) == s._hash(r2)
     # distint content (note only x-www-form-urlencoded payload is analysed)
     r2.request.content = '{"param1":"2"}'
     assert not s._hash(r) == s._hash(r2)
Example #10
0
    def test_load(self):
        r = tutils.tflow(resp=True)
        r.request.headers["key"] = ["one"]

        r2 = tutils.tflow(resp=True)
        r2.request.headers["key"] = ["two"]

        s = flow.ServerPlaybackState(None, [r, r2], False, False)
        assert s.count() == 2
        assert len(s.fmap.keys()) == 1

        n = s.next_flow(r)
        assert n.request.headers["key"] == ["one"]
        assert s.count() == 1

        n = s.next_flow(r)
        assert n.request.headers["key"] == ["two"]
        assert s.count() == 0

        assert not s.next_flow(r)