def sanitize_input(req): rzdoc_name = request.get_json().get('rzdoc_name') attr_diff_dict = request.get_json()['attr_diff'] attr_diff = Attr_Diff.from_json_dict(attr_diff_dict) sanitize_input__attr_diff(attr_diff) return rzdoc_name, attr_diff;
def sanitize_input(req): rzdoc_name = request.get_json().get('rzdoc_name') attr_diff_dict = request.get_json()['attr_diff'] attr_diff = Attr_Diff.from_json_dict(attr_diff_dict) sanitize_input__attr_diff(attr_diff) return rzdoc_name, attr_diff
def test_ws_event__attr_diff(self): class NS_test(BaseNamespace): def on_diff_commit__attr(self, *data): greenlet.getcurrent().data = data raise KeyboardInterrupt() # TODO: cleanup: properly close socket test_label = neo4j_test_util.rand_label() n, n_id = test_util.generate_random_node_dict(test_label) # apply attr_diff attr_diff = Attr_Diff() attr_diff.add_node_attr_write(n_id, 'attr_0', 0) attr_diff.add_node_attr_write(n_id, 'attr_1', 'a') attr_diff.add_node_attr_rm(n_id, 'attr_2') def c_0(): with RZ_websocket(namespace=NS_test) as (_, ns_sock): c1_t.switch() # allow peer to connect data = json.dumps(attr_diff) ns_sock.emit('diff_commit__attr', data) c1_t.switch() def c_1(): with RZ_websocket(namespace=NS_test) as (sock, _): c0_t.switch() # allow peer to emit sock.wait(8) # allow self to receive c0_t = greenlet(c_0) c1_t = greenlet(c_1) c1_t.data = None c0_t.switch() self.assertTrue(None != c1_t.data) self.assertEqual(2, len(c1_t.data)) diff_in = Attr_Diff.from_json_dict(c1_t.data[0]) commit_ret = Attr_Diff.from_json_dict(c1_t.data[1]) self.assertEqual(Attr_Diff, type(diff_in)) self.assertEqual(Attr_Diff, type(commit_ret))
def test_ws_event__attr_diff(self): class NS_test(BaseNamespace): def on_diff_commit__attr(self, *data): greenlet.getcurrent().data = data raise KeyboardInterrupt( ) # TODO: cleanup: properly close socket test_label = neo4j_test_util.rand_label() n, n_id = test_util.generate_random_node_dict(test_label) # apply attr_diff attr_diff = Attr_Diff() attr_diff.add_node_attr_write(n_id, 'attr_0', 0) attr_diff.add_node_attr_write(n_id, 'attr_1', 'a') attr_diff.add_node_attr_rm(n_id, 'attr_2') def c_0(): with RZ_websocket(namespace=NS_test) as (_, ns_sock): c1_t.switch() # allow peer to connect data = json.dumps(attr_diff) ns_sock.emit('diff_commit__attr', data) c1_t.switch() def c_1(): with RZ_websocket(namespace=NS_test) as (sock, _): c0_t.switch() # allow peer to emit sock.wait(8) # allow self to receive c0_t = greenlet(c_0) c1_t = greenlet(c_1) c1_t.data = None c0_t.switch() self.assertTrue(None != c1_t.data) self.assertEqual(2, len(c1_t.data)) diff_in = Attr_Diff.from_json_dict(c1_t.data[0]) commit_ret = Attr_Diff.from_json_dict(c1_t.data[1]) self.assertEqual(Attr_Diff, type(diff_in)) self.assertEqual(Attr_Diff, type(commit_ret))
def on_diff_commit__attr(self, json_data): # FIXME: sanitize input json_dict = json.loads(json_data) attr_diff = Attr_Diff.from_json_dict(json_dict['attr_diff']) log.info('ws: rx: attr diff: ' + str(attr_diff)) ctx = self.__context__common(json_dict) kernel = self.request.kernel attr_diff, commit_ret = kernel.diff_commit__attr(attr_diff, ctx) # [!] note: here we actually send the attr_diff twice, but in the future # commit_ret may not be the same return self.multicast_msg('diff_commit__attr', attr_diff, commit_ret)