Exemplo n.º 1
0
 def test_get_non_image_url(self):
     """ Regression test. Make sure that if the file is not an image
         we still get a file's urls without throwing a
         TransformationError.
     """
     instance = ModelWithTextFile(
         text_file=ContentFile('content', name='my_file')
     )
     instance.save()
     with sleuth.watch('urllib.quote') as urllib_quote_watcher:
         with sleuth.detonate('djangae.storage.get_serving_url', TransformationError):
             instance.refresh_from_db()
             instance.text_file.url
             instance.save()
             self.assertTrue(urllib_quote_watcher.called)
Exemplo n.º 2
0
 def test_invalid_sender_address_is_logged(self):
     """ If we use an invalid 'from' address, we want this to be logged. App Engine doesn't
         include the invalid address in its error message, so we have to log it in Djangae.
     """
     invalid_from_address = "*****@*****.**"
     with sleuth.watch("djangae.mail.logger.error") as log_err:
         # The SDK doesn't raise InvalidSenderError, so we have to force it to blow up
         with sleuth.detonate("djangae.mail.aeemail.EmailMessage.send", InvalidSenderError):
             try:
                 send_mail("Subject", "Hello", invalid_from_address, ["*****@*****.**"])
             except InvalidSenderError:
                 pass
         self.assertTrue(log_err.called)
         call_args = log_err.calls[0].args
         # The invalid 'from' address  should be logged somewhere in the args
         args_str = u"".join(unicode(a)for a in call_args)
         self.assertTrue(invalid_from_address in args_str)
Exemplo n.º 3
0
    def start_operation(self, operation, detonate=True):
        # Make a from_state and a to_state to pass to the operation, these can just be the
        # current state of the models
        from_state = ProjectState.from_apps(apps)
        to_state = from_state.clone()
        schema_editor = connection.schema_editor()
        app_label = TestModel._meta.app_label

        # If we just start the operation then it will hang forever waiting for its mapper task to
        # complete, so we won't even be able to call process_task_queues().  So to avoid that we
        # detonate the _wait_until_task_finished method. Then tasks can be processed after that.
        if detonate:
            with sleuth.detonate(
                "djangae.tests.test_migrations.operations.%s._wait_until_task_finished" % operation.__class__.__name__,
                UniqueException
            ):
                try:
                    operation.database_forwards(app_label, schema_editor, from_state, to_state)
                except UniqueException:
                    pass
        else:
            operation.database_forwards(app_label, schema_editor, from_state, to_state)
Exemplo n.º 4
0
    def start_operation(self, operation, detonate=True):
        # Make a from_state and a to_state to pass to the operation, these can just be the
        # current state of the models
        from_state = ProjectState.from_apps(apps)
        to_state = from_state.clone()
        schema_editor = connection.schema_editor()
        app_label = TestModel._meta.app_label

        # If we just start the operation then it will hang forever waiting for its mapper task to
        # complete, so we won't even be able to call process_task_queues().  So to avoid that we
        # detonate the _wait_until_task_finished method. Then tasks can be processed after that.
        if detonate:
            with sleuth.detonate(
                "djangae.tests.test_migrations.operations.%s._wait_until_task_finished" % operation.__class__.__name__,
                UniqueException
            ):
                try:
                    operation.database_forwards(app_label, schema_editor, from_state, to_state)
                except UniqueException:
                    pass
        else:
            operation.database_forwards(app_label, schema_editor, from_state, to_state)
Exemplo n.º 5
0
 def test_transformation_error(self):
     storage = BlobstoreStorage()
     with sleuth.detonate("djangae.storage.get_serving_url", TransformationError):
         self.assertEqual("thing", storage.url("thing"))
Exemplo n.º 6
0
 def test_transformation_error(self):
     storage = BlobstoreStorage()
     with sleuth.detonate('djangae.storage.get_serving_url', TransformationError):
         self.assertIsNone(storage.url('thing'))
Exemplo n.º 7
0
 def test_transformation_error(self):
     storage = BlobstoreStorage()
     with sleuth.detonate('djangae.storage.get_serving_url',
                          TransformationError):
         self.assertIsNone(storage.url('thing'))
Exemplo n.º 8
0
 def test_large_image_error(self):
     storage = BlobstoreStorage()
     with sleuth.detonate('djangae.storage.get_serving_url',
                          LargeImageError):
         self.assertEqual('thing', storage.url('thing'))
Exemplo n.º 9
0
 def test_transaction_errors_are_handled(self):
     with sleuth.detonate(
             'djangae.contrib.locking.models.LockQuerySet.filter',
             transaction.TransactionFailedError):
         lock = Lock.acquire("my_lock", wait=False)
         self.assertIsNone(lock)
Exemplo n.º 10
0
 def test_large_image_error(self):
     storage = BlobstoreStorage()
     with sleuth.detonate('djangae.storage.get_serving_url', LargeImageError):
         self.assertEqual('thing', storage.url('thing'))