Re: DEFAULT_FILE_STORAGE and tests

2018-09-26 Thread Alessandro Dentella
Ciao Luca!

On Tue, Sep 25, 2018 at 12:29:45PM -0700, Luca Bocchi wrote:
>Already tried with:
>class GeneraliDiscoverRunner(DiscoverRunner):
>def setup_test_environment(self, **kwargs):
>settings.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage'
>super().setup_test_environment(**kwargs)
>?
>otherwise, I'd say to run the test with a custom settings module like
>./manage.py test --settings=test_settings

This seems to be the only viable solution, thanks


>or
>try to override that value in the setUp method of your TestCase class.

I did try this as well and  to my surprise it didn't work eather, even
thought I should spend more time debugging why...

sandro

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20180926122138.GA16185%40bluff.e-den.it.
For more options, visit https://groups.google.com/d/optout.


Re: DEFAULT_FILE_STORAGE and tests

2018-09-25 Thread luca bocchi


Il giorno giovedì 20 settembre 2018 15:25:23 UTC+2, sandro dentella ha 
scritto:
>
> Hi,
>
> I have a storage that create some thumbnail and is declared in some  
> models' fields. It's created inheriting from DEFAULT_FILE_STORAGE and it 
> just works fine both in FileSystemStorage and in Aws. 
>
> For this project need the aws Storage (from Django_storages) but when 
> testing I prefer the local FileSystemStorage, so my TEST_RUNNER sets the 
> desired one as follows:
>
>
>
> from django.conf import settings
> from django.test.runner import DiscoverRunner
>
>
> class GeneraliDiscoverRunner(DiscoverRunner):
> def __init__(self, *args, **kwargs):
> settings.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage'
> super().__init__(*args, **kwargs)
>
> It seems that this changes the Storage in all situations apart from the 
> fields declared in the models via the storage=ThumbnailStorage. I guess 
> when model are read the settings from the runner has not yet been set. Is 
> there a way to set the Storage in due time?
>
>
> Thanks in advance
> sandro
> *:-)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/15789ee1-034f-4658-b739-e92ead413e14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DEFAULT_FILE_STORAGE and tests

2018-09-25 Thread luca bocchi
already tried:

class GeneraliDiscoverRunner(DiscoverRunner):
def setup_test_environment(self, **kwargs):
settings.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage'
super().setup_test_environment(**kwargs)

?

although I'm not sure that settings can be changed at runtime by that.

other options:
- use a custom settings module (already suggested)
- try to make the change in the *setUp* method of your *TestCase* subclass.

additional info about how you're trying to do that would be helpful.

L

Il giorno giovedì 20 settembre 2018 15:59:11 UTC+2, sandro dentella ha 
scritto:
>
>
> Hi Raffaele, 
>
> On Thu, Sep 20, 2018 at 03:36:11PM +0200, Raffaele Salmaso wrote: 
> >On Thu, Sep 20, 2018 at 3:25 PM sandro dentella 
> ><[1]sandro@gmail.com > wrote: 
> > 
> >from django.conf import settings 
> >from django.test.runner import DiscoverRunner 
> >class GeneraliDiscoverRunner(DiscoverRunner): 
> >def __init__(self, *args, **kwargs): 
> >settings.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage' 
> >super().__init__(*args, **kwargs) 
> >It seems that this changes the Storage in all situations apart from 
> the 
> >fields declared in the models via the storage=ThumbnailStorage. I 
> guess 
> >when model are read the settings from the runner has not yet been 
> set. 
> >Is there a way to set the Storage in due time? 
> > 
> >Not really sure, but you can use override_settings from 
> >django.test.utils as 
> >from django.test.utils import override_settings 
> >@override_settings(DEFAULT_FILE_STORAGE='web.storage.TestStorage') 
> >class GeneraliDiscoverRunner(DiscoverRunner): 
> >pass 
> >(override_settings does a lot of other things) 
> >or use a custom DJANGO_SETTINGS_MODULE 
>
> really I've already tried it as well, but it happens the same: it 
> doesn't work for the Storage declared in the models. 
>
> I'd need to set the settings *before* the models are read. It seems 
> that the runner is instantiated too late! 
>
>
> sandro 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ee87371e-f1b4-4ac1-b39b-0ac32fb8f5f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DEFAULT_FILE_STORAGE and tests

2018-09-25 Thread luca bocchi
Already tried with:


class GeneraliDiscoverRunner(DiscoverRunner):
def setup_test_environment(self, **kwargs):
settings.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage'
super().setup_test_environment(**kwargs)

?
otherwise, I'd say to run the test with a custom settings module like 

*./manage.py test --settings=test_settings*

or

try to override that value in the *setUp* method of your *TestCase* class.

L


