def test_near_miss_request_pattern_result_serialization(self): e = NearMissRequestPatternResult( url='test', absolute_url='test2', method=HttpMethods.GET, client_ip='1.1.1.1', headers={CommonHeaders.ACCEPT: 'json'}, query_parameters={'test': 1}, cookies={'chocolate': 'chip'}, basic_auth_credentials=BasicAuthCredentials(username='******', password='******'), browser_proxy_request=False, body_as_base64='test3', body='test4') serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, 'url', 'test') self.assertDictContainsKeyWithValue(serialized, 'absoluteUrl', 'test2') self.assertDictContainsKeyWithValue(serialized, 'method', 'GET') self.assertDictContainsKeyWithValue(serialized, 'clientIp', '1.1.1.1') self.assertDictContainsKeyWithValue(serialized, 'headers', {'Accept': 'json'}) self.assertDictContainsKeyWithValue(serialized, 'queryParameters', {'test': 1}) self.assertDictContainsKeyWithValue(serialized, 'cookies', {'chocolate': 'chip'}) self.assertDictContainsKeyWithValue(serialized, 'basicAuthCredentials', { 'username': '******', 'password': '******' }) self.assertDictContainsKeyWithValue(serialized, 'browserProxyRequest', False) self.assertDictContainsKeyWithValue(serialized, 'bodyAsBase64', 'test3') self.assertDictContainsKeyWithValue(serialized, 'body', 'test4')
def test_near_miss_request_pattern_result_serialization(self): e = NearMissRequestPatternResult( url="test", absolute_url="test2", method=HttpMethods.GET, client_ip="1.1.1.1", headers={CommonHeaders.ACCEPT: "json"}, query_parameters={"test": 1}, cookies={"chocolate": "chip"}, basic_auth_credentials=BasicAuthCredentials(username="******", password="******"), browser_proxy_request=False, body_as_base64="test3", body="test4", ) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "url", "test") self.assertDictContainsKeyWithValue(serialized, "absoluteUrl", "test2") self.assertDictContainsKeyWithValue(serialized, "method", "GET") self.assertDictContainsKeyWithValue(serialized, "clientIp", "1.1.1.1") self.assertDictContainsKeyWithValue(serialized, "headers", {"Accept": "json"}) self.assertDictContainsKeyWithValue(serialized, "queryParameters", {"test": 1}) self.assertDictContainsKeyWithValue(serialized, "cookies", {"chocolate": "chip"}) self.assertDictContainsKeyWithValue(serialized, "basicAuthCredentials", { "username": "******", "password": "******" }) self.assertDictContainsKeyWithValue(serialized, "browserProxyRequest", False) self.assertDictContainsKeyWithValue(serialized, "bodyAsBase64", "test3") self.assertDictContainsKeyWithValue(serialized, "body", "test4")
def test_near_miss_match_serialization(self): e = NearMissMatch( request=NearMissMatchRequest(url='test'), request_pattern=NearMissRequestPatternResult(url='test2'), match_result=NearMissMatchResult(distance=0.75)) serialized = e.get_json_data() self.assertDictContainsKeyWithValueType(serialized, 'request', dict) request = serialized['request'] self.assertDictContainsKeyWithValue(request, 'url', 'test') self.assertDictContainsKeyWithValueType(serialized, 'requestPattern', dict) request_pattern = serialized['requestPattern'] self.assertDictContainsKeyWithValue(request_pattern, 'url', 'test2') self.assertDictContainsKeyWithValueType(serialized, 'matchResult', dict) match_result = serialized['matchResult'] self.assertDictContainsKeyWithValue(match_result, 'distance', 0.75)
def test_near_miss_match_response_serialization(self): e = NearMissMatchResponse(near_misses=[ NearMissMatch(request=NearMissMatchRequest(url='test'), request_pattern=NearMissRequestPatternResult( url='test2'), match_result=NearMissMatchResult(distance=0.75)) ]) serialized = e.get_json_data() self.assertDictContainsKeyWithValueType(serialized, 'nearMisses', list) near_miss = serialized['nearMisses'][0] self.assertDictContainsKeyWithValueType(near_miss, 'request', dict) self.assertDictContainsKeyWithValue(near_miss['request'], 'url', 'test') self.assertDictContainsKeyWithValueType(near_miss, 'requestPattern', dict) self.assertDictContainsKeyWithValue(near_miss['requestPattern'], 'url', 'test2') self.assertDictContainsKeyWithValueType(near_miss, 'matchResult', dict) self.assertDictContainsKeyWithValue(near_miss['matchResult'], 'distance', 0.75)
def test_near_miss_match_serialization(self): e = NearMissMatch( request=NearMissMatchRequest(url="test"), request_pattern=NearMissRequestPatternResult(url="test2"), match_result=NearMissMatchResult(distance=0.75), ) serialized = e.get_json_data() self.assertDictContainsKeyWithValueType(serialized, "request", dict) request = serialized["request"] self.assertDictContainsKeyWithValue(request, "url", "test") self.assertDictContainsKeyWithValueType(serialized, "requestPattern", dict) request_pattern = serialized["requestPattern"] self.assertDictContainsKeyWithValue(request_pattern, "url", "test2") self.assertDictContainsKeyWithValueType(serialized, "matchResult", dict) match_result = serialized["matchResult"] self.assertDictContainsKeyWithValue(match_result, "distance", 0.75)
def test_near_miss_match_response_serialization(self): e = NearMissMatchResponse(near_misses=[ NearMissMatch( request=NearMissMatchRequest(url="test"), request_pattern=NearMissRequestPatternResult(url="test2"), match_result=NearMissMatchResult(distance=0.75), ) ]) serialized = e.get_json_data() self.assertDictContainsKeyWithValueType(serialized, "nearMisses", list) near_miss = serialized["nearMisses"][0] self.assertDictContainsKeyWithValueType(near_miss, "request", dict) self.assertDictContainsKeyWithValue(near_miss["request"], "url", "test") self.assertDictContainsKeyWithValueType(near_miss, "requestPattern", dict) self.assertDictContainsKeyWithValue(near_miss["requestPattern"], "url", "test2") self.assertDictContainsKeyWithValueType(near_miss, "matchResult", dict) self.assertDictContainsKeyWithValue(near_miss["matchResult"], "distance", 0.75)
def test_near_miss_request_pattern_result_deserialization(self): serialized = { 'clientIp': '1.1.1.1', 'cookies': { 'chocolate': 'chip' }, 'absoluteUrl': 'test2', 'headers': { 'Accept': 'json' }, 'url': 'test', 'browserProxyRequest': False, 'body': 'test4', 'bodyAsBase64': 'test3', 'queryParameters': { 'test': 1 }, 'basicAuthCredentials': { 'username': '******', 'password': '******' }, 'method': 'GET' } e = NearMissRequestPatternResult.from_dict(serialized) self.assertIsInstance(e, NearMissRequestPatternResult) self.assertEquals('test', e.url) self.assertEquals('test2', e.absolute_url) self.assertEquals('GET', e.method) self.assertEquals('1.1.1.1', e.client_ip) self.assertEquals({'Accept': 'json'}, e.headers) self.assertEquals({'test': 1}, e.query_parameters) self.assertEquals({'chocolate': 'chip'}, e.cookies) self.assertIsInstance(e.basic_auth_credentials, BasicAuthCredentials) self.assertEquals('username', e.basic_auth_credentials.username) self.assertEquals('password', e.basic_auth_credentials.password) self.assertEquals(False, e.browser_proxy_request) self.assertEquals('test3', e.body_as_base64) self.assertEquals('test4', e.body)
def test_near_miss_request_pattern_result_deserialization(self): serialized = { "clientIp": "1.1.1.1", "cookies": { "chocolate": "chip" }, "absoluteUrl": "test2", "headers": { "Accept": "json" }, "url": "test", "browserProxyRequest": False, "body": "test4", "bodyAsBase64": "test3", "queryParameters": { "test": 1 }, "basicAuthCredentials": { "username": "******", "password": "******" }, "method": "GET", } e = NearMissRequestPatternResult.from_dict(serialized) self.assertIsInstance(e, NearMissRequestPatternResult) self.assertEquals("test", e.url) self.assertEquals("test2", e.absolute_url) self.assertEquals("GET", e.method) self.assertEquals("1.1.1.1", e.client_ip) self.assertEquals({"Accept": "json"}, e.headers) self.assertEquals({"test": 1}, e.query_parameters) self.assertEquals({"chocolate": "chip"}, e.cookies) self.assertIsInstance(e.basic_auth_credentials, BasicAuthCredentials) self.assertEquals("username", e.basic_auth_credentials.username) self.assertEquals("password", e.basic_auth_credentials.password) self.assertEquals(False, e.browser_proxy_request) self.assertEquals("test3", e.body_as_base64) self.assertEquals("test4", e.body)