예제 #1
0
    def test_send_ok_custom_params(self, mock_put_sms):
        service = sms_plusserver.SMSService()
        sms = sms_plusserver.SMS('+4911122233344',
                                 'Hello!',
                                 orig='TEST',
                                 registered_delivery=False,
                                 debug=True,
                                 project='PROJECT2',
                                 encoding='utf-8',
                                 max_parts=3)

        success = service.send(sms, timeout=30, fail_silently=True)

        mock_put_sms.assert_called_once_with(destination='+4911122233344',
                                             text='Hello!',
                                             orig='TEST',
                                             registered_delivery=False,
                                             debug=True,
                                             project='PROJECT2',
                                             encoding='utf-8',
                                             max_parts=3,
                                             timeout=30,
                                             fail_silently=True)
        self.assertTrue(success)
        self.assertIsInstance(sms.put_response, sms_plusserver.SMSResponse)
예제 #2
0
 def test_state_with_put_and_state_response(self):
     sms = sms_plusserver.SMS('+4911122233344', 'Hello!')
     sms.put_response = sms_plusserver.SMSResponse(
         'REQUEST OK\nhandle = d41d8cd98f00b204e9800998ecf8427e')
     sms.state_response = sms_plusserver.SMSResponse(
         'REQUEST OK\nstate = arrived\n')
     self.assertEqual(sms.state, 'arrived')
예제 #3
0
    def test_init_custom_attributes(self):
        destination = '+4911122233344'
        text = 'Hello!'
        custom_orig = 'TEST'
        custom_registered_delivery = False
        custom_debug = True
        custom_project = 'TestProject'
        custom_encoding = 'utf-8'
        custom_max_parts = 3

        sms = sms_plusserver.SMS(
            destination,
            text,
            orig=custom_orig,
            registered_delivery=custom_registered_delivery,
            debug=custom_debug,
            project=custom_project,
            encoding=custom_encoding,
            max_parts=custom_max_parts)

        self.assertEqual(sms.destination, destination)
        self.assertEqual(sms.text, text)
        self.assertEqual(sms.orig, custom_orig)
        self.assertEqual(sms.registered_delivery, custom_registered_delivery)
        self.assertEqual(sms.debug, custom_debug)
        self.assertEqual(sms.project, custom_project)
        self.assertEqual(sms.encoding, custom_encoding)
        self.assertEqual(sms.max_parts, custom_max_parts)
예제 #4
0
    def test_send_default_parameters(self, mock_send):
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')

        sms.send()

        mock_send.assert_called_once_with(sms,
                                          timeout=None,
                                          fail_silently=False)
예제 #5
0
    def test_check_state_custom_parameters(self, mock_check_state):
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')

        sms.check_state(wait=True, timeout=30, fail_silently=True)

        mock_check_state.assert_called_once_with(sms,
                                                 wait=True,
                                                 timeout=30,
                                                 fail_silently=True)
예제 #6
0
    def test_check_state_default_parameters(self, mock_check_state):
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')

        sms.check_state()

        mock_check_state.assert_called_once_with(sms,
                                                 wait=False,
                                                 timeout=None,
                                                 fail_silently=False)
예제 #7
0
    def test_send_custom_service(self, mock_send):
        mock_service = mock.MagicMock()
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')

        sms.send(service=mock_service)

        mock_service.send.assert_called_once_with(sms,
                                                  timeout=None,
                                                  fail_silently=False)
        mock_send.assert_not_called()
예제 #8
0
    def test_check_state_custom_service(self, mock_check_state):
        mock_service = mock.MagicMock()
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')

        sms.check_state(service=mock_service)

        mock_service.check_state.assert_called_once_with(sms,
                                                         wait=False,
                                                         timeout=None,
                                                         fail_silently=False)
        mock_check_state.assert_not_called()
예제 #9
0
    def test_init_default_attributes(self):
        destination = '+4911122233344'
        text = 'Hello!'

        sms = sms_plusserver.SMS(destination, text)

        self.assertEqual(sms.destination, destination)
        self.assertEqual(sms.text, text)
        self.assertIsNone(sms.orig)
        self.assertTrue(sms.registered_delivery)
        self.assertFalse(sms.debug)
        self.assertIsNone(sms.project)
        self.assertIsNone(sms.encoding)
        self.assertIsNone(sms.max_parts)
