def test_payload_build(self):
     type = PayloadType.UNK
     event = PayloadEvent.UNK
     data = "test_data"
     role = "test_role"
     p = Payload(data, event, type, role)
     x = build_payload(p.content())
     y = self.param_association(x, data, type, event, role)
     self.assertEqual(x.content(), y.content())
     print("Build: DICT :Passed")
     y = build_payload(json.dumps(x.content()))
     self.assertEqual(x.content(), y.content())
     print("Build: JSON :Passed")
     p = Payload(data, event, type)
     self.assertEqual(BLANK_FIELD, p.role)
     print("Build: Default Role :Passed")
 def run(self):
     res_data = None
     running = True
     self.lock.acquire()
     while running:
         try:
             req_data = self.request.recv(1024)
             if req_data is not None and (len(req_data) > 0):
                 req_data = build_payload(req_data.decode("utf8"))
                 if isinstance(req_data, Payload):
                     # Sends the received data to be manage by a helper function
                     res_data = self.data_handler(req_data, self.del_whitelist)
                     if running:
                         self.respond(res_data)
                 else:
                     print("[!] Raw data retrieved: {}".format(res_data))
             else:
                 self.send_event_message(PayloadEventMessages.ERROR, "There was no data received!")
         except socket.error as err:
             if err.errno not in [104, 32]:
                 raise
             running = False
     print("[-] Connection to {} Closed \n".format(self.client_address))