| 159 | |
| 160 | |
| 161 | def test_cut(): |
| 162 | c = cut.Cut() |
| 163 | with taddons.context(): |
| 164 | tflows = [tflow.tflow(resp=True)] |
| 165 | assert c.cut(tflows, ["request.method"]) == [["GET"]] |
| 166 | assert c.cut(tflows, ["request.scheme"]) == [["http"]] |
| 167 | assert c.cut(tflows, ["request.host"]) == [["address"]] |
| 168 | assert c.cut(tflows, ["request.port"]) == [["22"]] |
| 169 | assert c.cut(tflows, ["request.path"]) == [["/path"]] |
| 170 | assert c.cut(tflows, ["request.url"]) == [["http://address:22/path"]] |
| 171 | assert c.cut(tflows, ["request.content"]) == [[b"content"]] |
| 172 | assert c.cut(tflows, ["request.header[header]"]) == [["qvalue"]] |
| 173 | assert c.cut(tflows, ["request.header[unknown]"]) == [[""]] |
| 174 | |
| 175 | assert c.cut(tflows, ["response.status_code"]) == [["200"]] |
| 176 | assert c.cut(tflows, ["response.reason"]) == [["OK"]] |
| 177 | assert c.cut(tflows, ["response.content"]) == [[b"message"]] |
| 178 | assert c.cut(tflows, ["response.header[header-response]"]) == [["svalue"]] |
| 179 | assert c.cut(tflows, ["moo"]) == [[""]] |
| 180 | with pytest.raises(exceptions.CommandError): |
| 181 | assert c.cut(tflows, ["__dict__"]) == [[""]] |
| 182 | |
| 183 | with taddons.context(): |
| 184 | tflows = [tflow.tflow(resp=False)] |
| 185 | assert c.cut(tflows, ["response.reason"]) == [[""]] |
| 186 | assert c.cut(tflows, ["response.header[key]"]) == [[""]] |
| 187 | |
| 188 | for f in (tflow.ttcpflow(), tflow.tudpflow()): |
| 189 | c = cut.Cut() |
| 190 | with taddons.context(): |
| 191 | tflows = [f] |
| 192 | assert c.cut(tflows, ["request.method"]) == [[""]] |
| 193 | assert c.cut(tflows, ["response.status"]) == [[""]] |