Il giorno giovedì 20 settembre 2018 15:25:23 UTC+2, sandro dentella ha 
scritto:
>
> Hi,
>
> I have a storage that create some thumbnail and is declared in some  
> models' fields. It's created inheriting from DEFAULT_FILE_STORAGE and it 
> just works fine both in FileSystemStorage and in Aws. 
>
> For this project need the aws Storage (from Django_storages) but when 
> testing I prefer the local FileSystemStorage, so my TEST_RUNNER sets the 
> desired one as follows:
>
>
>
> from django.conf import settings
> from django.test.runner import DiscoverRunner
>
>
> class GeneraliDiscoverRunner(DiscoverRunner):
> def __init__(self, *args, **kwargs):
> settings.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage'
> super().__init__(*args, **kwargs)
>
> It seems that this changes the Storage in all situations apart from the 
> fields declared in the models via the storage=ThumbnailStorage. I guess 
> when model are read the settings from the runner has not yet been set. Is 
> there a way to set the Storage in due time?
>
>
> Thanks in advance
> sandro
> *:-)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2245d393-9cd8-444e-8ddb-3dde294f008a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DEFAULT_FILE_STORAGE and tests

2018-09-20 Thread Alessandro Dentella


Hi Raffaele,

On Thu, Sep 20, 2018 at 03:36:11PM +0200, Raffaele Salmaso wrote:
>On Thu, Sep 20, 2018 at 3:25 PM sandro dentella
><[1]sandro.dente...@gmail.com> wrote:
>
>from django.conf import settings
>from django.test.runner import DiscoverRunner
>class GeneraliDiscoverRunner(DiscoverRunner):
>def __init__(self, *args, **kwargs):
>settings.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage'
>super().__init__(*args, **kwargs)
>It seems that this changes the Storage in all situations apart from the
>fields declared in the models via the storage=ThumbnailStorage. I guess
>when model are read the settings from the runner has not yet been set.
>Is there a way to set the Storage in due time?
>
>Not really sure, but you can use override_settings from
>django.test.utils as
>from django.test.utils import override_settings
>@override_settings(DEFAULT_FILE_STORAGE='web.storage.TestStorage')
>class GeneraliDiscoverRunner(DiscoverRunner):
>pass
>(override_settings does a lot of other things)
>or use a custom DJANGO_SETTINGS_MODULE

really I've already tried it as well, but it happens the same: it
doesn't work for the Storage declared in the models.

I'd need to set the settings *before* the models are read. It seems
that the runner is instantiated too late!


sandro

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20180920135837.GA3690%40bluff.e-den.it.
For more options, visit https://groups.google.com/d/optout.


Re: DEFAULT_FILE_STORAGE and tests

2018-09-20 Thread Raffaele Salmaso
On Thu, Sep 20, 2018 at 3:25 PM sandro dentella 
wrote:

>
>
> from django.conf import settings
> from django.test.runner import DiscoverRunner
>
>
> class GeneraliDiscoverRunner(DiscoverRunner):
> def __init__(self, *args, **kwargs):
> settings.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage'
> super().__init__(*args, **kwargs)
>
> It seems that this changes the Storage in all situations apart from the
> fields declared in the models via the storage=ThumbnailStorage. I guess
> when model are read the settings from the runner has not yet been set. Is
> there a way to set the Storage in due time?
>
> Not really sure, but you can use override_settings from django.test.utils
as

from django.test.utils import override_settings
@override_settings(DEFAULT_FILE_STORAGE='web.storage.TestStorage')
class GeneraliDiscoverRunner(DiscoverRunner):
pass

(override_settings does a lot of other things)

or use a custom DJANGO_SETTINGS_MODULE

-- 
| Raffaele Salmaso
| https://salmaso.org
| https://bitbucket.org/rsalmaso
| https://github.com/rsalmaso

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABgH4JsQ93KtvRqs0F00hoLTp7_M%2BAqrLFn65iTtS%3DeBJ9YQvQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


DEFAULT_FILE_STORAGE and tests

2018-09-20 Thread sandro dentella
Hi,

I have a storage that create some thumbnail and is declared in some  
models' fields. It's created inheriting from DEFAULT_FILE_STORAGE and it 
just works fine both in FileSystemStorage and in Aws. 

For this project need the aws Storage (from Django_storages) but when 
testing I prefer the local FileSystemStorage, so my TEST_RUNNER sets the 
desired one as follows:



from django.conf import settings
from django.test.runner import DiscoverRunner


class GeneraliDiscoverRunner(DiscoverRunner):
def __init__(self, *args, **kwargs):
settings.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage'
super().__init__(*args, **kwargs)

It seems that this changes the Storage in all situations apart from the 
fields declared in the models via the storage=ThumbnailStorage. I guess 
when model are read the settings from the runner has not yet been set. Is 
there a way to set the Storage in due time?


Thanks in advance
sandro
*:-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eab9b4ce-4e07-420e-bc23-4daa3f789641%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.