示例#1
0
 def from_dict(self, request_dict):
     super(ViberMessageRequest, self).from_dict(request_dict)
     self._message = messages.get_message(request_dict['message'])
     self._sender = UserProfile().from_dict(request_dict['sender'])
     self._message_token = request_dict['message_token']
     self._silent = request_dict.get('silent', None)
     self._reply_type = request_dict.get('reply_type', None)
     self._chat_id = request_dict.get('chat_id', None)
     return self
示例#2
0
    def test_handle_conversation_started_request(self):
        arguments = MockArgumentParser()
        client = MockViberBotClient(arguments, viber_client=MockViberApi(None))
        self.assertIsNotNone(client)

        request = ViberConversationStartedRequest()
        request._user = UserProfile(user_id="User123")

        client.handle_conversation_started_request(request)
 def from_dict(self, request_dict):
     super(ViberConversationStartedRequest, self).from_dict(request_dict)
     self._message_token = request_dict['message_token']
     self._type = request_dict['type']
     if 'context' in request_dict:
         self._context = request_dict['context']
     self._user = UserProfile().from_dict(request_dict['user'])
     if 'api_version' in request_dict:
         self._api_version = request_dict['api_version']
     if 'subscribed' in request_dict:
         self._subscribed = request_dict['subscribed']
     return self
示例#4
0
    def test_handle_subscribed_request(self):
        arguments = MockArgumentParser()
        client = MockViberBotClient(arguments, viber_client=MockViberApi(None))
        self.assertIsNotNone(client)

        request = ViberSubscribedRequest()
        request._user = UserProfile(user_id="User123")

        client.handle_subscribed_request(request)

        self.assertIsNotNone(client.test_viber_client)
        self.assertIsNotNone(client.test_viber_client._messages)
        self.assertEqual(1, len(client.test_viber_client._messages))
        self.assertEqual("Thanks for subscribing!",
                         client.test_viber_client._messages[0].text)
示例#5
0
    def test_receive_message(self):
        arguments = MockArgumentParser()
        viber_api = MockViberApi(None)
        client = MockViberBotClient(arguments, viber_client=viber_api)
        self.assertIsNotNone(client)

        request = unittest.mock.Mock()
        request.get_data.return_value = "{}"
        request.headers = {"X-Viber-Content-Signature": "SIGNATURE"}

        return_request = ViberMessageRequest()
        return_request._message = "Hello"
        return_request._sender = UserProfile(user_id="User123")
        viber_api._request = return_request

        client.receive_message(request)
示例#6
0
    def test_handle_message_request(self):
        arguments = MockArgumentParser()
        client = MockViberBotClient(arguments, viber_client=MockViberApi(None))
        self.assertIsNotNone(client)

        request = ViberMessageRequest()
        request._message = "Hello"
        request._sender = UserProfile(user_id="User123")

        client.test_question = "Hi there"

        client.handle_message_request(request)

        self.assertIsNotNone(client.test_viber_client)
        self.assertIsNotNone(client.test_viber_client._messages)
        self.assertEqual(1, len(client.test_viber_client._messages))
        self.assertEqual("Hi there",
                         client.test_viber_client._messages[0].text)
 def from_dict(self, request_dict):
     super(ViberSubscribedRequest, self).from_dict(request_dict)
     self._user = UserProfile().from_dict(request_dict['user'])
     if 'api_version' in request_dict:
         self._api_version = request_dict['api_version']
     return self
	def from_dict(self, request_dict):
		super(ViberMessageRequest, self).from_dict(request_dict)
		self._message = messages.get_message(request_dict['message'])
		self._sender = UserProfile().from_dict(request_dict['sender'])
		self._message_token = request_dict['message_token']
		return self