예제 #10
0
    def test_check_state_service_error(self, mock_check_sms_state):
        service = sms_plusserver.SMSService()
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')
        sms.put_response = sms_plusserver.SMSResponse(
            'REQUEST OK\nhandle = d41d8cd98f00b204e9800998ecf8427e')

        with self.assertRaises(sms_plusserver.RequestError):
            service.check_state(sms)

        mock_check_sms_state.assert_called_once_with(
            handle_id='d41d8cd98f00b204e9800998ecf8427e',
            timeout=None,
            fail_silently=False)
        self.assertIsNone(sms.state_response)
예제 #11
0
    def test_check_state_ok_custom_params(self, mock_check_sms_state):
        service = sms_plusserver.SMSService()
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')
        sms.put_response = sms_plusserver.SMSResponse(
            'REQUEST OK\nhandle = d41d8cd98f00b204e9800998ecf8427e')

        state = service.check_state(sms, timeout=30, fail_silently=True)

        mock_check_sms_state.assert_called_once_with(
            handle_id='d41d8cd98f00b204e9800998ecf8427e',
            timeout=30,
            fail_silently=True)
        self.assertEqual(state, 'arrived')
        self.assertIsInstance(sms.state_response, sms_plusserver.SMSResponse)
예제 #12
0
    def test_repr(self):
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')
        self.assertEqual(repr(sms), '<SMS +4911122233344>')

        sms.put_response = sms_plusserver.SMSResponse(
            'REQUEST OK\nhandle = d41d8cd98f00b204e9800998ecf8427e')
        self.assertEqual(
            repr(sms),
            '<SMS +4911122233344 [d41d8cd98f00b204e9800998ecf8427e]>')

        sms.state_response = sms_plusserver.SMSResponse(
            'REQUEST OK\nstate = processed')
        self.assertEqual(
            repr(sms),
            '<SMS +4911122233344 [d41d8cd98f00b204e9800998ecf8427e] processed>'
        )
예제 #13
0
    def test_send_service_error(self, mock_put_sms):
        service = sms_plusserver.SMSService()
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')

        with self.assertRaises(sms_plusserver.RequestError):
            service.send(sms)

        mock_put_sms.assert_called_once_with(destination='+4911122233344',
                                             text='Hello!',
                                             orig=None,
                                             registered_delivery=True,
                                             debug=False,
                                             project=None,
                                             encoding=None,
                                             max_parts=None,
                                             timeout=None,
                                             fail_silently=False)
        self.assertIsNone(sms.put_response)
예제 #14
0
    def test_send_ok_default_params(self, mock_put_sms):
        service = sms_plusserver.SMSService()
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')

        handle_id = service.send(sms)

        mock_put_sms.assert_called_once_with(destination='+4911122233344',
                                             text='Hello!',
                                             orig=None,
                                             registered_delivery=True,
                                             debug=False,
                                             project=None,
                                             encoding=None,
                                             max_parts=None,
                                             timeout=None,
                                             fail_silently=False)
        self.assertEqual(handle_id, 'd41d8cd98f00b204e9800998ecf8427e')
        self.assertIsInstance(sms.put_response, sms_plusserver.SMSResponse)
예제 #15
0
    def test_send_custom_parameters(self, mock_send):
        sms = sms_plusserver.SMS('+4911122233344', 'Hello!')

        sms.send(timeout=30, fail_silently=True)

        mock_send.assert_called_once_with(sms, timeout=30, fail_silently=True)
예제 #16
0
 def test_state_with_put_response(self):
     sms = sms_plusserver.SMS('+4911122233344', 'Hello!')
     sms.put_response = sms_plusserver.SMSResponse(
         'REQUEST OK\nhandle = d41d8cd98f00b204e9800998ecf8427e')
     self.assertIsNone(sms.state)  # No "state" found in put response
예제 #17
0
 def test_handle_id_with_put_response(self):
     sms = sms_plusserver.SMS('+4911122233344', 'Hello!')
     sms.put_response = sms_plusserver.SMSResponse(
         'REQUEST OK\nhandle = d41d8cd98f00b204e9800998ecf8427e')
     self.assertEqual(sms.handle_id, 'd41d8cd98f00b204e9800998ecf8427e')
예제 #18
0
 def test_state_no_state_response(self):
     sms = sms_plusserver.SMS('+4911122233344', 'Hello!')
     self.assertIsNone(sms.state)
예제 #19
0
 def test_handle_id_no_put_response(self):
     sms = sms_plusserver.SMS('+4911122233344', 'Hello!')
     self.assertIsNone(sms.handle_id)