def aaa(): """ YowSup2 - Gateway """ from yowsup_gateway import YowsupGateway gateway = YowsupGateway(credentials=("380664761290", "rw/XJQWbcCDpcDjpZ7BL8RItdQo=")) result = gateway.send_messages([ ("380952886976", "Номер Вашего заказа %d\nВаш магазин Кексик." % order.pk) ]) if result.is_success: logger.info( result.inbox, result.outbox, ) # Receive messages result = gateway.receive_messages() if result.is_sucess: logger.info( result.inbox, result.outbox, )
def aaa(): """ YowSup2 - Gateway """ from yowsup_gateway import YowsupGateway gateway = YowsupGateway(credentials=("380664761290", "rw/XJQWbcCDpcDjpZ7BL8RItdQo=")) result = gateway.send_messages([("380952886976", "Номер Вашего заказа %d\nВаш магазин Кексик." % order.pk)]) if result.is_success: print result.inbox, result.outbox # Receive messages result = gateway.receive_messages() if result.is_sucess: print result.inbox, result.outbox
def setUp(self): self.stack = YowsupGateway(("341111111", "password")) stackClassesArr = (GatewayLayer, CoreLayerMock) self.stack._YowStack__stack = stackClassesArr[::-1] self.stack._YowStack__stackInstances = [] self.stack._YowStack__props = {} self.stack._construct() self.mock_layer = self.stack._YowStack__stackInstances[0] self.gateway_layer = self.stack._YowStack__stackInstances[1] self.number = "341234567" self.content = "message test" self.message = (self.number, self.content)
from yowsup_gateway import YowsupGateway # from yowsup.layers.axolotl import YowAxolotlLayer # import logging # logger.setLevel(logging.DEBUG) import logging logger = logging.getLogger('yowsup.stacks.yowstack') logging.basicConfig(level=logging.DEBUG) gateway = YowsupGateway(credentials=("08020661647", "password")) # Send text messages result = gateway.send_messages([("08065982698", "Delebeat weldone")]) # if result.is_success: # print result.inbox, result.outbox # Receive messages # result = gateway.receive_messages() # if result.is_sucess: # print result.inbox, result.outbox
class FunctionalTests(unittest.TestCase): def setUp(self): self.stack = YowsupGateway(("341111111", "password")) stackClassesArr = (GatewayLayer, CoreLayerMock) self.stack._YowStack__stack = stackClassesArr[::-1] self.stack._YowStack__stackInstances = [] self.stack._YowStack__props = {} self.stack._construct() self.mock_layer = self.stack._YowStack__stackInstances[0] self.gateway_layer = self.stack._YowStack__stackInstances[1] self.number = "341234567" self.content = "message test" self.message = (self.number, self.content) def test_configuration_layer_error(self): class IncorrectLayer(object): pass with self.assertRaises(ConfigurationError): YowsupGateway(("341111111", "password"), False, (IncorrectLayer,)) def test_auth_error(self): self.mock_layer.error_auth = True with self.assertRaises(AuthenticationError): self.stack.send_messages([self.message]) self.assertFalse(self.gateway_layer.connected) def test_send_text_message(self): result = self.stack.send_messages([self.message]) self.assertTrue(result.is_success) self.assertEqual(1, len(result.inbox)) self.assertEqual(1, len(result.outbox)) out_message = result.outbox[0] in_ack = result.inbox[0] self.assertEqual(out_message.getBody(), self.content) self.assertEqual(out_message.getTo(), self.number + "@s.whatsapp.net") self.assertEqual(out_message.getType(), "text") self.assertEqual(out_message.getId(), in_ack.getId()) self.assertEqual(out_message.getTo(), in_ack._from) self.assertEqual(out_message.getType(), in_ack.getClass()) def test_send_text_message_not_ok(self): self.mock_layer.error_ack = True with self.assertRaises(ConnectionError): self.stack.send_messages([self.message]) def _queue_thread(self, fn, *args, **kwargs): while not self.gateway_layer.connected: pass fn(*args, **kwargs) def _test_receive(self, receive_action): self.input_thread = threading.Thread(target=self._queue_thread, args=(receive_action,)) self.input_thread.daemon = True self.input_thread.start() result = self.stack.receive_messages() self.assertTrue(result.is_success) return result def test_receive_text_message(self): result = self._test_receive(self.mock_layer.receive_message) self.assertEqual(1, len(result.inbox)) self.assertEqual(1, len(result.outbox)) in_message = result.inbox[0] out_receipt = result.outbox[0] message = text_message_protocol_entity() self.assertEqual(in_message.getBody(), message.getBody()) self.assertEqual(in_message.getFrom(), message.getFrom()) self.assertEqual(in_message.getId(), out_receipt.getId()) def test_receive_receipt(self): result = self._test_receive(self.mock_layer.receive_receipt) self.assertEqual(1, len(result.inbox)) self.assertEqual(1, len(result.outbox)) in_receipt = result.inbox[0] out_ack = result.outbox[0] receipt = receipt_incoming_protocol_entity() self.assertEqual(receipt.getId(), in_receipt.getId()) self.assertEqual(receipt.getFrom(), in_receipt.getFrom()) self.assertEqual(in_receipt.getId(), out_ack.getId()) self.assertEqual(in_receipt.getFrom(), out_ack._to) self.assertEqual(out_ack.getClass(), "receipt")