def test_sanitize_query(self): req_response_list = [ ({"first": None, "last": None}, {"first": 0, "last": 100}), ({"first": 123, "last": None}, {"first": 123, "last": 223}), ({"first": None, "last": 1000}, {"first": 0, "last": 100}), ({"first": 100, "last": None}, {"first": 100, "last": 200}), ({}, {"first": 0, "last": 100}), ] for req, resp in req_response_list: self.assertDictEqual(sanitize_query(req), resp)
def test_sanitize_query(self): req_response_list = [ ({ "first": None, "last": None }, { "first": 0, "last": 100 }), ({ "first": 123, "last": None }, { "first": 123, "last": 223 }), ({ "first": None, "last": 1000 }, { "first": 0, "last": 100 }), ({ "first": 100, "last": None }, { "first": 100, "last": 200 }), ({ "first": 123 }, { "first": 123, "last": 223 }), ({ "last": 123 }, { "first": 0, "last": 100 }), ({}, { "first": 0, "last": 100 }), ] for req, resp in req_response_list: assert sanitize_query(req) == resp
def test_sanitize_query_binary_fields(self): for field in ("infohash", "channel_pk"): field_in_b = b'0' * 20 field_in_hex = hexlify(field_in_b) assert sanitize_query({field: field_in_hex})[field] == field_in_b