def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() self.user1 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.user2 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user2 is None: self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1111-11-11") self.create_circle("INFO1") self.create_circle("INFO2") self.create_circle("INFO3") self.token1 = authenticate_user(self.api, self.user1, "test") self.token2 = authenticate_user(self.api, self.user2, "test") self.tokenAdmin = authenticate_user(self.api, "*****@*****.**", "PapieNeo2019")
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() self.user1 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.user2 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user2 is None: self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1111-11-11") self.circle = Circle(name="Mamie") self.linkCircle = UserToCircle(user=self.user1, circle=self.circle) self.linkCircle2 = UserToCircle(user=self.user2, circle=self.circle) db.session.commit() self.token1 = authenticate_user(self.api, self.user1, "test") self.token2 = authenticate_user(self.api, self.user2, "test") self.tokenAdmin = authenticate_user(self.api, "*****@*****.**", "PapieNeo2019")
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() self.user1 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.user2 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user2 is None: self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1111-11-11") self.circle1 = Circle(name="TestPaymentCircle") self.link1 = UserToCircle() self.link1.user = self.user1 self.link1.circle = self.circle1 db.session.commit() self.token1 = authenticate_user(self.api, self.user1, "test") self.token2 = authenticate_user(self.api, self.user2, "test")
class SocketClientsStorage(unittest.TestCase): def setUp(self): neo_config.load_config() neo_config.set_project_variables() self.neo = NeoAPI(neo_config) self.api = self.neo.activate_testing() self.u1 = db_utils.get_user("*****@*****.**") self.u2 = db_utils.get_user("*****@*****.**") self.t1 = testutils.authenticate_user(self.api, self.u1, neo_config.beta_user1_password) self.t2 = testutils.authenticate_user(self.api, self.u2, neo_config.beta_user2_password) self.use_redis = neo_config.use_redis self.url = neo_config.redis_url_dev if self.use_redis: sockets.storage.set_conf(self.use_redis, self.url) self.redis_conn = sockets.storage RedisStorage.clean_databases(self.url) def tearDown(self): db_utils.clean_default_content() RedisStorage.clean_databases(self.url) def test_create_client(self): ae.authentication(self.t1, "test_session_id") assert len(sockets) == 1 ae.authentication(self.t2, "test_session_id2") assert len(sockets) == 2 ae.disconnection("test_session_id") assert len(sockets) == 1 ae.disconnection("test_session_id2") assert len(sockets) == 0
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() db.session.query(UserModel).delete() db.session.commit()
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() self.user1 = db.session.query(UserModel).filter(UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.user2 = db.session.query(UserModel).filter(UserModel.email == "*****@*****.**").first() if self.user2 is None: self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1111-11-11") self.user3 = db.session.query(UserModel).filter(UserModel.email == "*****@*****.**").first() if self.user3 is None: self.user3 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1111-11-11") self.create_circle() self.conv1 = Conversation(name="ConversationInfoTest") self.conv2 = Conversation(name="ConversationInfoTest2") self.conv3 = Conversation(name="ConversationInfoTest2") self.UserToConv1 = UserToConv() self.UserToConv2 = UserToConv() self.UserToConv3 = UserToConv() self.UserToConv4 = UserToConv() self.create_conversation(self.conv1, self.user1, self.user2, self.UserToConv1, self.UserToConv2, self.circle) self.create_conversation(self.conv3, self.user1, self.user2, UserToConv(), UserToConv(), self.circle) self.create_conversation(self.conv2, self.user2, self.user3, self.UserToConv3, self.UserToConv4, self.circle2) self.token1 = authenticate_user(self.api, self.user1, "test") self.token2 = authenticate_user(self.api, self.user2, "test") self.token3 = authenticate_user(self.api, self.user3, "test") self.tokenAdmin = authenticate_user(self.api, "*****@*****.**", "PapieNeo2019")
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() self.user1 = db.session.query(UserModel).filter(UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.api_token = self.user1.encode_api_token()
class SocketioAuthenticate(unittest.TestCase): def setUp(self): neo_config.load_config() neo_config.set_project_variables() self.neo = NeoAPI(neo_config) self.api = self.neo.activate_testing() self.client = SocketIOTestClient(self.neo.app, socketio) self.client2 = SocketIOTestClient(self.neo.app, socketio) self.client.disconnect() self.client2.disconnect() self.user1 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") db.session.commit() self.token1 = authenticate_user(self.api, self.user1, "test") def tearDown(self): self.client.disconnect() self.client2.disconnect() def test_valid_connection(self): assert len(sockets) == 0 self.client.connect() assert len(sockets) == 0 self.client2.connect() assert len(sockets) == 0 def test_valid_authentication(self): data = {'token': self.token1} assert len(sockets) == 0 self.client.connect() self.client.emit('authenticate', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' if not self.neo.config.use_redis: assert len(sockets) == 1 def test_invalid_authentication(self): data = {'token': '333444'} assert len(sockets) == 0 self.client.connect() self.client.emit('authenticate', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'error'
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() self.user1 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.user2 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user2 is None: self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1111-11-11") self.circle = Circle(name="Mamie") self.circle2 = Circle(name="test") self.linkCircle = UserToCircle(user=self.user1, circle=self.circle, privilege="ADMIN") self.linkCircle2 = UserToCircle(user=self.user2, circle=self.circle) self.conversation = Conversation("test") self.conversation.circle = self.circle self.conversation.device_access = True self.device = Device(name="Papie") self.device2 = Device(name="test") self.device2.circle = self.circle2 self.device2_password = self.device2.get_pre_activation_password() self.device2.activate(self.device2.key) self.device.circle = self.circle self.device_password = self.device.get_pre_activation_password() self.device.activate(self.device.key) self.message = Message(is_user=False) self.message.conversation = self.conversation self.message.device = self.device db.session.commit() self.token1 = authenticate_user(self.api, self.user1, "test") self.token2 = authenticate_user(self.api, self.user2, "test") self.device_token = authenticate_device(self.api, self.device, self.device_password) self.device2_token = authenticate_device(self.api, self.device2, self.device2_password) self.tokenAdmin = authenticate_user(self.api, "*****@*****.**", "PapieNeo2019")
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() self.user1 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") db.session.commit() self.token1 = authenticate_user(self.api, self.user1, "test")
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() db.session.query(UserModel).delete() db.session.commit() new_user = UserModel(email="*****@*****.**", password="******", first_name="first_name", last_name="last_name", birthday="1999-02-02") db.session.add(new_user) db.session.commit()
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing() self.user1 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.user2 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user2 is None: self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1111-11-11") self.user3 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user3 is None: self.user3 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1111-11-11") self.circle = Circle(name="TestConversationinvite") self.link = UserToCircle() self.link.user = self.user1 self.link.circle = self.circle self.link2 = UserToCircle() self.link2.user = self.user2 self.link2.circle = self.circle self.conv = Conversation() self.conv.circle = self.circle self.utc1 = UserToConversation(privilege="ADMIN") self.utc1.user = self.user1 self.utc1.conversation = self.conv self.utc2 = UserToConversation(privilege="STANDARD") self.utc2.user = self.user2 self.utc2.conversation = self.conv db.session.commit() self.token1 = authenticate_user(self.api, self.user1, "test") self.token2 = authenticate_user(self.api, self.user2, "test") self.token3 = authenticate_user(self.api, self.user3, "test")
class SocketioMessageEvents(unittest.TestCase): def setUp(self): neo_config.load_config() neo_config.set_project_variables() self.neo = NeoAPI(neo_config) self.api = self.neo.activate_testing() self.client = SocketIOTestClient(self.neo.app, socketio) self.client2 = SocketIOTestClient(self.neo.app, socketio) self.deviceClient = SocketIOTestClient(self.neo.app, socketio) self.client.disconnect() self.client2.disconnect() self.deviceClient.disconnect() self.user1 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.user2 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user2 is None: self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.circle = Circle(name="Mamie") self.linkCircle = UserToCircle(user=self.user1, circle=self.circle, privilege="ADMIN") self.linkCircle2 = UserToCircle(user=self.user2, circle=self.circle) self.conversation = Conversation("test") self.conversation.device_access = True self.conversation.circle = self.circle self.link = UserToConversation(user=self.user1, conversation=self.conversation, privilege='ADMIN') self.link2 = UserToConversation(user=self.user2, conversation=self.conversation) self.device = Device(name="Papie") self.device.circle = self.circle self.device_password = self.device.get_pre_activation_password() self.device.activate(self.device.key) db.session.commit() self.circle_id = self.circle.id self.conversation_id = self.conversation.id self.token1 = authenticate_user(self.api, self.user1, "test") self.token2 = authenticate_user(self.api, self.user2, "test") self.device_token = authenticate_device(self.api, self.device, self.device_password) self.tokenAdmin = authenticate_user(self.api, "*****@*****.**", "PapieNeo2019") def tearDown(self): self.client.disconnect() self.client2.disconnect() self.deviceClient.disconnect() def test_valid_message(self): data = {'token': self.token1} assert len(sockets) == 0 self.client.connect() self.client2.connect() self.deviceClient.connect() self.client.emit('authenticate', data, json=True) self.client2.emit('authenticate', {'token': self.token2}, json=True) self.deviceClient.emit('authenticate', {'token': self.device_token}, json=True) res1 = self.client.get_received() res2 = self.client2.get_received() res3 = self.deviceClient.get_received() assert len(res1) == 1 assert res1[0]['name'] == 'success' assert len(res2) == 1 assert res2[0]['name'] == 'success' assert len(res3) == 1 assert res3[0]['name'] == 'success' self.client.emit('join_conversation', {'conversation_id': self.conversation_id}, json=True) self.client2.emit('join_conversation', {'conversation_id': self.conversation_id}, json=True) self.deviceClient.emit('join_conversation', {'conversation_id': self.conversation_id}, json=True) res1 = self.client.get_received() res2 = self.client2.get_received() res3 = self.deviceClient.get_received() assert len(res1) == 1 assert res1[0]['name'] == 'success' assert len(res2) == 1 assert res2[0]['name'] == 'success' assert len(res3) == 1 assert res3[0]['name'] == 'success' sock = { 'conversation_id': self.conversation_id, 'text_message': 'test web socket' } self.client.emit('message', sock, json=True) err = self.client.get_received() res = self.client2.get_received() res2 = self.deviceClient.get_received() assert len(err) == 2 assert len(res) == 1 assert len(res2) == 1 self.client.disconnect() self.client2.disconnect() self.deviceClient.disconnect() def test_valid_message_from_device(self): data = {'token': self.token1} assert len(sockets) == 0 self.client.connect() self.client2.connect() self.deviceClient.connect() self.client.emit('authenticate', data, json=True) self.client2.emit('authenticate', {'token': self.token2}, json=True) self.deviceClient.emit('authenticate', {'token': self.device_token}, json=True) res1 = self.client.get_received() res2 = self.client2.get_received() res3 = self.deviceClient.get_received() assert len(res1) == 1 assert res1[0]['name'] == 'success' assert len(res2) == 1 assert res2[0]['name'] == 'success' assert len(res3) == 1 assert res3[0]['name'] == 'success' self.client.emit('join_conversation', {'conversation_id': self.conversation_id}, json=True) self.client2.emit('join_conversation', {'conversation_id': self.conversation_id}, json=True) self.deviceClient.emit('join_conversation', {'conversation_id': self.conversation_id}, json=True) res1 = self.client.get_received() res2 = self.client2.get_received() res3 = self.deviceClient.get_received() assert len(res1) == 1 assert res1[0]['name'] == 'success' assert len(res2) == 1 assert res2[0]['name'] == 'success' assert len(res3) == 1 assert res3[0]['name'] == 'success' sock = { 'conversation_id': self.conversation_id, 'text_message': 'test web socket' } self.deviceClient.emit('message', sock, json=True) err = self.client.get_received() res = self.client2.get_received() res2 = self.deviceClient.get_received() assert len(err) == 1 assert len(res) == 1 assert len(res2) == 2 def test_notif_on_conversation(self): data = {'token': self.token1} assert len(sockets) == 0 self.client.connect() self.client2.connect() self.deviceClient.connect() self.client.emit('authenticate', data, json=True) self.client2.emit('authenticate', {'token': self.token2}, json=True) self.deviceClient.emit('authenticate', {'token': self.device_token}, json=True) res1 = self.client.get_received() res2 = self.client2.get_received() res3 = self.deviceClient.get_received() assert len(res1) == 1 assert res1[0]['name'] == 'success' assert len(res2) == 1 assert res2[0]['name'] == 'success' assert len(res3) == 1 assert res3[0]['name'] == 'success' self.client.emit('join_conversation', {'conversation_id': self.conversation_id}, json=True) self.client2.emit('join_conversation', {'conversation_id': self.conversation_id}, json=True) self.deviceClient.emit('join_conversation', {'conversation_id': self.conversation_id}, json=True) res1 = self.client.get_received() res2 = self.client2.get_received() res3 = self.deviceClient.get_received() assert len(res1) == 1 assert res1[0]['name'] == 'success' assert len(res2) == 1 assert res2[0]['name'] == 'success' assert len(res3) == 1 assert res3[0]['name'] == 'success' json_data = { 'token': self.token1, 'conversation_id': self.conversation_id, 'text_message': 'test web socket' } self.api.post('/message/send', data=json.dumps(json_data), content_type='application/json') err = self.client.get_received() res = self.client2.get_received() res2 = self.deviceClient.get_received() assert len(err) == 1 assert len(res) == 1 assert len(res2) == 1 self.client.disconnect() self.client2.disconnect() self.deviceClient.disconnect()
class SocketioRoomConversation(unittest.TestCase): def setUp(self): neo_config.load_config() neo_config.set_project_variables() self.neo = NeoAPI(neo_config) self.api = self.neo.activate_testing() self.client = SocketIOTestClient(self.neo.app, socketio) self.client.disconnect() self.user1 = db.session.query(UserModel).filter(UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.user2 = db.session.query(UserModel).filter(UserModel.email == "*****@*****.**").first() if self.user2 is None: self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.circle = Circle(name="Mamie") self.linkCircle = UserToCircle(user=self.user1, circle=self.circle, privilege="ADMIN") self.conversation = Conversation("test", device_access=True) self.conversation.device_access = True self.conversation.circle = self.circle self.link2 = UserToConversation(user=self.user2, conversation=self.conversation) self.device = Device(name="Papie") self.device.circle = self.circle self.device_password = self.device.get_pre_activation_password() self.device.activate(self.device.key) db.session.commit() self.circle_id = self.circle.id self.conversation_id = self.conversation.id self.token1 = authenticate_user(self.api, self.user1, "test") self.token2 = authenticate_user(self.api, self.user2, "test") self.device_token = authenticate_device(self.api, self.device, self.device_password) self.tokenAdmin = authenticate_user(self.api, "*****@*****.**", "PapieNeo2019") def tearDown(self): self.client.disconnect() def test_invalid_join_conversation(self): data = { 'token': self.token1 } assert len(sockets) == 0 self.client.connect() self.client.emit('authenticate', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' data = { 'conversation_id': self.conversation_id } self.client.emit('join_conversation', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'error' def test_valid_join_conversation(self): data = { 'token': self.token2 } assert len(sockets) == 0 self.client.connect() self.client.emit('authenticate', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' data = { 'conversation_id': self.conversation_id } self.client.emit('join_conversation', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' def test_valid_device_join_conversation(self): data = { 'token': self.device_token } assert len(sockets) == 0 self.client.connect() self.client.emit('authenticate', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' data = { 'conversation_id': self.conversation_id } self.client.emit('join_conversation', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' def test_device_join_without_conv_access(self): self.conversation.device_access = False db.session.commit() data = { 'token': self.device_token } assert len(sockets) == 0 self.client.connect() self.client.emit('authenticate', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' data = { 'conversation_id': self.conversation_id } self.client.emit('join_conversation', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'error' def test_valid_leave_conversation(self): data = { 'token': self.token2 } assert len(sockets) == 0 self.client.connect() self.client.emit('authenticate', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' data = { 'conversation_id': self.conversation_id } self.client.emit('join_conversation', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' self.client.emit('leave_conversation', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' def test_invalid_leave_conversation(self): data = { 'token': self.token1 } assert len(sockets) == 0 self.client.connect() self.client.emit('authenticate', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success' data = { 'conversation_id': self.conversation_id } self.client.emit('leave_conversation', data, json=True) res = self.client.get_received() assert len(res) == 1 assert res[0]['name'] == 'success'
def setUp(self): neo_config.load_config() neo_config.set_project_variables() neo = NeoAPI(neo_config) self.api = neo.activate_testing()
class SocketioWebrtcEvents(unittest.TestCase): def setUp(self): neo_config.load_config() neo_config.set_project_variables() self.neo = NeoAPI(neo_config) self.api = self.neo.activate_testing() self.client = SocketIOTestClient(self.neo.app, socketio) self.client2 = SocketIOTestClient(self.neo.app, socketio) self.deviceClient = SocketIOTestClient(self.neo.app, socketio) self.client.disconnect() self.client2.disconnect() self.deviceClient.disconnect() self.user1 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user1 is None: self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.user2 = db.session.query(UserModel).filter( UserModel.email == "*****@*****.**").first() if self.user2 is None: self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname", last_name="lastname", birthday="1995-12-12") self.email = self.user2.email self.circle = Circle(name="Mamie") self.linkCircle = UserToCircle(user=self.user1, circle=self.circle, privilege="ADMIN") self.linkCircle2 = UserToCircle(user=self.user2, circle=self.circle) self.conversation = Conversation("test") self.conversation.device_access = True self.conversation.circle = self.circle self.link = UserToConversation(user=self.user1, conversation=self.conversation, privilege='ADMIN') self.link2 = UserToConversation(user=self.user2, conversation=self.conversation) self.device = Device(name="Papie") self.device.circle = self.circle self.device_password = self.device.get_pre_activation_password() self.device.activate(self.device.key) db.session.commit() self.circle_id = self.circle.id self.conversation_id = self.conversation.id self.token1 = authenticate_user(self.api, self.user1, "test") self.token2 = authenticate_user(self.api, self.user2, "test") self.device_token = authenticate_device(self.api, self.device, self.device_password) self.tokenAdmin = authenticate_user(self.api, "*****@*****.**", "PapieNeo2019") def tearDown(self): self.client.disconnect() self.client2.disconnect() self.deviceClient.disconnect() def test_valid_message(self): data = {'token': self.token1} assert len(sockets) == 0 self.client.connect() self.client2.connect() self.deviceClient.connect() self.client.emit('authenticate', data, json=True) self.client2.emit('authenticate', {'token': self.token2}, json=True) self.deviceClient.emit('authenticate', {'token': self.device_token}, json=True) res1 = self.client.get_received() res2 = self.client2.get_received() res3 = self.deviceClient.get_received() assert len(res1) == 1 assert res1[0]['name'] == 'success' assert len(res2) == 1 assert res2[0]['name'] == 'success' assert len(res3) == 1 assert res3[0]['name'] == 'success' self.client.emit('webrtc_credentials') res1 = self.client.get_received() assert len(res1) == 1 def test_valid_forward(self): assert len(sockets) == 0 self.client.connect() self.client2.connect() self.client.emit('authenticate', {'token': self.token1}, json=True) self.client2.emit('authenticate', {'token': self.token2}, json=True) res1 = self.client.get_received() res2 = self.client2.get_received() assert len(res1) == 1 assert res1[0]['name'] == 'success' assert len(res2) == 1 assert res2[0]['name'] == 'success' self.client.emit('webrtc_forward', {'email': self.email}) res1 = self.client.get_received() res2 = self.client2.get_received() assert len(res1) == 1 assert len(res2) == 1