Exemplo n.º 1
0
    def test_returns_when_record_already_exists(self):
        action = SetupMxRecords('my-user', 'my-key', provider='CLOUDFLARE')

        with patch.object(action, '_driver',
                          new_callable=PropertyMock) as mock_driver:
            mock_driver.iterate_zones.return_value = [
                Zone(id='1',
                     domain='foo.com',
                     type='master',
                     ttl=1,
                     driver=mock_driver),
                Zone(id='2',
                     domain='my-zone',
                     type='master',
                     ttl=1,
                     driver=mock_driver),
            ]
            mock_driver.create_record.side_effect = throw(
                LibcloudError('81057: The record already exists.',
                              mock_driver))

            action('my-domain.my-zone')

            self.assertEqual(mock_driver.iterate_zones.call_count, 1)
            self.assertEqual(mock_driver.create_record.call_count, 1)
Exemplo n.º 2
0
    def test_202(self):
        resource_id = 'eb93fde9-0cc6-4339-b7d6-f6e838e78f1c'
        self.raw_email_storage.fetch_text.side_effect = throw(
            ObjectDoesNotExistError(None, None, None))

        _, status = self._execute_action(resource_id)
        self.assertEqual(status, 202)
Exemplo n.º 3
0
 def given_response_status(cls, mock_build_opener, status, exception):
     mock_opener = Mock()
     mock_response = Mock()
     mock_build_opener.return_value = mock_opener
     if exception:
         mock_opener.open.side_effect = throw(exception)
     else:
         mock_opener.open.return_value = mock_response
         mock_response.getcode.return_value = status
Exemplo n.º 4
0
    def test_no_results(self):
        email = {
            'to': ['*****@*****.**'],
            'from': '*****@*****.**',
            'subject': 'en',
            'body': 'arandomsearch',
            'sent_at': '2020-02-01 21:17'
        }
        self.page_fetch.side_effect = throw(PageError(None, None, None))

        result_email = self._execute_format(email)

        self.assertEqual(result_email['subject'], 'No results')
Exemplo n.º 5
0
    def test_handles_exceptions_when_processing_image(self, mock_pil):
        mock_pil.open.side_effect = throw(IOError())
        handled_errors = []

        def on_error(*args):
            handled_errors.append(args)

        self.givenTestImage()
        input_email = {'body': '<div><h3>test image</h3><img src="http://test-url.png"/></div>'}

        output_email = email_parser.format_inline_images(input_email, on_error)

        self.assertEqual(len(handled_errors), 1)
        self.assertEqual(output_email, input_email)
Exemplo n.º 6
0
    def test_202(self):
        resource_id = 'eb93fde9-0cc6-4339-b7d6-f6e838e78f1c'

        self.raw_email_storage.fetch_text.side_effect = throw(
            ObjectDoesNotExistError(None, None, None))

        _, status = self._execute_action(resource_id)

        self.assertEqual(status, 202)
        self.raw_email_storage.fetch_text.assert_called_once_with(resource_id)
        self.assertFalse(self.raw_email_storage.delete.called)
        self.assertFalse(self.email_storage.store_object.called)
        self.assertFalse(self.pending_storage.store_text.called)
        self.assertFalse(self.email_parser.called)
Exemplo n.º 7
0
    def test_multiple_results(self):
        email = {
            'to': ['*****@*****.**'],
            'from': '*****@*****.**',
            'subject': 'en',
            'body': 'mercury',
            'sent_at': '2020-02-01 21:17'
        }
        self.page_fetch.side_effect = throw(
            DisambiguationError(Mock(options=['article1', 'article2']),
                                'Message'))

        result_email = self._execute_format(email)

        self.assertEqual(result_email['subject'], 'Suggested Searches')
Exemplo n.º 8
0
    def test_handles_race_condition_when_creating_container(self):
        with patch.object(self._storage, '_driver', new_callable=PropertyMock) as driver:
            container = {'get_was_called': False}

            # noinspection PyUnusedLocal
            def get_container(*args, **kwargs):
                if not container['get_was_called']:
                    container['get_was_called'] = True
                    # noinspection PyTypeChecker
                    raise ContainerDoesNotExistError(None, driver, self._container)

                return container

            # noinspection PyTypeChecker
            driver.create_container.side_effect = throw(ContainerAlreadyExistsError(None, driver, self._container))
            driver.get_container.side_effect = get_container

            self.assertIs(self._storage._client._wrapped, container)
Exemplo n.º 9
0
    def test_throws_when_error_is_unknown(self):
        action = SetupMxRecords('my-user', 'my-key', provider='CLOUDFLARE')

        with patch.object(action, '_driver',
                          new_callable=PropertyMock) as mock_driver:
            mock_driver.iterate_zones.return_value = [
                Zone(id='1',
                     domain='foo.com',
                     type='master',
                     ttl=1,
                     driver=mock_driver),
                Zone(id='2',
                     domain='my-zone',
                     type='master',
                     ttl=1,
                     driver=mock_driver),
            ]
            mock_driver.create_record.side_effect = throw(
                LibcloudError('Some unknown error', mock_driver))

            with self.assertRaises(LibcloudError):
                action('my-domain.my-zone')