Check for A Message When Testing with Selenium

2016-04-20 Thread Austin West
I'm attempting to write a Selenium test for my django app that performs a 
custom action in the admin page. If the action is successful, the i use the 
message_user function to send a success message back to the user, e.g. 
"Action successful!". It appears that this message doesn't appear in the 
raw html when the new page is loaded, and as such I can't perform an assert 
that the message is appearing and the action was successful.

I know I could do this using the context/etc. using the built in django 
client, but is it possible to do it using an external web driver like 
Selenium?

Thanks in advance.

-- 
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/a1d36959-b269-4a78-9051-684d7b551415%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to use selenium automated testing in django projects

2016-02-28 Thread Derek
I would separate out the two kinds of testing; one test to check the form 
functionality (and you do not have to use Selenium for this, btw); and one 
test to simulate how the Excel file is processed once it is loaded.  For 
testing Excel, we use pre-created sheets with known, fixed data and test 
that each type/combo is processed correctly.

On Saturday, 27 February 2016 15:23:05 UTC+2, Vikneswaran S J wrote:
>
> I need to use selenium automated testing for django application with input 
> from excel sheet. How to use use this feature? any idea?
>

-- 
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/089ffd20-9ff1-42f9-ba5e-947792f52e3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to use selenium automated testing in django projects

2016-02-27 Thread Dan Tagg
Harry Percival is very good
http://www.obeythetestinggoat.com

Not sure if he covers Excel

Dan
On 27 Feb 2016 13:22, "Vikneswaran S J" <vickyrahul...@gmail.com> wrote:

> I need to use selenium automated testing for django application with input
> from excel sheet. How to use use this feature? any idea?
>
> --
> 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/0868a7b8-652a-40c5-b80f-d56159ad15af%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0868a7b8-652a-40c5-b80f-d56159ad15af%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAPZHCY60busYmHGENCo1u2%3DbsSDjvb7-3EP9K3ZogD1PoOETtg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to use selenium automated testing in django projects

2016-02-27 Thread Vikneswaran S J
I need to use selenium automated testing for django application with input 
from excel sheet. How to use use this feature? any idea?

-- 
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/0868a7b8-652a-40c5-b80f-d56159ad15af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tutorial 5 (Testing) seems to have an error

2016-02-15 Thread Tim Graham
It looks like you have a Python path problem or that your project isn't 
structured correctly such that the model is being registered twice. Does 
that mean anything to you? I'm not sure if you are also new to Python or 
just to Django.

On Monday, February 15, 2016 at 11:16:51 AM UTC-5, Eric Livingston wrote:
>
> I have been walking through the Tutorial for Django, and upon reaching 
> part 5 and introducing the first test case, I get this output (the 
> directory I put the tutorial in is called 'demo')
>
>  
>
> RuntimeError: Model class demo.polls.models.Question doesn't declare an 
> explicit app_label and isn't in an application in INSTALLED_APPS.
>
>  
>
> I tried adding a Meta section to the Question model, after doing some 
> poking around in the docs.
>
>  
>
> class Question(models.Model):
>
> question_text = models.CharField(max_length=200)
>
> pub_date = models.DateTimeField('date published')
>
>  
>
> class Meta:
>
> app_label='polls'
>
>  
>
> But then I get this:
>
>  
>
> RuntimeError: Conflicting 'question' models in application 'polls':  'polls.models.Question'> and .
>
>  
>
> What modifications would I have to make to the standard Tutorial code so 
> the Models are correctly bound to the polls app? Do I have to add something 
> else to the installed_apps besides 'polls.apps.PollsConfig'? That's the 
> only thing the tutorial says to add.
>
>  
>
> Thanks,
>
> Eric
>

-- 
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/7f1db3e4-6f3a-43dc-99e7-59d5d2d1fddc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Tutorial 5 (Testing) seems to have an error

2016-02-15 Thread Eric Livingston


I have been walking through the Tutorial for Django, and upon reaching part 
5 and introducing the first test case, I get this output (the directory I 
put the tutorial in is called 'demo')

 

RuntimeError: Model class demo.polls.models.Question doesn't declare an 
explicit app_label and isn't in an application in INSTALLED_APPS.

 

I tried adding a Meta section to the Question model, after doing some 
poking around in the docs.

 

class Question(models.Model):

question_text = models.CharField(max_length=200)

pub_date = models.DateTimeField('date published')

 

class Meta:

app_label='polls'

 

But then I get this:

 

RuntimeError: Conflicting 'question' models in application 'polls':  and .

 

What modifications would I have to make to the standard Tutorial code so 
the Models are correctly bound to the polls app? Do I have to add something 
else to the installed_apps besides 'polls.apps.PollsConfig'? That's the 
only thing the tutorial says to add.

 

Thanks,

Eric

-- 
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/bf6740d8-3b1b-44de-a396-ab1b95b183c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing the interaction of multiple sites

2016-01-04 Thread Nikolas Stevenson-Molnar
On Monday, January 4, 2016 at 3:39:22 PM UTC-8, Michal Petrucha wrote:
>
> Hi Nikolas, 
>
> Thanks for your suggestion, unfortunately, I don't see how it helps in 
> my case. 
>
> What I'm after is some kind of integration test: when I try to load a 
> page form the relying instance, verify that it gets redirected to the 
> provider, and then it gets redirected back with the correct callback 
> parameters. In both cases I need to actually hit the respective server 
> running a Django app, since it involves side effects (and side 
> conditions), such as whether the user is logged in on the provider, 
> and some in-database state changes to verify that the callback was 
> valid. 
>
> I don't see how mocking a HTTP response would help me with this, but, 
> of course, I may be missing something here. 
>
> Cheers, 
>
> Michal 
>

Sorry, I just misunderstood the question. I was thinking of unit tests, in 
which you'd want to remove as many external components as possible. 

-- 
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/ad81c184-e315-4ada-92f0-23cf7cf86259%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing the interaction of multiple sites

2016-01-04 Thread Michal Petrucha
On Mon, Jan 04, 2016 at 03:22:10PM -0800, Nikolas Stevenson-Molnar wrote:
> HTTPretty may help with this. It will let you mock a response from the 
> second server: https://github.com/gabrielfalcao/httpretty
> 
> _Nik

Hi Nikolas,

Thanks for your suggestion, unfortunately, I don't see how it helps in
my case.

What I'm after is some kind of integration test: when I try to load a
page form the relying instance, verify that it gets redirected to the
provider, and then it gets redirected back with the correct callback
parameters. In both cases I need to actually hit the respective server
running a Django app, since it involves side effects (and side
conditions), such as whether the user is logged in on the provider,
and some in-database state changes to verify that the callback was
valid.

I don't see how mocking a HTTP response would help me with this, but,
of course, I may be missing something here.

Cheers,

Michal

-- 
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/20160104233809.GB20308%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: Testing the interaction of multiple sites

2016-01-04 Thread Nikolas Stevenson-Molnar
HTTPretty may help with this. It will let you mock a response from the 
second server: https://github.com/gabrielfalcao/httpretty

_Nik

On Monday, January 4, 2016 at 2:50:05 PM UTC-8, Michal Petrucha wrote:
>
> Hi folks, 
>
> I'd like to write some tests for a simple redirect-based SSO solution, 
> in which there's one instance of an app responsible for 
> authentication, and all other instances redirect new sessionless users 
> to it, and then expect a redirect callback. Kind of like a simplified 
> version of OAuth in which there's no need for the relying party to 
> make a background request to the identity provider, since the provider 
> and the relying party share the same database. Each instance has its 
> own settings, SITE_ID and such. 
>
> I was thinking about using Selenium with LiveServerTestCase for this; 
> however, I'd need to have both the provider and the relying instance 
> listening at the same time. 
>
> Is there a simple mechanism to have LiveServerTestCase run two 
> separate server threads with different settings? Is there some kind of 
> third-party testing package that can do that? 
>
> Cheers, and have a happy New Year. 
>
> Michal 
>

-- 
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/3a60e98b-5660-4e39-b671-d8a42aa7f3f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing the interaction of multiple sites

2016-01-04 Thread Nikolas Stevenson-Molnar
HTTPretty may help with this. It will let you mock a response from the second 
server: https://github.com/gabrielfalcao/httpretty

_Nik

On 1/4/2016 2:49:34 PM, Michal Petrucha <michal.petru...@konk.org> wrote:
Hi folks,

I'd like to write some tests for a simple redirect-based SSO solution,
in which there's one instance of an app responsible for
authentication, and all other instances redirect new sessionless users
to it, and then expect a redirect callback. Kind of like a simplified
version of OAuth in which there's no need for the relying party to
make a background request to the identity provider, since the provider
and the relying party share the same database. Each instance has its
own settings, SITE_ID and such.

I was thinking about using Selenium with LiveServerTestCase for this;
however, I'd need to have both the provider and the relying instance
listening at the same time.

Is there a simple mechanism to have LiveServerTestCase run two
separate server threads with different settings? Is there some kind of
third-party testing package that can do that?

Cheers, and have a happy New Year.

Michal

--
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/20160104224904.GA20308%40konk.org.
For more options, visit https://groups.google.com/d/optout.

-- 
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/d9f6f506-0fdc-4a92-aa8e-385d486635f8%40getmailbird.com.
For more options, visit https://groups.google.com/d/optout.


Testing the interaction of multiple sites

2016-01-04 Thread Michal Petrucha
Hi folks,

I'd like to write some tests for a simple redirect-based SSO solution,
in which there's one instance of an app responsible for
authentication, and all other instances redirect new sessionless users
to it, and then expect a redirect callback. Kind of like a simplified
version of OAuth in which there's no need for the relying party to
make a background request to the identity provider, since the provider
and the relying party share the same database. Each instance has its
own settings, SITE_ID and such.

I was thinking about using Selenium with LiveServerTestCase for this;
however, I'd need to have both the provider and the relying instance
listening at the same time.

Is there a simple mechanism to have LiveServerTestCase run two
separate server threads with different settings? Is there some kind of
third-party testing package that can do that?

Cheers, and have a happy New Year.

Michal

-- 
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/20160104224904.GA20308%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: testing django migrations

2015-12-27 Thread Gergely Polonkai
I'm also interested in that, except that I'd like to test RunPython steps.
On Dec 28, 2015 12:32 AM, "Dan Tagg"  wrote:

> Hi,
>
> I used this:
> https://github.com/plumdog/django_migration_testcase
>
> It's only worth writing tests if you are modifying code created by
> makemigrations.
>
> Dan
>
> On 27 December 2015 at 10:14, varun naganathan <
> varunnaganathan...@gmail.com> wrote:
>
>> Hi,I wanted to know how am i supposed to test the working of django
>> migrations.As in how the migrations generate the SQL query.Basically I want
>> to inspect how the sql query generated as in the output of "./manage.py
>> sqlmigrate" is being generated.I've generally used "pdb" along wth
>> unittest.TestCase,but for migrations I'm pretty much stuck.Does anyone
>> probably have a sample test they wrote to test the django migrations.
>> Thanks in advance.
>>
>> --
>> 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/b6364f7e-56ab-4682-ad0a-3684e6199c8f%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Wildman and Herring Limited, Registered Office: 52 Great Eastern Street,
> London, EC2A 3EP, Company no: 05766374
>
> --
> 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/CAPZHCY5CJ_9jex%2BnKNi%3DCy2XG9X9zrLS%3DJBW-mUmDoCpK6%2BTPA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CACczBUL7z8M8nPbsAO2jM2EvyMCqxT4JJVGGSvA8MW__a8E6VQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: testing django migrations

2015-12-27 Thread Dan Tagg
Hi,

I used this:
https://github.com/plumdog/django_migration_testcase

It's only worth writing tests if you are modifying code created by
makemigrations.

Dan

On 27 December 2015 at 10:14, varun naganathan  wrote:

> Hi,I wanted to know how am i supposed to test the working of django
> migrations.As in how the migrations generate the SQL query.Basically I want
> to inspect how the sql query generated as in the output of "./manage.py
> sqlmigrate" is being generated.I've generally used "pdb" along wth
> unittest.TestCase,but for migrations I'm pretty much stuck.Does anyone
> probably have a sample test they wrote to test the django migrations.
> Thanks in advance.
>
> --
> 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/b6364f7e-56ab-4682-ad0a-3684e6199c8f%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Wildman and Herring Limited, Registered Office: 52 Great Eastern Street,
London, EC2A 3EP, Company no: 05766374

-- 
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/CAPZHCY5CJ_9jex%2BnKNi%3DCy2XG9X9zrLS%3DJBW-mUmDoCpK6%2BTPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


testing django migrations

2015-12-27 Thread varun naganathan
Hi,I wanted to know how am i supposed to test the working of django 
migrations.As in how the migrations generate the SQL query.Basically I want 
to inspect how the sql query generated as in the output of "./manage.py 
sqlmigrate" is being generated.I've generally used "pdb" along wth 
unittest.TestCase,but for migrations I'm pretty much stuck.Does anyone 
probably have a sample test they wrote to test the django migrations.
Thanks in advance.

-- 
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/b6364f7e-56ab-4682-ad0a-3684e6199c8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do you approach unit testing for pluggable apps?

2015-12-21 Thread Nan
So far I usually just build a sample project that also serves as a 
demonstration of how to use the pluggable app, and use `manage.py test` to 
run the tests inside the pluggable apps test module.  Is this the preferred 
method?  Should a pluggable app's tests stand alone and be runnable outside 
of project context?  If so, how would you handle testing operations that 
require database access?

-- 
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/5dcb2d3b-0e56-44a9-92f1-d857ff9423a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Testing if app has automatically logged out.

2015-12-03 Thread Meg Bledsoe
My teammates copy and pasted this code into an app for our project.
lass AutoLogout:
  def process_request(self, request):
if not request.user.is_authenticated() :
  #Can't log out if not logged in
  return

try:
  if datetime.now() - request.session['last_touch'] > timedelta( 0, 
settings.AUTO_LOGOUT_DELAY * 60, 0):
auth.logout(request)
del request.session['last_touch']
return
except KeyError:
  pass

request.session['last_touch'] = datetime.now()


I'm trying to write a test to make sure this works. So far I've tried a lot 
of things, but I don't have much experience with testing. This is what I 
have, but I don't know how to fix it.

class AutoLogoutTest(unittest.TestCase):

def setUp(self):
self.loggedout = AutoLogout()
self.request = Mock()
self.client = Client()
self.user = User.objects.create_user(username='testuser', 
password='pass')
self.client.login(username='testuser', password='pass')

def test_auto_logout(self):
session['last_touch'] = timedelta(31*60)
response = self.client.get('/logout/', follow=True)
self.assertRedirects(response, '/')
message = list(response.context['messages'])
self.assertEqual(str(message[0]), 'You have successfully logged 
out.')
self.assertNotIn('_auth_user_id', self.client.session)

Any help would be appreciated.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9b85e5e7-fe00-4b46-977b-d1217d3abb35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit testing for apis

2015-11-24 Thread David Palao
Hi,
I was browsing the EuroPython 2015 videos and found a talk titled "TDD
for APIs". I have not watched it, but you might be interested in it:
https://www.youtube.com/watch?v=Okz6agNgaTA=51=PL8uoeex94UhGGUH0mFb-StlZ1WYGWiJfP
Best

2015-11-24 11:27 GMT+01:00 Kishan Mehta <kishanmeh...@gmail.com>:
> Hi All,
>
> How can I write negative unit test cases for api endpoints
> I am using django.tests.TestCase for unit testing.
>
> Thanks,
> Kishan
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d67330b4-e495-4ae3-9898-2d9d980ec6e4%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKUKWz%3D3NreQyh1eCfnwSqy0AcOuESR3mo9gvdbj%3D4L3thJL8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Unit testing for apis

2015-11-24 Thread Kishan Mehta
Hi All,

How can I write negative unit test cases for api endpoints 
I am using django.tests.TestCase for unit testing. 

Thanks,
Kishan

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d67330b4-e495-4ae3-9898-2d9d980ec6e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating the testing db fails (django 1.8.5)

2015-10-15 Thread Uwe Schuerkamp

>
> I solved it myself... looks like I forgot to create the initial migrations 
> for the app. After running
>

python manage.py makemigrations club300
python  manage.py migrate --fake-initial

python manage.py test club300

appears to work fine. Sorry for the noise & thanks for your help!

Uwe

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db479740-90cb-4a3c-b263-8b011464d5ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating the testing db fails (django 1.8.5)

2015-10-15 Thread Uwe Schuerkamp
Here's some more info in case it helps: 

The "manage.py test" call seems to get as far as creating the table 
"django_migrations", then things break. The production DB has several more 
tables (25 in all) I'm not seeing in the output below, so I guess this 
issue must be related to the migrations table in some manner. 

All the best, Uwe


MariaDB [test_club300_owl]> show tables ; 
+-+
| Tables_in_test_club300_owl  |
+-+
| club300_alert   |
| club300_area|
| club300_bird|
| club300_birdcategory|
| club300_birdcategory_birdcategory_birds |
| club300_country |
| club300_location|
| club300_newsitem|
| club300_observation |
| club300_toplist |
| club300_toplist_toplist_birds   |
| club300_userprofile |
| django_migrations   |
+-+
13 rows in set (0.00 sec)




>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1267ddd2-b62b-4509-bd71-b95c6a844375%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating the testing db fails (django 1.8.5)

2015-10-15 Thread Uwe Schuerkamp

>
> Hi Mike,
>

thanks for your quick reply.

I tried deleting the test database, but that didn't help either (actually I 
tried this several times before I posted here, I even set up a "fresh" 
production database  on my test machine and re-imported the live data in 
order to solve the problem).

All the best, 

Uwe

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12e76866-8880-4c10-9ce3-8876d2059a7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating the testing db fails (django 1.8.5)

2015-10-15 Thread Mike Dewhirst

On 14/10/2015 11:34 PM, Uwe Schuerkamp wrote:

Hi folks,

this is my first posting in this group, so I'm sorry in advance if I'm
breaking any rules or missing some vital information.

My setup:Â

Ubuntu Server 14.04.x
Python 2.7.6
Django 1.8.4 (updated to 1.8.5 recently) installed via "pip"
MariaDB 5.5.44

I'm trying to set up a test framework for a little internal project
which I've been working on since the Django 1.3 days. I've recently
migrated the project to Django 1.8.4/5 via Django 1.7, and everything
appears to be working fine.Â

Trying to set up a testing framework for the first time to get out of my
bad "non-testing" habit and increase the test coverage above "0%" for
the first time ever, I've run into a problem when the manage.py script
tries to create the test database (permissions on the MySQL side are ok,
i've tested createdb, dropping, creating and changing tables in the test
db manually):Â

http://pastebin.com/XDRiqaqL


A quick glance at pastebin indicates the error is a failure to delete 
the test database.


Can you manually delete it prior to running the tests? That would skip 
the entire section (apparently) which raises the error.


Mike



I've been googling for quite some time and have tried creating the
migrations via "--fake-initial", but nothing has helped to work around
the problem.Â

I've read it could be some foreign key problem (MariaDB 5.5.x backend),
but I'm at a loss on how to analyze things further except for randomly
reordering my models which seems a bit silly. 8(Â

Thanks in advance for any pointers,Â

Uwe

--
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
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/6d0a3eee-fa06-4ba4-b8ac-5447c073e830%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/6d0a3eee-fa06-4ba4-b8ac-5447c073e830%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/561F4E92.9030705%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Creating the testing db fails (django 1.8.5)

2015-10-14 Thread Uwe Schuerkamp
Hi folks,

this is my first posting in this group, so I'm sorry in advance if I'm 
breaking any rules or missing some vital information.

My setup: 

Ubuntu Server 14.04.x
Python 2.7.6
Django 1.8.4 (updated to 1.8.5 recently) installed via "pip"
MariaDB 5.5.44

I'm trying to set up a test framework for a little internal project which 
I've been working on since the Django 1.3 days. I've recently migrated the 
project to Django 1.8.4/5 via Django 1.7, and everything appears to be 
working fine. 

Trying to set up a testing framework for the first time to get out of my 
bad "non-testing" habit and increase the test coverage above "0%" for the 
first time ever, I've run into a problem when the manage.py script tries to 
create the test database (permissions on the MySQL side are ok, i've tested 
createdb, dropping, creating and changing tables in the test db manually): 

http://pastebin.com/XDRiqaqL

I've been googling for quite some time and have tried creating the 
migrations via "--fake-initial", but nothing has helped to work around the 
problem. 

I've read it could be some foreign key problem (MariaDB 5.5.x backend), but 
I'm at a loss on how to analyze things further except for randomly 
reordering my models which seems a bit silly. 8( 

Thanks in advance for any pointers, 

Uwe

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6d0a3eee-fa06-4ba4-b8ac-5447c073e830%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Live Site to Localhost (Testing)

2015-08-25 Thread Gergely Polonkai
If this is a Django-only thing, you can use manage.py to dump and load your
data, without the SQL dump. The code, I guess, is available from somewhere,
e.g. in a VCS so you just have to clone/checkout.
On 20 Aug 2015 16:40, <bh...@diamondyarn.com> wrote:

> We have a completely developed Django Site running on live, But it never
> had a testing environment. Now, I downloaded all the files of Website and
> download a mysql dump file.
> I want to run this on my local machine windows (Just to push my changes
> here to test before going live).
> I installed all requirements (Python 2.7, Pip, Mysql, Django), and able to
> create a new project and run the server. How do I configure and run the
> downloaded site now?
>
> Your help is highly Appreciated.
>
> Thanks,
> Bhanu.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8ec6f13f-53fb-49e0-b7c2-98be447e7960%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8ec6f13f-53fb-49e0-b7c2-98be447e7960%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUJm1%3DMfoAzxG2Fnwk8KOz2RaAZ1novkERmimOo3bAE%2BBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Live Site to Localhost (Testing)

2015-08-25 Thread Bhadreshsinh Gohil
Dear Bhanu

Put your download sites in your config folder(web directory) and restore
your database.

*Thanks And Regards*

Bhadreshsinh Gohil
<http://about.me/bhadu.gohil>
Asst. Prof.
<http://about.me/bhadu.gohil>
GTU PG School,
<http://about.me/bhadu.gohil>
Mo. No. +91 7600 95 94 93
--
[ GTU PG School is on Social-Media too. Kindly follow us at:
*Facebook:* @Facebook
<https://www.facebook.com/pages/GTU-PG-School/528875657221511> & *Twitter:*
@GTUPGSchool <https://twitter.com/GTUPGSchool> ]
*Website:* GTUPGSchool
<http://knowyourcollege.in/CollegeBasic.aspx?CollegeCode=8211> & *MOODLE:*
@e-learning <http://pgschool.gtu.ac.in/moodle/>

On Thu, Aug 20, 2015 at 8:10 PM, <bh...@diamondyarn.com> wrote:

> We have a completely developed Django Site running on live, But it never
> had a testing environment. Now, I downloaded all the files of Website and
> download a mysql dump file.
> I want to run this on my local machine windows (Just to push my changes
> here to test before going live).
> I installed all requirements (Python 2.7, Pip, Mysql, Django), and able to
> create a new project and run the server. How do I configure and run the
> downloaded site now?
>
> Your help is highly Appreciated.
>
> Thanks,
> Bhanu.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8ec6f13f-53fb-49e0-b7c2-98be447e7960%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8ec6f13f-53fb-49e0-b7c2-98be447e7960%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEAngN%3D%3D89Kv6Mjqu0p4gf72sAewrx5ikaeLHbmyfQRN9aFWqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django Live Site to Localhost (Testing)

2015-08-20 Thread bhanu
We have a completely developed Django Site running on live, But it never 
had a testing environment. Now, I downloaded all the files of Website and 
download a mysql dump file. 
I want to run this on my local machine windows (Just to push my changes 
here to test before going live). 
I installed all requirements (Python 2.7, Pip, Mysql, Django), and able to 
create a new project and run the server. How do I configure and run the 
downloaded site now?  

Your help is highly Appreciated.

Thanks,
Bhanu.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8ec6f13f-53fb-49e0-b7c2-98be447e7960%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Testing Signals

2015-08-11 Thread Grant Means
I have an app that fires a custom signal when a specific method is called. 
I wrote a test that connects to the signal in setUp() and uses a local 
listener function to set a class attribute to True if the handler is 
called. You can see the relevant code here:

https://dpaste.de/mAGw

This works fine if I test the module directly using ./manage.py test  
test_models.py. However if I run test  or simply test the signals 
don't appear to connect. Using PyCharm I stepped through the code and found 
that when I call .connect() in my TestCase, and step into Signal.connect() 
I can see all of the expected receivers on `self.receivers`. 

However if I step into the Signal.send() method when the signal is fired, 
none of the expected receivers are in place. Again, this works if I test 
the module directly just not if I use `test ` or `test`. 

Does anyone have any guidance on how I could get this to work? Thanks!

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8390428d-f5a4-4e51-860f-6e7c1d965e6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-30 Thread Michael Herrmann
I'm very relieved - thanks Tim! If I can help, please let me know.

Best,
Michael

On 30 July 2015 at 17:56, Tim Graham <timogra...@gmail.com> wrote:

> We are working on that solution:
> https://github.com/django/django/pull/5060
>
>
> On Thursday, July 30, 2015 at 7:19:31 AM UTC-4, mic...@herrmann.io wrote:
>>
>> Hi all,
>>
>> I've just been bitten by this new "feature" as well. I completely don't
>> understand this design decision of 1.8. It is very useful to be able to
>> create model classes without having to save them to the database, not just
>> for unit tests but also for experimenting in the shell. The new "feature"
>> breaks this which is a huge PITA, in my opinion.
>>
>> Could the check for RelatedObjectDoesNotExist not be performed in the
>> save(...) method by Django? Then we would get the best of both worlds: You
>> can create models however you like in unit tests or the shell, and at the
>> same time if you erroneously attempt to save a foreign key which doesn't
>> yet exist you would get the exception.
>>
>> I feel strongly about this because it is very much against the ease of
>> use which I like so much about Django. Is this the appropriate forum to
>> request this as a feature for 1.9 (or another future Django version)?
>>
>> Thanks,
>> Michael
>>
>> On Thursday, 16 July 2015 18:37:39 UTC+2, Carl Meyer wrote:
>>>
>>> Hi Roland,
>>>
>>> On 07/16/2015 07:46 AM, Roland Swingler wrote:
>>> >> i'll just say that Django tests don't favor too much into the "unit"
>>> > test spectrum;
>>> >
>>> > That is what I'm seeing - it is the same with rails out of the box as
>>> > well. I guess I'm just curious to know whether:
>>> >
>>> > a) the 'unit' test end of the spectrum is feasible if that's what you
>>> like
>>> > b) what is available in the Django community (if anything, whether
>>> > libraries, 'ways-of-doing-things' etc.) to support this if it is an
>>> > approach one wants to take.
>>>
>>> I also write model tests using unsaved models where possible. I don't
>>> think it has significant test isolation benefits (your tests are still
>>> integrating with most of the ORM), but it does have test-suite speed
>>> benefits!
>>>
>>> I understand why the change was made in 1.8 to disallow assigning an
>>> unsaved object to a ForeignKey/OneToOneField attribute; in production
>>> code that would almost always be a bug. Personally, though, I've never
>>> been bitten by that bug, I'm confident I could easily find and fix such
>>> a bug if I did write it, and I don't want to give up the ability to use
>>> related unsaved models in tests. So I just use my own subclasses of
>>> ForeignKey and OneToOneField with `allow_unsaved_instance_assignment =
>>> True` set on them (essentially reverting the safety change in 1.8). I
>>> haven't attempted to switch it on dynamically for testing; that should
>>> be possible using a setting and a custom subclass, but I wouldn't choose
>>> to do that; differences between test and production behavior should be
>>> minimized.
>>>
>>> Carl
>>>
>>>


-- 
[image: Inline image 1]

Michael Herrmann, MSc
Alser Straße 18/26
1090 Wien
Tel.: +43 699 11 65 16 40
Email: mich...@herrmann.io

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABrKpmDpe1DzPDj0TtC--cLx%3DpuesGF_WbeESj7tkYLAMeTYSA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-30 Thread Tim Graham
We are working on that solution: https://github.com/django/django/pull/5060

On Thursday, July 30, 2015 at 7:19:31 AM UTC-4, mic...@herrmann.io wrote:
>
> Hi all,
>
> I've just been bitten by this new "feature" as well. I completely don't 
> understand this design decision of 1.8. It is very useful to be able to 
> create model classes without having to save them to the database, not just 
> for unit tests but also for experimenting in the shell. The new "feature" 
> breaks this which is a huge PITA, in my opinion.
>
> Could the check for RelatedObjectDoesNotExist not be performed in the 
> save(...) method by Django? Then we would get the best of both worlds: You 
> can create models however you like in unit tests or the shell, and at the 
> same time if you erroneously attempt to save a foreign key which doesn't 
> yet exist you would get the exception.
>
> I feel strongly about this because it is very much against the ease of use 
> which I like so much about Django. Is this the appropriate forum to request 
> this as a feature for 1.9 (or another future Django version)?
>
> Thanks,
> Michael
>
> On Thursday, 16 July 2015 18:37:39 UTC+2, Carl Meyer wrote:
>>
>> Hi Roland, 
>>
>> On 07/16/2015 07:46 AM, Roland Swingler wrote: 
>> >> i'll just say that Django tests don't favor too much into the "unit" 
>> > test spectrum; 
>> > 
>> > That is what I'm seeing - it is the same with rails out of the box as 
>> > well. I guess I'm just curious to know whether: 
>> > 
>> > a) the 'unit' test end of the spectrum is feasible if that's what you 
>> like 
>> > b) what is available in the Django community (if anything, whether 
>> > libraries, 'ways-of-doing-things' etc.) to support this if it is an 
>> > approach one wants to take. 
>>
>> I also write model tests using unsaved models where possible. I don't 
>> think it has significant test isolation benefits (your tests are still 
>> integrating with most of the ORM), but it does have test-suite speed 
>> benefits! 
>>
>> I understand why the change was made in 1.8 to disallow assigning an 
>> unsaved object to a ForeignKey/OneToOneField attribute; in production 
>> code that would almost always be a bug. Personally, though, I've never 
>> been bitten by that bug, I'm confident I could easily find and fix such 
>> a bug if I did write it, and I don't want to give up the ability to use 
>> related unsaved models in tests. So I just use my own subclasses of 
>> ForeignKey and OneToOneField with `allow_unsaved_instance_assignment = 
>> True` set on them (essentially reverting the safety change in 1.8). I 
>> haven't attempted to switch it on dynamically for testing; that should 
>> be possible using a setting and a custom subclass, but I wouldn't choose 
>> to do that; differences between test and production behavior should be 
>> minimized. 
>>
>> Carl 
>>
>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24147436-a0fa-49c8-bd80-e4e74d052319%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-30 Thread michael
Hi all,

I've just been bitten by this new "feature" as well. I completely don't 
understand this design decision of 1.8. It is very useful to be able to 
create model classes without having to save them to the database, not just 
for unit tests but also for experimenting in the shell. The new "feature" 
breaks this which is a huge PITA, in my opinion.

Could the check for RelatedObjectDoesNotExist not be performed in the 
save(...) method by Django? Then we would get the best of both worlds: You 
can create models however you like in unit tests or the shell, and at the 
same time if you erroneously attempt to save a foreign key which doesn't 
yet exist you would get the exception.

I feel strongly about this because it is very much against the ease of use 
which I like so much about Django. Is this the appropriate forum to request 
this as a feature for 1.9 (or another future Django version)?

Thanks,
Michael

On Thursday, 16 July 2015 18:37:39 UTC+2, Carl Meyer wrote:
>
> Hi Roland, 
>
> On 07/16/2015 07:46 AM, Roland Swingler wrote: 
> >> i'll just say that Django tests don't favor too much into the "unit" 
> > test spectrum; 
> > 
> > That is what I'm seeing - it is the same with rails out of the box as 
> > well. I guess I'm just curious to know whether: 
> > 
> > a) the 'unit' test end of the spectrum is feasible if that's what you 
> like 
> > b) what is available in the Django community (if anything, whether 
> > libraries, 'ways-of-doing-things' etc.) to support this if it is an 
> > approach one wants to take. 
>
> I also write model tests using unsaved models where possible. I don't 
> think it has significant test isolation benefits (your tests are still 
> integrating with most of the ORM), but it does have test-suite speed 
> benefits! 
>
> I understand why the change was made in 1.8 to disallow assigning an 
> unsaved object to a ForeignKey/OneToOneField attribute; in production 
> code that would almost always be a bug. Personally, though, I've never 
> been bitten by that bug, I'm confident I could easily find and fix such 
> a bug if I did write it, and I don't want to give up the ability to use 
> related unsaved models in tests. So I just use my own subclasses of 
> ForeignKey and OneToOneField with `allow_unsaved_instance_assignment = 
> True` set on them (essentially reverting the safety change in 1.8). I 
> haven't attempted to switch it on dynamically for testing; that should 
> be possible using a setting and a custom subclass, but I wouldn't choose 
> to do that; differences between test and production behavior should be 
> minimized. 
>
> Carl 
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/acbdd6a3-077e-43d2-bb42-72ecf235bcb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-16 Thread Carl Meyer
Hi Roland,

On 07/16/2015 07:46 AM, Roland Swingler wrote:
>> i'll just say that Django tests don't favor too much into the "unit"
> test spectrum;
> 
> That is what I'm seeing - it is the same with rails out of the box as
> well. I guess I'm just curious to know whether:
> 
> a) the 'unit' test end of the spectrum is feasible if that's what you like
> b) what is available in the Django community (if anything, whether
> libraries, 'ways-of-doing-things' etc.) to support this if it is an
> approach one wants to take.

I also write model tests using unsaved models where possible. I don't
think it has significant test isolation benefits (your tests are still
integrating with most of the ORM), but it does have test-suite speed
benefits!

I understand why the change was made in 1.8 to disallow assigning an
unsaved object to a ForeignKey/OneToOneField attribute; in production
code that would almost always be a bug. Personally, though, I've never
been bitten by that bug, I'm confident I could easily find and fix such
a bug if I did write it, and I don't want to give up the ability to use
related unsaved models in tests. So I just use my own subclasses of
ForeignKey and OneToOneField with `allow_unsaved_instance_assignment =
True` set on them (essentially reverting the safety change in 1.8). I
haven't attempted to switch it on dynamically for testing; that should
be possible using a setting and a custom subclass, but I wouldn't choose
to do that; differences between test and production behavior should be
minimized.

Carl

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55A7DDB4.9080506%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Testing related models without saving

2015-07-16 Thread Roland Swingler
> i'll just say that Django tests don't favor too much into the "unit" test 
spectrum;

That is what I'm seeing - it is the same with rails out of the box as well. 
I guess I'm just curious to know whether:

a) the 'unit' test end of the spectrum is feasible if that's what you like
b) what is available in the Django community (if anything, whether 
libraries, 'ways-of-doing-things' etc.) to support this if it is an 
approach one wants to take.

Thanks,
Roland

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/90102d23-297c-402a-8fe6-bfc3d4ad2f4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-16 Thread Javier Guerra Giraldez
On Thu, Jul 16, 2015 at 8:18 AM, Roland Swingler
<roland.swing...@gmail.com> wrote:
> I understand that the test db uses a different schema (it's the same in
> rails), the point is to be able to run tests isolated from having a database
> at all.


there are several testing styles, each one with different dogmas.
discussions of the adequacy of them can get very heated and
non-productive.

one of these styles states that each test should be perfectly isolated
from any other conceivable source of errors, including the database,
and in fact stopping short of suspecting the base OS itself (usually).

without trying to get too deep in religious dogma, i'll just say that
Django tests don't favor too much into the "unit" test spectrum;
instead they lean somewhat towards the "integration" camp (although
not totally there, either).

in short, the database is considered a required infrastructure
service, and tests usually assume it works as expected.

-- 
Javier

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFkDaoR08cr5DSFH9HOXXxXvdH2QwefE-xuO0yi8hDmf58bSNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-16 Thread Roland Swingler
Hi,

Thanks for the link - I'll investigate that further, especially as to 
whether you can set that dynamically.

I understand that the test db uses a different schema (it's the same in 
rails), the point is to be able to run tests isolated from having a 
database at all.

Thanks,
Roland

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6607ea31-9966-4d67-b43f-1974c17b33cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-16 Thread Bruno A.
This might help 
maybe: 
https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ForeignKey.allow_unsaved_instance_assignment

On Thursday, 16 July 2015 12:21:30 UTC+1, Roland Swingler wrote:
>
> Hi all,
>
> I've very recently come to to Django from a rails background, and 
> struggling to do unit testing of Django models without saving to the 
> database as I'm used to in Rails. Lets say you have 2 linked models, for 
> example User and UserProfileDetails, then in my tests I want to set up the 
> structure and not save any of it:
>
> user = User()
> user.profile_details = UserProfileDetails()
> ...
> # stuff that tests non-persistence related functionality
>
> But I don't seem to be able to do this, because it will raise a 
> RelatedObjectDoesNotExist error, saying UserProfileDetails has no user. 
> Obviously I can get around this by saving the user first, but if I want to 
> not touch the database in tests is there any way I can achieve this?
>
> (also apologies if this has been asked before - I did a quick search of 
> the archives and couldn't find anything).
>
> Thanks in advance,
> Roland
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6fcb1249-6aab-4af6-b583-57ad18364419%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-16 Thread Bruno A.
You did not quote your models, but I assume your UserProfileDetails has a 
OneToOne or ForeignKey relationship with User model.

With Django, you generally need to save the related model before adding it 
to the Foreignkey, as the relationship in UserProfileDetails is using the 
primary key (called id by default) from User instance, which is populated 
when the object is saved.

I don't quite understand why you don't want to save the User model first, 
the unit tests are running on a separate DB schema.

On Thursday, 16 July 2015 12:21:30 UTC+1, Roland Swingler wrote:
>
> Hi all,
>
> I've very recently come to to Django from a rails background, and 
> struggling to do unit testing of Django models without saving to the 
> database as I'm used to in Rails. Lets say you have 2 linked models, for 
> example User and UserProfileDetails, then in my tests I want to set up the 
> structure and not save any of it:
>
> user = User()
> user.profile_details = UserProfileDetails()
> ...
> # stuff that tests non-persistence related functionality
>
> But I don't seem to be able to do this, because it will raise a 
> RelatedObjectDoesNotExist error, saying UserProfileDetails has no user. 
> Obviously I can get around this by saving the user first, but if I want to 
> not touch the database in tests is there any way I can achieve this?
>
> (also apologies if this has been asked before - I did a quick search of 
> the archives and couldn't find anything).
>
> Thanks in advance,
> Roland
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2e820843-6bd6-43aa-98fa-bdbf23574d3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Testing related models without saving

2015-07-16 Thread Roland Swingler
Hi all,

I've very recently come to to Django from a rails background, and 
struggling to do unit testing of Django models without saving to the 
database as I'm used to in Rails. Lets say you have 2 linked models, for 
example User and UserProfileDetails, then in my tests I want to set up the 
structure and not save any of it:

user = User()
user.profile_details = UserProfileDetails()
...
# stuff that tests non-persistence related functionality

But I don't seem to be able to do this, because it will raise a 
RelatedObjectDoesNotExist error, saying UserProfileDetails has no user. 
Obviously I can get around this by saving the user first, but if I want to 
not touch the database in tests is there any way I can achieve this?

(also apologies if this has been asked before - I did a quick search of the 
archives and couldn't find anything).

Thanks in advance,
Roland

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8005dcd3-0fd3-46f1-bc7e-70e59734e386%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How can i keep test data in django testing

2015-05-28 Thread Sub Zero
 

I am using django 1.8 and it says to use --keepdb to save test database

https://docs.djangoproject.com/en/1.8/topics/testing/overview/#the-test-database

I am doing that and database is there but everytime i see it and it is 
empty and has no data in it.

Is there any way that i can preserve that so that i can see whats in there
 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ab63d509-20e7-4b5d-8afe-207a130bf8dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing a new app

2015-05-28 Thread Bill Freeman
If the "new" app doesn't need services from the larger app in order t work,
but rather the other way around, why not leave it separate, and later, just
make it an install requirement for the larger app?

On Thu, May 28, 2015 at 5:54 AM, Klaas Feenstra  wrote:

> Using GIT would be the way of working..
>
> On Thu, May 28, 2015 at 4:24 AM, DZ  wrote:
>
>> Greetings,
>>
>>  I want to start a new app that if it works out I will tie into a larger
>> django app. I do not really want the worlds to mix at the start just in
>> case I need scrap and start it over a few times. I was thinking the best
>> approach would be to create this first as a stand alone app and then when I
>> have the details worked out bring it under the larger app. When I bring it
>> under the larger app I know I would start the data over and use south to
>> bring the worlds together. I am developing under windows, django, python,
>> mysql, and I use south as my db migration tool. Does anyone forsee any
>> problems with this approach? Sorry if the question seems obvious or simple
>> just would like to travel the path of lower resistance as Im working out
>> the features/models of this new app.
>>
>> Thanks for any advice.
>>
>> DZ
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/81557fc6-48c7-4cea-ae9a-c5b49be06f82%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJcivaembcZ%3DNtNxiWP%3Dr8e%3DHTfZfFLn4jYDCedcKiqS_vsb0A%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%2BAj0s2PnCaDnbR1_JU1r4mJh6reoeAOucL1-K6UR%3DTKO80sg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing a new app

2015-05-28 Thread Klaas Feenstra
Using GIT would be the way of working..

On Thu, May 28, 2015 at 4:24 AM, DZ  wrote:

> Greetings,
>
>  I want to start a new app that if it works out I will tie into a larger
> django app. I do not really want the worlds to mix at the start just in
> case I need scrap and start it over a few times. I was thinking the best
> approach would be to create this first as a stand alone app and then when I
> have the details worked out bring it under the larger app. When I bring it
> under the larger app I know I would start the data over and use south to
> bring the worlds together. I am developing under windows, django, python,
> mysql, and I use south as my db migration tool. Does anyone forsee any
> problems with this approach? Sorry if the question seems obvious or simple
> just would like to travel the path of lower resistance as Im working out
> the features/models of this new app.
>
> Thanks for any advice.
>
> DZ
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/81557fc6-48c7-4cea-ae9a-c5b49be06f82%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJcivaembcZ%3DNtNxiWP%3Dr8e%3DHTfZfFLn4jYDCedcKiqS_vsb0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Testing a new app

2015-05-28 Thread DZ
Greetings,

 I want to start a new app that if it works out I will tie into a larger 
django app. I do not really want the worlds to mix at the start just in 
case I need scrap and start it over a few times. I was thinking the best 
approach would be to create this first as a stand alone app and then when I 
have the details worked out bring it under the larger app. When I bring it 
under the larger app I know I would start the data over and use south to 
bring the worlds together. I am developing under windows, django, python, 
mysql, and I use south as my db migration tool. Does anyone forsee any 
problems with this approach? Sorry if the question seems obvious or simple 
just would like to travel the path of lower resistance as Im working out 
the features/models of this new app.

Thanks for any advice.

DZ

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/81557fc6-48c7-4cea-ae9a-c5b49be06f82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing Setup gives 500, but dev server works okay

2015-05-25 Thread Timothy W. Cook
I should add that the actual error is:

selenium.common.exceptions.NoSuchElementException: Message: Unable to
locate element: {"method":"id","selector":"id_login"}

because the main page never loads so it can't find the login button,


On Mon, May 25, 2015 at 12:29 PM, Timothy W. Cook  wrote:

> I have a project that I started, then decided I should apply a TDD
> approach.
>
> Well the user registration and login portion already works but I am
> attempting to add some tests to it.
> The user can register, is redirected back to the main page with a Login
> button.
>
> Here is the test code:
>
> def test_visitor_can_register_and_login_logout(self):
> self.browser.get(self.server_url)
> self.browser.find_element_by_id('id_register').click()
> self.browser.find_element_by_id('id_username').send_keys(TEST_USER)
> self.browser.find_element_by_id('id_email').send_keys(TEST_EMAIL)
>
> self.browser.find_element_by_id('id_password1').send_keys(TEST_PASSWORD)
>
> self.browser.find_element_by_id('id_password2').send_keys(TEST_PASSWORD)
> self.browser.find_element_by_id('submit_registration').click()
> time.sleep(10)
> ## Existing user is invited to login
> self.browser.find_element_by_id('id_login').click()
> self.browser.find_element_by_id('id_login').send_keys(TEST_USER)
>
> self.browser.find_element_by_id('id_password').send_keys(TEST_PASSWORD)
> self.browser.find_element_by_id('log_me_in').click()
>
> ## test user is logged in and can logout
> self.browser.find_element_by_id('id_logout').click()
> self.browser.find_element_by_tag_name('button').click()
> ##redirected back to main page
> self.browser.find_element_by_id('id_login')
>
> I see the main page load, the registration page loads and the inputs are
> filled in.
> When the submit_registion button is clicked I get a 500.  You can see I
> put a sleep in there just so I could see it and verify that the process
> isn't running too fast for the server to respond.
>
> I originally had the registration and login in separate tests but I
> understand that this might require TransactionTestCase ?  I am using
> from django.test import LiveServerTestCase in this class.
>
> I have one other test before that runs fine.
>
> Any ideas?  Tips on troubleshooting this functional test?
>
>
>
>
>
> 
> Timothy Cook
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
> MLHIM http://www.mlhim.org
>
>


-- 


Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3UetYF2s47x3KiY%3D%3DZ8%3DYpCu%3Dc3L10z-XHOxBfUsHnRDw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Testing Setup gives 500, but dev server works okay

2015-05-25 Thread Timothy W. Cook
I have a project that I started, then decided I should apply a TDD
approach.

Well the user registration and login portion already works but I am
attempting to add some tests to it.
The user can register, is redirected back to the main page with a Login
button.

Here is the test code:

def test_visitor_can_register_and_login_logout(self):
self.browser.get(self.server_url)
self.browser.find_element_by_id('id_register').click()
self.browser.find_element_by_id('id_username').send_keys(TEST_USER)
self.browser.find_element_by_id('id_email').send_keys(TEST_EMAIL)

self.browser.find_element_by_id('id_password1').send_keys(TEST_PASSWORD)

self.browser.find_element_by_id('id_password2').send_keys(TEST_PASSWORD)
self.browser.find_element_by_id('submit_registration').click()
time.sleep(10)
## Existing user is invited to login
self.browser.find_element_by_id('id_login').click()
self.browser.find_element_by_id('id_login').send_keys(TEST_USER)

self.browser.find_element_by_id('id_password').send_keys(TEST_PASSWORD)
self.browser.find_element_by_id('log_me_in').click()

## test user is logged in and can logout
self.browser.find_element_by_id('id_logout').click()
self.browser.find_element_by_tag_name('button').click()
##redirected back to main page
self.browser.find_element_by_id('id_login')

I see the main page load, the registration page loads and the inputs are
filled in.
When the submit_registion button is clicked I get a 500.  You can see I put
a sleep in there just so I could see it and verify that the process isn't
running too fast for the server to respond.

I originally had the registration and login in separate tests but I
understand that this might require TransactionTestCase ?  I am using
from django.test import LiveServerTestCase in this class.

I have one other test before that runs fine.

Any ideas?  Tips on troubleshooting this functional test?






Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3Xv1Zz-6uSkUphtNa_kx-YbUbA2MOPn0wOUN-Bpm3sm%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I patch django.core.mail.send_mail for testing?

2015-05-19 Thread Stephen J. Butler
I think you instead want to use self.modify_settings() or
self.override_settings() to change EMAIL_BACKEND to locmem:

https://docs.djangoproject.com/en/1.8/topics/email/#in-memory-backend

Then you can inspect django.core.mail.outbox to verify recipients, message, etc.

On Tue, May 19, 2015 at 7:08 PM, Andrew Farrell  wrote:
> Hi folks,
>
> I'm trying to use mock.patch to test that a particular post-save signal
> kicks off an email. My current approach to this is...
>
>
> from django.test import TestCase
>
> from mock import patch
>
> class RegisterTestCase(TestCase):
> def test_mail_is_sent(self):
> with patch('django.core.mail.send_mail') as mocked_send_mail:
> from register.models import Subscriber  #This test still fails
> if I have the import outside the mock context
> subscriber = Subscriber.objects.create(
> email = 't...@example.com',
> )
> self.assertTrue(mocked_send_mail.called)
> self.assertFalse(subscriber.active)
> self.assertEqual(mocked_send_mail.call_args['recipient_list'],
> 't...@example.com')
>
> def test_patching_mail_works(self):
> with patch('django.core.mail.send_mail') as mocked_send_mail:
> from django.core.mail import send_mail   #This test actually
> fails too if I have the import outside the mock context
> send_mail(subject="foo", message="bar", from_email="Andrew M.
> Farrell ",
> recipient_list = ['Andrew M. Farrell ',])
> self.assertTrue(mocked_send_mail.called)
>
> The first test fails while the second test passes.
> As I understand from reading the mock.patch documentation,
> patch('django.core.mail.send_mail') should cause all references to that
> object to instead referr to an instance of MagicMock.
> However, I can verify by inserting a pdb.set_trace() call into the signal
> handler that send_mail is in fact called during the test and that
> send_mail.func_code is  "//anaconda/envs/taxbrain/lib/python2.7/site-packages/django/core/mail/__init__.py",
> line 41>.
>
> Are there other things that could cause a function to not be mocked
> properly?
> Is my interpretation of the documentation just incorrect?
>
> thank you,
> Andrew
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2By5TLYig%3DiywETuc2pvfe3%3Dajyzc4yhv0QyVWiCj6U16mMH1Q%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD4ANxU4-wW6PCPShNDEti68-_JEmPn%3D7-SEPC3kxPWt9khC3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How do I patch django.core.mail.send_mail for testing?

2015-05-19 Thread Andrew Farrell
Hi folks,

I'm trying to use mock.patch
 to test
that a particular post-save signal kicks off an email. My current approach
to this is...


from django.test import TestCase

from mock import patch

class RegisterTestCase(TestCase):
def test_mail_is_sent(self):
with patch('django.core.mail.send_mail') as mocked_send_mail:
from register.models import Subscriber  #This test still fails
if I have the import outside the mock context
subscriber = Subscriber.objects.create(
email = 't...@example.com',
)
self.assertTrue(mocked_send_mail.called)
self.assertFalse(subscriber.active)
self.assertEqual(mocked_send_mail.call_args['recipient_list'], '
t...@example.com')

def test_patching_mail_works(self):
with patch('django.core.mail.send_mail') as mocked_send_mail:
from django.core.mail import send_mail   #This test actually
fails too if I have the import outside the mock context
send_mail(subject="foo", message="bar", from_email="Andrew M.
Farrell ",
recipient_list = ['Andrew M. Farrell ',])
self.assertTrue(mocked_send_mail.called)

The first test fails while the second test passes.
As I understand from reading the mock.patch

 documentation, patch('django.core.mail.send_mail') should cause all
references to that object to instead referr to an instance of MagicMock.
However, I can verify by inserting a pdb.set_trace() call into the signal
handler that send_mail is in fact called during the test and that
send_mail.func_code is .

Are there other things that could cause a function to not be mocked
properly?
Is my interpretation of the documentation just incorrect?

thank you,
Andrew

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2By5TLYig%3DiywETuc2pvfe3%3Dajyzc4yhv0QyVWiCj6U16mMH1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing request parameters in Django (“+” behaves differently)

2015-04-20 Thread Eneko Illarramendi
Thank you Tom.

Somehow it seemed strange to test this view using client.get('/page/', {
'filter': 'one and two'})
but I get why it is like this.

Cheers,
Eneko


On Monday, April 20, 2015 at 3:30:55 PM UTC+2, Tom Evans wrote:
>
> On Sat, Apr 18, 2015 at 12:13 PM, Eneko Illarramendi 
> <eneko.ill...@gmail.com > wrote: 
> > Previously posted in SO: 
> > 
> http://stackoverflow.com/questions/29703930/testing-request-parameters-in-django-behaves-differently
>  
> > --- 
> > 
> > I have a Django View that uses a query parameter to so some content 
> > filtering. Something like this: 
> > 
> > /page/?filter=one+and+two 
> > /page/?filter=one,or,two 
> > 
> > I have noticed that Django converts the + to a space 
> > (request.GET.get('filter') returns one and two), and I´m OK with that. I 
> > just need to adjust the split() function I use in the View accordingly. 
>
> The arguments in a query string are urlencoded. Spaces are urlencoded 
> as '+'. Django's request.GET is a dict like object with the query 
> string arguments decoded. 
>
> > 
> > But... 
> > 
> > When I try to test this View, and I call: 
> > 
> > from django.test import Client 
> > client = Client() 
> > client.get('/page/', {'filter': 'one+and+two'}) 
>
> The test client takes a dictionary of raw strings, not urlencoded 
> strings. If you like, you are telling it to test the URL 
> '/page/?filter=one%2Band%2Btwo', as '+' is urlencoded as '%2B'. 
>
> Django is consistent, the test client takes raw un-encoded strings, 
> and request.GET delivers raw un-encoded strings. 
>
> Cheers 
>
> Tom 
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/274a6eb9-dfa5-42ba-aff9-d564fad4e0c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing request parameters in Django (“+” behaves differently)

2015-04-20 Thread Tom Evans
On Sat, Apr 18, 2015 at 12:13 PM, Eneko Illarramendi
<eneko.illarrame...@gmail.com> wrote:
> Previously posted in SO:
> http://stackoverflow.com/questions/29703930/testing-request-parameters-in-django-behaves-differently
> ---
>
> I have a Django View that uses a query parameter to so some content
> filtering. Something like this:
>
> /page/?filter=one+and+two
> /page/?filter=one,or,two
>
> I have noticed that Django converts the + to a space
> (request.GET.get('filter') returns one and two), and I´m OK with that. I
> just need to adjust the split() function I use in the View accordingly.

The arguments in a query string are urlencoded. Spaces are urlencoded
as '+'. Django's request.GET is a dict like object with the query
string arguments decoded.

>
> But...
>
> When I try to test this View, and I call:
>
> from django.test import Client
> client = Client()
> client.get('/page/', {'filter': 'one+and+two'})

The test client takes a dictionary of raw strings, not urlencoded
strings. If you like, you are telling it to test the URL
'/page/?filter=one%2Band%2Btwo', as '+' is urlencoded as '%2B'.

Django is consistent, the test client takes raw un-encoded strings,
and request.GET delivers raw un-encoded strings.

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1Lt7hvVA3mzR%2BZ4-srnr3pAvuwSDWRfxe_uV%2B%3D5Zoohig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Testing request parameters in Django (“+” behaves differently)

2015-04-18 Thread Eneko Illarramendi
*Previously posted in 
SO: 
http://stackoverflow.com/questions/29703930/testing-request-parameters-in-django-behaves-differently*
---

I have a Django View that uses a query parameter to so some content 
filtering. Something like this:

/page/?filter=one+and+two/page/?filter=one,or,two

I have noticed that Django converts the + to a space (
request.GET.get('filter') returns one and two), and I´m OK with that. I 
just need to adjust the split() function I use in the View accordingly.

*But...*

When I try to test this View, and I call:

from django.test import Client
client = Client()
client.get('/page/', {'filter': 'one+and+two'})

request.GET.get('filter') returns one+and+two: with plus signs and no 
spaces. Why is this?

I would like to think that Client().get() mimics the browser behaviour, so 
what I would like to understand is why calling client.get('/page/', 
{'filter': 'one+two+three'}) is not like browsing to 
/page/?filter=one+and+two. For testing purposes it should be the same in my 
opinion, and in both cases the view should receive a consistent value for 
filter: be it with + or with spaces. What I don´t get is why there are two 
different behaviours.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ae167e22-3cb6-4201-a301-204a02a3de2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Data migration script populating db table - testing

2015-03-23 Thread Filipe Ximenes
One way to do it is to run all operations, don't call "save" and verify
"manually" if objects are correct.
I don't know about other methods, but if someone else does it would be
great.

On Sun, Mar 22, 2015 at 6:29 AM, Murthy Sandeep 
wrote:

> Hi
>
> I have created an data migration script for populating one of
> app db tables with data from a JSON file.  First I ran
>
> python manage.py makemigrations --empty TPP_App
>
>
>
> (‘TPP_App’ is the name of my app) and then I added a custom
> method called populate_db which will use bulk_create to add
> multiple entries to the table, and then do a save() to write the
> changes to the db.  At the moment the custom method is empty
> because I am still working on it, but the script looks like this right
> now
>
> # -*- coding: utf-8 -*-
> from __future__ import unicode_literals
>
> from django.db import models, migrations
>
> def populate_db( apps, schema_editor ):
> print ‘Populating db from JSON file...'
>
> class Migration(migrations.Migration):
>
> dependencies = [
> ('TPP_App', '0003_auto_20150224_2024'),
> ]
>
> operations = [
>migrations.RunPython( populate_db ),
> ]
>
> How do I test this script to make sure the custom method works
> as expected, before I run it fully?  Can I call this from the interpreter
> and test it with the db API?
>
> At the moment if I do
>
> python manage.py migrate
>
> it reports there are no migrations to apply.
>
> Sandeep
>
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/10767D81-937A-4F08-983A-B055C4AB3982%40sandeepmurthy.is
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 


*Filipe Ximenes*+55 (81) 8245-9204

*Vinta Software Studio*http://www.vinta.com.br

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA-QWB34WORCeaYAYxSN6FewAKJ1xhzVZcJitQFiL7s9eBDS%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Data migration script populating db table - testing

2015-03-22 Thread Murthy Sandeep
Hi

I have created an data migration script for populating one of
app db tables with data from a JSON file.  First I ran

python manage.py makemigrations --empty TPP_App



(‘TPP_App’ is the name of my app) and then I added a custom
method called populate_db which will use bulk_create to add
multiple entries to the table, and then do a save() to write the
changes to the db.  At the moment the custom method is empty
because I am still working on it, but the script looks like this right
now

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

def populate_db( apps, schema_editor ):
print ‘Populating db from JSON file...'

class Migration(migrations.Migration):

dependencies = [
('TPP_App', '0003_auto_20150224_2024'),
]

operations = [
   migrations.RunPython( populate_db ),
]

How do I test this script to make sure the custom method works
as expected, before I run it fully?  Can I call this from the interpreter
and test it with the db API?

At the moment if I do

python manage.py migrate

it reports there are no migrations to apply.

Sandeep


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/10767D81-937A-4F08-983A-B055C4AB3982%40sandeepmurthy.is.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP using GPGMail


Testing migrations

2015-03-20 Thread Gergely Polonkai
Hello,

I just wrote a migration class with RunPython. When I run my tests, my
coverage value drops to to ninety-something percents, because the initial
database created by the test runner is (obviously) empty, thus, my
migration function’s for iteration won’t run.

Is there a way to test such migrations? Not just because of coverage
values, but I’d like to check if my migration function runs correctly.
Basically I create a new column which will have a generated initial value
based on other fields.

Thanks in advance!

Best,
Gergely

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUKBu-8W7hS6b4_EXGnZGGq1jYuDshOU8q4NPbvp%2B_wVOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing Django: testing template at different time

2015-03-18 Thread Zaki Akhmad
On Fri, Mar 13, 2015 at 5:32 AM, Collin Anderson <cmawebs...@gmail.com> wrote:
> Hi,
>
> You could try using freezegun to run the test as if it were a certain time
> of day.
> https://pypi.python.org/pypi/freezegun

Hi Collin,

thanks for the response.
After spent some time, finally I managed to get the testing.

I put my code snippets here
https://gist.github.com/za/2a217c47582737f88259

> Or, you could say something like:
> if 9 <= datetime.datetime.now().hour < 17:
> self.assertContains(response, "It's working time!")
> else:
> self.assertContains(response, "Happy holiday!")
>
> That way it will at least not fail (most of the time :).

Yes, but my mentor said it's not best practice in testing because we
want to test all the condition whenever we execute the test code.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE7Ck-TX83e9Qt_Xm35rqUzWNBP%2Be_QtE5%3Dicz7_Ydx1-spQuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing template context processors

2015-03-17 Thread Gergely Polonkai
Hello,

My processor sets some template variables based on request.user and some
DB/redis query results, which are displayed on each page on a header bar,
so I only need to create a mocked request with user set to something
(AnonymousUser or a valid user object).

I'm already using Mock[2] for middleware testing, funny that I didn't think
of this way (especially as I implemented it today), so thanks for pointing
out!

[2] https://pypi.python.org/pypi/mock
On 17 Mar 2015 17:59, "Carl Meyer" <c...@oddbird.net> wrote:

> Hi Gergely,
>
> On 03/17/2015 10:52 AM, Gergely Polonkai wrote:
> > I wrote a context processor which makes some global variables of mine
> > available for templates. I cannot find a good (cough… any) article on
> > how to test such processors. Could you give me some directions on where
> > to start with writing one?
>
> Writing a unit test for a context processor is quite simple. Construct a
> fake request (you can use RequestFactory, though if your context
> processor only accesses one or two attributes of the request, it might
> be simpler to just build a custom fake or use a library like pretend
> [1]), then call the context processor function in your test, passing in
> the fake request, and assert that the returned dictionary contains what
> you expect.
>
> If your templates require the values from the context processor in order
> to render correctly, you can also write a higher-level integration or
> functional test by using the test client to access a view that renders a
> template that needs the context processor, and then assert the right
> value is found in the rendered HTML.
>
> Carl
>
>   [1] https://pypi.python.org/pypi/pretend
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/55085D7A.5040007%40oddbird.net
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUK0Q%2BriJZ9FNBxDvXAHHUAVNVh8tamCPbqCeQFr__UgTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing template context processors

2015-03-17 Thread Carl Meyer
Hi Gergely,

On 03/17/2015 10:52 AM, Gergely Polonkai wrote:
> I wrote a context processor which makes some global variables of mine
> available for templates. I cannot find a good (cough… any) article on
> how to test such processors. Could you give me some directions on where
> to start with writing one?

Writing a unit test for a context processor is quite simple. Construct a
fake request (you can use RequestFactory, though if your context
processor only accesses one or two attributes of the request, it might
be simpler to just build a custom fake or use a library like pretend
[1]), then call the context processor function in your test, passing in
the fake request, and assert that the returned dictionary contains what
you expect.

If your templates require the values from the context processor in order
to render correctly, you can also write a higher-level integration or
functional test by using the test client to access a view that renders a
template that needs the context processor, and then assert the right
value is found in the rendered HTML.

Carl

  [1] https://pypi.python.org/pypi/pretend

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55085D7A.5040007%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Testing template context processors

2015-03-17 Thread Gergely Polonkai
Hello,

I wrote a context processor which makes some global variables of mine
available for templates. I cannot find a good (cough… any) article on how
to test such processors. Could you give me some directions on where to
start with writing one?

Thanks in advance!

Best,
Gergely

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUJo7m_B9rqU64rA6k7wOb%3DQy0CeBfKkWYdmd2L5Wds1dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Testing Migrations (django 1.7)?

2015-03-16 Thread Sean Briceland
Hi all,
Previous to Django 1.7, I had a nifty solution for testing south Migrations.

I'd basically get a list of migrations for an app via:
migrations = Migrations('some_app')

Then to get the ORM at a given point in migrations:
orm_at_migration = migrations['000X_name_of_migration'].orm()

I could then use call_command to perform a migration and assert using the 
state-based orm's.

In Django 1.7, I haven't found a way to get the ORM at a given point in 
migrations. If anyone has any ideas or experience in this area, I would 
greatly appreciate a nudge in the right direction.

Thanks

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/af578fb2-f36b-4ff2-b4e5-03ce190b0cec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing Django: testing template at different time

2015-03-12 Thread Collin Anderson
Hi,

You could try using freezegun to run the test as if it were a certain time 
of day.
https://pypi.python.org/pypi/freezegun

Or, you could say something like:
if 9 <= datetime.datetime.now().hour < 17:
self.assertContains(response, "It's working time!") 
else:
self.assertContains(response, "Happy holiday!")

That way it will at least not fail (most of the time :).

Collin

On Wednesday, March 11, 2015 at 7:43:35 AM UTC-4, Zaki Akhmad wrote:
>
> Hello, 
>
> I'd like to write a test script for my django app. 
>
> Example, if within business hour, my django app will render: 
> "It's working time!" 
>
> And if not within business hour, my django app will render: 
> "Happy holiday!" 
>
> So the views, will check when the url is accessed. 
>
> How do I write the test script? 
> Following django docs here[1], I started to write my test code. 
>
> from django.test import Client, TestCase 
>
> class TestPage(TestCase): 
> def test_holiday(self): 
> response = self.client.get('/day/') 
> self.assertEqual(response.status_code, 200) 
> self.assertContains(response, "It's working time!") 
>
> This test code will success if I run within business hour. But If I 
> run it not within business hour, the test code will fail. 
>
> * How to write a better test code? 
> * How do I use mock/patch? 
> * How to write test code that will check the within and not within 
> business hour in one file that both will success whenever I run the 
> test code? 
>
> [1]
> https://docs.djangoproject.com/en/1.7/topics/testing/tools/#testing-responses 
>
> Thanks, 
>
> -- 
> Zaki Akhmad 
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3003d453-3d31-4fed-ab9a-eadd40fee8af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Testing Django: testing template at different time

2015-03-11 Thread Zaki Akhmad
Hello,

I'd like to write a test script for my django app.

Example, if within business hour, my django app will render:
"It's working time!"

And if not within business hour, my django app will render:
"Happy holiday!"

So the views, will check when the url is accessed.

How do I write the test script?
Following django docs here[1], I started to write my test code.

from django.test import Client, TestCase

class TestPage(TestCase):
def test_holiday(self):
response = self.client.get('/day/')
self.assertEqual(response.status_code, 200)
self.assertContains(response, "It's working time!")

This test code will success if I run within business hour. But If I
run it not within business hour, the test code will fail.

* How to write a better test code?
* How do I use mock/patch?
* How to write test code that will check the within and not within
business hour in one file that both will success whenever I run the
test code?

[1]https://docs.djangoproject.com/en/1.7/topics/testing/tools/#testing-responses

Thanks,

-- 
Zaki Akhmad

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE7Ck-Ri8KUkhzHddmOqHoWMmm8%2BPBdTFjAt1yQDT9FbSvhnpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 5 Testing

2015-02-21 Thread Gavin Patrick McCoy
Ok. I get you. Thanks very much!

On Saturday, 21 February 2015 11:56:50 UTC, Daniel Roseman wrote:
>
> You're doing this in the shell, which uses your devv database in which you 
> have obviously defined a poll already. 
>
> The docs are taking about running this in a unit test, which would create 
> a blank db without any polls. 
> -- 
> DR.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/408cefd6-b563-43a6-ae3f-29554e8b17cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 5 Testing

2015-02-21 Thread Gavin Patrick McCoy
I got a code 200. Thanks for your reply.

On Saturday, 21 February 2015 11:05:35 UTC, 严超 wrote:
>
> I think the purpose here is to test reverse() function. As long as you 
> got code 200, it's ok whatever html it returns.
> Is it right ?
>
> *Best Regards!*
>
>
> *Chao Yan--About me : http://about.me/chao_yan 
> *
>
> *My twitter: @yanchao727 *
> *My Weibo: http://weibo.com/herewearenow *
> *--*
>  
> 2015-02-21 18:41 GMT+08:00 Gavin Patrick McCoy  >:
>
>> Hi, 
>>
>> I'm on part 5 of the polls tutorial (
>> https://docs.djangoproject.com/en/1.7/intro/tutorial05/) and I am 
>> running Django 1.7 and Python 3.4 on Windows 8. Just want to make sure I'm 
>> on the right track.
>>
>> For the following part of tutorial:
>>
>> >>> # get a response from '/'>>> response = client.get('/')>>> # we should 
>> >>> expect a 404 from that address>>> response.status_code404>>> # on the 
>> >>> other hand we should expect to find something at '/polls/'>>> # we'll 
>> >>> use 'reverse()' rather than a hardcoded URL>>> from 
>> >>> django.core.urlresolvers import reverse>>> response = 
>> >>> client.get(reverse('polls:index'))>>> response.status_code200>>> 
>> >>> response.content'\n\n\nNo polls are available.\n\n' 
>> >>> *<-Not getting this. See below. Seeing What's up?*>>> # note - you 
>> >>> might get unexpected results if your ``TIME_ZONE``>>> # in 
>> >>> ``settings.py`` is not correct. If you need to change it,>>> # you will 
>> >>> also need to restart your shell session>>> from polls.models import 
>> >>> Question>>> from django.utils import timezone>>> # create a Question and 
>> >>> save it>>> q = Question(question_text="Who is your favorite Beatle?", 
>> >>> pub_date=timezone.now())>>> q.save()>>> # check the response once 
>> >>> again>>> response = client.get('/polls/')>>> response.content'\n\n\n
>> >>> \n\nWho is your favorite 
>> >>> Beatle?\n\n\n\n' *Seeing What's up? here too.*
>> >>> # If the following doesn't work, you probably omitted the call to>>> # 
>> >>> setup_test_environment() described above>>> 
>> >>> response.context['latest_question_list'][> >>> Beatle?>] *Seeing What's up? here too*
>>
>>
>> Instead of getting '\n\n\nNo polls are available.\n\n' , the 
>> What's up poll is coming up i.e. b'r\n\t\r\n\t\r\n\t\t> href="/polls/1/">Whatse up?\r\n\t\r\n\t\r\n? The rest of 
>> the code works fine as in adding the Beatles question but the What's up? 
>> question is also coming up along with the Beatles question. Is this ok? Any 
>> help would be greatly appreciated.
>>
>> Thanks,
>>
>> Gavin
>>
>>  -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/fc23070f-8f90-4c4c-925a-94c24d3ee8bf%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24834d06-e86a-4221-af71-5a250715076d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Writing your first Django app, part 5 Testing

2015-02-21 Thread Daniel Roseman
You're doing this in the shell, which uses your devv database in which you have 
obviously defined a poll already.

The docs are taking about running this in a unit test, which would create a 
blank db without any polls.
-- 
DR.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/247cb67c-c2f7-4df6-968a-3cc891455664%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 5 Testing

2015-02-21 Thread 严超
I think the purpose here is to test reverse() function. As long as you got
code 200, it's ok whatever html it returns.
Is it right ?

*Best Regards!*


*Chao Yan--About me : http://about.me/chao_yan
*

*My twitter: @yanchao727 *
*My Weibo: http://weibo.com/herewearenow *
*--*

2015-02-21 18:41 GMT+08:00 Gavin Patrick McCoy :

> Hi,
>
> I'm on part 5 of the polls tutorial (
> https://docs.djangoproject.com/en/1.7/intro/tutorial05/) and I am running
> Django 1.7 and Python 3.4 on Windows 8. Just want to make sure I'm on the
> right track.
>
> For the following part of tutorial:
>
> >>> # get a response from '/'>>> response = client.get('/')>>> # we should 
> >>> expect a 404 from that address>>> response.status_code404>>> # on the 
> >>> other hand we should expect to find something at '/polls/'>>> # we'll use 
> >>> 'reverse()' rather than a hardcoded URL>>> from django.core.urlresolvers 
> >>> import reverse>>> response = client.get(reverse('polls:index'))>>> 
> >>> response.status_code200>>> response.content'\n\n\nNo polls are 
> >>> available.\n\n' *<-Not getting this. See below. Seeing What's 
> >>> up?*>>> # note - you might get unexpected results if your 
> >>> ``TIME_ZONE``>>> # in ``settings.py`` is not correct. If you need to 
> >>> change it,>>> # you will also need to restart your shell session>>> from 
> >>> polls.models import Question>>> from django.utils import timezone>>> # 
> >>> create a Question and save it>>> q = Question(question_text="Who is your 
> >>> favorite Beatle?", pub_date=timezone.now())>>> q.save()>>> # check the 
> >>> response once again>>> response = client.get('/polls/')>>> 
> >>> response.content'\n\n\n\n\n >>> href="/polls/1/">Who is your favorite Beatle?\n\n
> >>> \n\n' *Seeing What's up? here too.*
> >>> # If the following doesn't work, you probably omitted the call to>>> # 
> >>> setup_test_environment() described above>>> 
> >>> response.context['latest_question_list'][ >>> Beatle?>] *Seeing What's up? here too*
>
>
> Instead of getting '\n\n\nNo polls are available.\n\n' , the 
> What's up poll is coming up i.e. b'r\n\t\r\n\t\r\n\t\t href="/polls/1/">Whatse up?\r\n\t\r\n\t\r\n? The rest of 
> the code works fine as in adding the Beatles question but the What's up? 
> question is also coming up along with the Beatles question. Is this ok? Any 
> help would be greatly appreciated.
>
> Thanks,
>
> Gavin
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/fc23070f-8f90-4c4c-925a-94c24d3ee8bf%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALAMvO9Erm_kJGTsE8KwJ3Y44Ssaf%3Dsy1yHaV65ieEx0AdS-sw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Writing your first Django app, part 5 Testing

2015-02-21 Thread Gavin Patrick McCoy
Hi, 

I'm on part 5 of the polls tutorial 
(https://docs.djangoproject.com/en/1.7/intro/tutorial05/) and I am running 
Django 1.7 and Python 3.4 on Windows 8. Just want to make sure I'm on the 
right track.

For the following part of tutorial:

>>> # get a response from '/'>>> response = client.get('/')>>> # we should 
>>> expect a 404 from that address>>> response.status_code404>>> # on the other 
>>> hand we should expect to find something at '/polls/'>>> # we'll use 
>>> 'reverse()' rather than a hardcoded URL>>> from django.core.urlresolvers 
>>> import reverse>>> response = client.get(reverse('polls:index'))>>> 
>>> response.status_code200>>> response.content'\n\n\nNo polls are 
>>> available.\n\n' *<-Not getting this. See below. Seeing What's 
>>> up?*>>> # note - you might get unexpected results if your ``TIME_ZONE``>>> 
>>> # in ``settings.py`` is not correct. If you need to change it,>>> # you 
>>> will also need to restart your shell session>>> from polls.models import 
>>> Question>>> from django.utils import timezone>>> # create a Question and 
>>> save it>>> q = Question(question_text="Who is your favorite Beatle?", 
>>> pub_date=timezone.now())>>> q.save()>>> # check the response once again>>> 
>>> response = client.get('/polls/')>>> response.content'\n\n\n\n\n 
>>>Who is your favorite Beatle?\n
>>> \n\n\n' *Seeing What's up? here too.*
>>> # If the following doesn't work, you probably omitted the call to>>> # 
>>> setup_test_environment() described above>>> 
>>> response.context['latest_question_list'][>> Beatle?>] *Seeing What's up? here too*


Instead of getting '\n\n\nNo polls are available.\n\n' , the What's 
up poll is coming up i.e. b'r\n\t\r\n\t\r\n\t\tWhatse up?\r\n\t\r\n\t\r\n? The rest of the 
code works fine as in adding the Beatles question but the What's up? question 
is also coming up along with the Beatles question. Is this ok? Any help would 
be greatly appreciated.

Thanks,

Gavin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fc23070f-8f90-4c4c-925a-94c24d3ee8bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing posts to S3

2015-02-11 Thread Tom Evans
On Wed, Feb 11, 2015 at 7:36 PM, Lee Hinde  wrote:
> I'm using django storages/boto to push json files to s3 where they are to be
> read by a different app.
>
> I'd like to test the file push by using the Test Client to see if the file
> is present on S3.
>
> client = Client()
> r = client.get(url, content_type="application/json")
>
> In every case, r comes back as:
>
> 
>
> I can take the  'url' and paste it into my browser and get the file.
>
> So, there's something about the process I'm not understanding. Is this not
> what Client is intended for?

No, the test client isn't a client for making web requests, it is a
client that creates phony request objects and simulates the
request/response inside of django itself. No network activity will
take place!

Just open it:

try:
r = urllib.urlopen(url).read()
except IOError:
...

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1%2BZPVagLTGP9t%3Dpk%2B%3Di7%2BssSu%3DL5T9UO2Y8kEhPwVUkgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Testing posts to S3

2015-02-11 Thread Lee Hinde
I'm using django storages/boto to push json files to s3 where they are to
be read by a different app.

I'd like to test the file push by using the Test Client to see if the file
is present on S3.

client = Client()
r = client.get(url, content_type="application/json")

In every case, r comes back as:



I can take the  'url' and paste it into my browser and get the file.

So, there's something about the process I'm not understanding. Is this not
what Client is intended for?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMw-gi%2BMMKXRAVA6XbpSXGmCP38rc2c-c2%3DJQ%3D6bOcPc3A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing reusable application: compatible way

2014-12-07 Thread Carl Meyer
On 12/07/2014 12:59 PM, Matwey V. Kornilov wrote:
> The following code works perfect for me, why the code in the
> documentations so sophisticated?
> 
> def runtests():
> os.environ.setdefault("DJANGO_SETTINGS_MODULE",
> "tests.test_settings")
> 
> try:
> from django import setup
> setup()
> except ImportError:
> pass
> from django.core.management import call_command
> 
> call_command("test","tests.__init__")
> 
> if __name__ == "__main__":
> runtests()

Sure, that works too. I don't think it's significantly simpler than the
documented version, and it's less flexible if you want to customize test
running further.

Carl

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5484C772.5040505%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Testing reusable application: compatible way

2014-12-07 Thread Carl Meyer
On 12/07/2014 02:28 PM, Carl Meyer wrote:
> On 12/07/2014 08:40 AM, Matwey V. Kornilov wrote:
>> I've followed this documentation:
>> https://docs.djangoproject.com/en/1.7/topics/testing/advanced/#using-the-django-test-runner-to-test-reusable-applications
>> and found that it works only for Django 1.7, whereas I would like to
>> have a code snipped working also for 1.5, 1.6.
>>
>> An issue with the runtests.py from the link above thatdjango.setup() has
>> been introduced only in 1.7 and elder version seems to require different
>> way to prepare settings object.
> 
> Older Django versions didn't require any explicit initialization step,
> so all you need to do is check `hasattr(django, 'setup')` and only call
> it if it exists (or you can check the Django version instead, if you
> prefer).
> 
> DiscoverRunner was only introduced in 1.6, so if you want to be
> 1.5-compatible you'll also need a fallback to the old
> DjangoTestSuiteRunner. And note that the format of test labels changed:
> in DjangoTestSuiteRunner it was an app-label, where in DiscoverRunner
> it's a full Python dotted path.

I forgot that the documented example uses django.test.utils.get_runner
instead of directly importing DiscoverRunner. `get_runner` existed
already in 1.5, so that code should work back to 1.5, I would think.

> You can see an example `runtests.py` that accounts for these differences
> here:
> https://github.com/carljm/django-model-utils/blob/master/runtests.py#L34
> 
> Carl
> 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5484C73B.7020902%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Testing reusable application: compatible way

2014-12-07 Thread Carl Meyer
Hi Matwey,

On 12/07/2014 08:40 AM, Matwey V. Kornilov wrote:
> I've followed this documentation:
> https://docs.djangoproject.com/en/1.7/topics/testing/advanced/#using-the-django-test-runner-to-test-reusable-applications
> and found that it works only for Django 1.7, whereas I would like to
> have a code snipped working also for 1.5, 1.6.
> 
> An issue with the runtests.py from the link above thatdjango.setup() has
> been introduced only in 1.7 and elder version seems to require different
> way to prepare settings object.

Older Django versions didn't require any explicit initialization step,
so all you need to do is check `hasattr(django, 'setup')` and only call
it if it exists (or you can check the Django version instead, if you
prefer).

DiscoverRunner was only introduced in 1.6, so if you want to be
1.5-compatible you'll also need a fallback to the old
DjangoTestSuiteRunner. And note that the format of test labels changed:
in DjangoTestSuiteRunner it was an app-label, where in DiscoverRunner
it's a full Python dotted path.

You can see an example `runtests.py` that accounts for these differences
here:
https://github.com/carljm/django-model-utils/blob/master/runtests.py#L34

Carl

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5484C682.1010805%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Testing reusable application: compatible way

2014-12-07 Thread Matwey V. Kornilov

The following code works perfect for me, why the code in the documentations 
so sophisticated?

def runtests():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", 
"tests.test_settings")

try:
from django import setup
setup()
except ImportError:
pass
from django.core.management import call_command

call_command("test","tests.__init__")

if __name__ == "__main__":
runtests()


воскресенье, 7 декабря 2014 г., 18:40:42 UTC+3 пользователь Matwey V. 
Kornilov написал:
>
> Hi,
>
> I've followed this documentation: 
> https://docs.djangoproject.com/en/1.7/topics/testing/advanced/#using-the-django-test-runner-to-test-reusable-applications
> and found that it works only for Django 1.7, whereas I would like to have 
> a code snipped working also for 1.5, 1.6.
>
> An issue with the runtests.py from the link above that django.setup() has 
> been introduced only in 1.7 and elder version seems to require different 
> way to prepare settings object.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3e14ba33-4d84-4d16-afc0-aa02b6b9ce09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Testing reusable application: compatible way

2014-12-07 Thread Matwey V. Kornilov
Hi,

I've followed this documentation: 
https://docs.djangoproject.com/en/1.7/topics/testing/advanced/#using-the-django-test-runner-to-test-reusable-applications
and found that it works only for Django 1.7, whereas I would like to have a 
code snipped working also for 1.5, 1.6.

An issue with the runtests.py from the link above that django.setup() has 
been introduced only in 1.7 and elder version seems to require different 
way to prepare settings object.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aeeb089e-d441-4e86-8f40-674eb97d4d58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit-testing Custom Admin Action, requires request and querysets parameters.

2014-11-25 Thread Azam Alias
Hi Collin,

I apologise for the late update. Didnt get any notifications from your 
reply.

I have solved this issue as per your suggestion. Pasting the solution for 
others' reference. 

Thanks !

from django.test import TestCase
from django.contrib.admin.sites import AdminSite
from batch_apps.models import App
from batch_apps.admin import AppAdmin


class MockRequest(object):
pass

request = MockRequest()


class AppAdminTest(TestCase):

def setUp(self):
self.app_admin = AppAdmin(App, AdminSite())

def test_activate_apps_should_activate_inactive_app(self):
app1 = App.objects.create(name='Inactive App 001', is_active=False)
queryset = App.objects.filter(pk=1)
self.app_admin.activate_apps(request, queryset)
self.assertTrue(App.objects.get(pk=1).is_active)

def test_deactivate_apps_should_deactivate_active_app(self):
app1 = App.objects.create(name='Active App 001', is_active=True)
queryset = App.objects.filter(pk=1)
self.app_admin.deactivate_apps(request, queryset)
self.assertFalse(App.objects.get(pk=1).is_active)



On Thursday, 6 November 2014 01:05:13 UTC+8, Collin Anderson wrote:
>
> Hello,
>
> Would it work to import AppAdmin, instantiate it, and then call the 
> methods in a unit test?
>
> Collin
>  
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f79f583-99a9-4d1c-b384-9733bbf98ec0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Warning / Error when testing with W flag

2014-11-21 Thread Collin Anderson
It looks like it's fixed for python 3.4 on master (the fix will eventually 
be in django 1.8)

On Wednesday, November 19, 2014 10:15:00 AM UTC-5, Carl Meyer wrote:
>
> Hi Daniel, 
>
> On 11/18/2014 02:01 AM, Daniel Grace wrote: 
> > Hi, 
> > I get another warning / error with a test command as follows: 
> >>python -W error manage.py test flow 
> > Traceback (most recent call last): 
> >   File "manage.py", line 8, in  
> > from django.core.management import execute_from_command_line 
> >   File "C:\landy\lib\site-packages\django\core\management\__init__.py", 
> > line 8, 
> > in  
> > from django.apps import apps 
> >   File "C:\landy\lib\site-packages\django\apps\__init__.py", line 1, in 
> >  
> > 
> > from .config import AppConfig   # NOQA 
> >   File "C:\landy\lib\site-packages\django\apps\config.py", line 5, in 
> >  
> > from django.utils.module_loading import module_has_submodule 
> >   File "C:\landy\lib\site-packages\django\utils\module_loading.py", line 
> > 4, in < 
> > module> 
> > import imp 
> >   File "C:\Python34\lib\imp.py", line 32, in  
> > PendingDeprecationWarning) 
> > PendingDeprecationWarning: the imp module is deprecated in favour of 
> > importlib; 
> > see the module's documentation for alternative uses 
>
> This is an issue that needs to be fixed in Django; see 
> https://code.djangoproject.com/ticket/21628 
>
> Until it is fixed in Django, I'm afraid there's not much you can do 
> about it other than ignore these warnings for now. 
>
> Carl 
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/47e2cafe-c135-4ab4-9c91-398e781d136a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Warning / Error when testing with W flag

2014-11-19 Thread Carl Meyer
Hi Daniel,

On 11/18/2014 02:01 AM, Daniel Grace wrote:
> Hi,
> I get another warning / error with a test command as follows:
>>python -W error manage.py test flow
> Traceback (most recent call last):
>   File "manage.py", line 8, in 
> from django.core.management import execute_from_command_line
>   File "C:\landy\lib\site-packages\django\core\management\__init__.py",
> line 8,
> in 
> from django.apps import apps
>   File "C:\landy\lib\site-packages\django\apps\__init__.py", line 1, in
> 
> 
> from .config import AppConfig   # NOQA
>   File "C:\landy\lib\site-packages\django\apps\config.py", line 5, in
> 
> from django.utils.module_loading import module_has_submodule
>   File "C:\landy\lib\site-packages\django\utils\module_loading.py", line
> 4, in <
> module>
> import imp
>   File "C:\Python34\lib\imp.py", line 32, in 
> PendingDeprecationWarning)
> PendingDeprecationWarning: the imp module is deprecated in favour of
> importlib;
> see the module's documentation for alternative uses

This is an issue that needs to be fixed in Django; see
https://code.djangoproject.com/ticket/21628

Until it is fixed in Django, I'm afraid there's not much you can do
about it other than ignore these warnings for now.

Carl



signature.asc
Description: OpenPGP digital signature


Warning / Error when testing with W flag

2014-11-18 Thread Daniel Grace
Hi,
I get another warning / error with a test command as follows:
>python -W error manage.py test flow
Traceback (most recent call last):
  File "manage.py", line 8, in 
from django.core.management import execute_from_command_line
  File "C:\landy\lib\site-packages\django\core\management\__init__.py", 
line 8,
in 
from django.apps import apps
  File "C:\landy\lib\site-packages\django\apps\__init__.py", line 1, in 


from .config import AppConfig   # NOQA
  File "C:\landy\lib\site-packages\django\apps\config.py", line 5, in 

from django.utils.module_loading import module_has_submodule
  File "C:\landy\lib\site-packages\django\utils\module_loading.py", line 4, 
in <
module>
import imp
  File "C:\Python34\lib\imp.py", line 32, in 
PendingDeprecationWarning)
PendingDeprecationWarning: the imp module is deprecated in favour of 
importlib;
see the module's documentation for alternative uses

Any ideas?

Thanks

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/84188383-a868-4dff-b4d7-b38320b2979f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit-testing Custom Admin Action, requires request and querysets parameters.

2014-11-05 Thread Collin Anderson
Hello,

Would it work to import AppAdmin, instantiate it, and then call the methods 
in a unit test?

Collin
 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9338e316-a58c-4ec1-a67a-47c52ffba1bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Unit-testing Custom Admin Action, requires request and querysets parameters.

2014-11-02 Thread Azam Alias
Hi, 

I would like to unit-test the activate_apps( ) and deactivate_apps( ) 
functions below, as low-level as possible.

How could I do this without going through Selenium (FT) route?

In my admin.py:

from django.contrib import admin
from my_app_listing.models import App

class AppAdmin(admin.ModelAdmin):
actions = ['activate_apps', 'deactivate_apps']
list_display = ('name', 'is_active', 'frequency')
fieldsets = [
(None, {'fields': ['name']}),
(None, {'fields': ['is_active']}),
(None, {'fields': ['frequency']}),
('Description', {'fields': ['description'], 'classes': ['collapse'
]}),
]

def activate_apps(self, request, queryset):
queryset.update(is_active=True)
activate_apps.short_description = "Activate selected Apps"

def deactivate_apps(self, request, queryset):
queryset.update(is_active=False)
deactivate_apps.short_description = "Deactivate selected Apps"

admin.site.register(App, AppAdmin)

Thanks in advance

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bea4fcab-8d7c-4613-9454-f5a70181ce5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Tutorial #5 Testing: return Poll.objects.filter( SyntaxError: 'return' outside function

2014-09-16 Thread Andy McKay
You've got a syntax error in your code, likely wherever you have
"return Poll.objects.filter(" in your code.

"Outside a function" likely means that you have not correctly indented
your code, for example if your return has no indentation. Whitespace
in Python is significant and is part of the syntax.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOjXX8bs%2BJqNcGbpFpDOgxg8KnTy0R-x5%2BR2UXTQr36eRg7JBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django Tutorial #5 Testing: return Poll.objects.filter( SyntaxError: 'return' outside function

2014-09-16 Thread Thomas George
Hello,

I was tooling along in the 1.6 tutorial quite well when I came across this 
error, and I'm not sure what to make of it:

return Poll.objects.filter(
SyntaxError: 'return' outside function

The test.py (below) is failing  9 of 12 tests with this error:

*import datetime*

*from django.utils import timezone*
*from django.test import TestCase*
*from django.core.urlresolvers import reverse*

*from polls.models import Poll*


*def create_poll(question, days):*
*"""*
*Creates a poll with the given `question` published the given number of*
*`days` offset to now (negative for polls published in the past,*
*positive for polls that have yet to be published).*
*"""*
*return Poll.objects.create(question=question,*
*   pub_date=timezone.now() + 
datetime.timedelta(days=days))*


*class PollIndexDetailTests(TestCase):*

*def test_detail_view_with_a_future_poll(self):*
*"""*
*The detail view of a poll with a pub_date in the future should*
*return a 404 not found.*
*"""*
*future_poll = create_poll(question='Future poll.', days=5)*
*future_poll.choice_set.create(choice_text='Choice 1', votes=0)*
*future_poll.choice_set.create(choice_text='Choice 2', votes=0)*
*response = self.client.get(reverse('polls:detail', 
args=(future_poll.id,)))*
*self.assertEqual(response.status_code, 404)*

*def test_detail_view_with_a_past_poll(self):*
*"""*
*The detail view of a poll with a pub_date in the past should 
display*
*the poll's question.*
*"""*
*past_poll = create_poll(question='Past Poll.', days=-5)*
*past_poll.choice_set.create(choice_text='Choice 1', votes=0)*
*past_poll.choice_set.create(choice_text='Choice 2', votes=0)*
*response = self.client.get(reverse('polls:detail', 
args=(past_poll.id,)))*
*self.assertContains(response, past_poll.question, status_code=200)*


*class PollIndexResultsTests(TestCase):*

*def test_results_view_with_a_future_poll(self):*
*"""*
*The results view of a poll with a pub_date in the future should*
*return a 404 not found.*
*"""*
*future_poll = create_poll(question='Future poll.', days=5)*
*future_poll.choice_set.create(choice_text='Choice 1', votes=0)*
*future_poll.choice_set.create(choice_text='Choice 2', votes=0)*
*response = self.client.get(reverse('polls:results', 
args=(future_poll.id,)))*
*self.assertEqual(response.status_code, 404)*


*def test_results_view_with_a_past_poll(self):*
*"""*
*The results view of a poll with a pub_date in the past should 
display*
*the poll's question.*
*"""*
*past_poll = create_poll(question='Past Poll.', days=-5)*
*past_poll.choice_set.create(choice_text='Choice 1', votes=0)*
*past_poll.choice_set.create(choice_text='Choice 2', votes=0)*
*response = self.client.get(reverse('polls:results', 
args=(past_poll.id,)))*
*self.assertContains(response, past_poll.question, status_code=200)*


*class PollViewTests(TestCase):*

*def test_index_view_with_no_polls(self):*
*"""*
*If no polls exist, an appropriate message should be displayed.*
*"""*
*response = self.client.get(reverse('polls:index'))*
*self.assertEqual(response.status_code, 200)*
*self.assertContains(response, "No polls are available.")*
*self.assertQuerysetEqual(response.context['latest_polls'], [])*

*def test_index_view_with_a_past_poll(self):*
*"""*
*Polls with a pub_date in the past should be displayed on the index 
page.*
*"""*
*create_poll(question="Past poll.", days=-30)*
*response = self.client.get(reverse('polls:index'))*
*self.assertQuerysetEqual(*
*response.context['latest_polls'],*
*['']*
*)*

*def test_index_view_with_a_future_poll(self):*
*"""*
*Polls with a pub_date in the future should not be displayed on the*
*index page.*
*"""*
*create_poll(question="Future poll.", days=30)*
*response = self.client.get(reverse('polls:index'))*
*self.assertContains(response, "No polls are available.", 
status_code=200)*
*self.assertQuerysetEqual(response.context['latest_polls'], [])*

*def test_index_view_with_future_poll_and_past_poll(self):*
*"""*
*Even if both past and future polls exist, only past polls should 
be*
*displayed.*
*"""*
*create_poll(question="Past poll.", days=-30)*
*create_poll(question="Future poll.", days=30)*
*response = self.client.get(reverse('polls:index'))*
*self.assertQuerysetEqual(*
*response.context['latest_polls'],*
*['']*
*)*


*def test_index_view_with_two_past_polls(self):*
*"""*
*The polls 

Django testing hooks

2014-09-03 Thread Andreas Kuhne
Hi all,

When running django tests (django 1.6) is it possible to run a specific
command before the tests and run a command on failure and on success?

I have bought a blink1 (http://blink1.thingm.com/) and would like it to
change colour depending on the results of the tests. Is this possible?

Regards,

Andréas

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALXYUb%3DgBYxWzXwp-iDhhZ1-pYO0FMSOD7zRXztPz2gkGbXbbw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit testing - self.assertEqual("Break it!", resp.content)

2014-07-07 Thread Pepsodent Cola
Hi,
I have been using assertEqual lately in my unit testing to deliberately 
make coverage break.  By comparing *Something False* with the 
complete HTML returned (*resp.content*).

self.assertEqual("Something False", *resp.content*)

In order to reveal and debug these 3 links.

self.assertNotContains(resp, 'Documentation')
self.assertNotContains(resp, 'Change 
password')
self.assertNotContains(resp, 'Log out')


But the unit test debug output of the complete HTML returned doesn't reveal 
those 3 links.  Why is that?

unit test output
http://dpaste.com/23XGR4M.txt

Compared to the HTML returned that I can see by manually checking the 
source page from my browser.

html source page
http://dpaste.com/0PCZJ0D

 Welcome, joe. 


*Documentation / Change password / Log out *



Is there something wrong with my overridden template file?  Where I have 
removed *{% block userlinks %}* in order to reveal Django admins above 3 
default links.

password_reset_form.html
http://dpaste.com/0T3N3JK

{% extends "admin/base_site.html" %}
{% load i18n %}





*{% comment %}{% block userlinks %}{% trans "Change password" %} / {% trans "Log out" %}{% endblock %}{% 
endcomment %}*


{% comment %}
{% block breadcrumbs %}

{% trans "Home" %}
 {% trans "Password reset" %}

{% endblock %}
{% endcomment %}

{% block title %}{% trans "Password reset - v.2" %}{% endblock %}


{% block content %}
{% trans "Password reset" %}
{% trans "Forgotten your password? Enter your email address below, and 
we'll email instructions for setting a new one." %}

{% csrf_token %}
{{ form.email.errors }}
{% trans "Email address:" %} {{ form.email 
}} 

{% endblock %}












On Monday, July 7, 2014 6:08:20 AM UTC+2, mitesh_django wrote:
>
> Hi,
>
> You are trying to compare  break it!  with the complete HTML 
> returned. Instead of assertEqual, use assertIn.
>
> self.assertIn("Break it!", resp.content)
>
> Regards, 
> Mitesh
> On 7 Jul 2014 01:44, "Pepsodent Cola" <pepsod...@gmail.com > 
> wrote:
>
>> When I run this unit test to make it break so it can output a bunch of 
>> html data.
>>
>> self.assertEqual("Break it!", *resp.content*)
>>
>>
>> test.py
>> # Reset password no login
>>
>> def test_Reset_no_login(self):
>> self.assertTrue(isinstance(self.user, User))
>> login = self.client.login(username='captain', password='america')
>>
>> self.assertEqual("Profile", *resp.content*)
>>
>> self.assertNotContains(resp, '> href="/admin/doc/">Documentation')
>> self.assertNotContains(resp, '> href="/admin/password_change/">Change password')
>> self.assertNotContains(resp, 'Log out')
>>
>>
>>
>> Then I can't find these html tags in unit test's *resp.content* but when 
>> I manually check the html source page from the web browser then I see those 
>> 3 html tags.
>> Why isn't unit test *resp.content* output displaying these 3 html lines?
>>
>>
>> html source page
>> http://dpaste.com/0PCZJ0D
>>
>>  Welcome, joe. 
>>
>>
>> *Documentation / > href="/admin/password_change/">Change password / > href="/admin/logout/">Log out *
>> 
>>
>>
>> unit test output
>> http://dpaste.com/23XGR4M.txt
>>
>> ==
>> FAIL: test_Reset_no_login (userprofile.tests.PasswordResetTest)
>> --
>> Traceback (most recent call last):
>>   File "/home/Python/Projects/Navi/Django/navi/userprofile/tests.py", 
>> line 132, in test_Reset_no_login
>>
>> self.assertEqual("Profile", resp.content)
>>
>> AssertionError: 'Profile' != '\n> lang="en-us" >\n\nPassword reset - v.2\n> rel="stylesheet" type="text/css" href="/static/admin/css/base.css" 
>> />\n\n\n\n> type="text/javascript">window.__admin_media_prefix__ = 
>> "/static/admin/";\n\n> />\n\n\n\n\n\n\n> id="container">\n\n\n\n> id="header">\n\n\n> id="site-name">Navi administration - v.1\n\n\n
>> \nAdmin navigation\n\n\n
>> \n\nHome\n\n
>> \n\n\n\n\n\n\n\n\n
>> \n\n\n\nPassword 
>> reset\nForgotten your password? Enter your email address below, and 
>> we\'ll email instructions for set

Re: Unit testing - self.assertEqual("Break it!", resp.content)

2014-07-06 Thread Mitesh Patel
Hi,

You are trying to compare  break it!  with the complete HTML
returned. Instead of assertEqual, use assertIn.

self.assertIn("Break it!", resp.content)

Regards,
Mitesh
On 7 Jul 2014 01:44, "Pepsodent Cola"  wrote:

> When I run this unit test to make it break so it can output a bunch of
> html data.
>
> self.assertEqual("Break it!", *resp.content*)
>
>
> test.py
> # Reset password no login
>
> def test_Reset_no_login(self):
> self.assertTrue(isinstance(self.user, User))
> login = self.client.login(username='captain', password='america')
>
> self.assertEqual("Profile", *resp.content*)
>
> self.assertNotContains(resp, 'Documentation')
> self.assertNotContains(resp, 'Change
> password')
> self.assertNotContains(resp, 'Log out')
>
>
>
> Then I can't find these html tags in unit test's *resp.content* but when
> I manually check the html source page from the web browser then I see those
> 3 html tags.
> Why isn't unit test *resp.content* output displaying these 3 html lines?
>
>
> html source page
> http://dpaste.com/0PCZJ0D
>
>  Welcome, joe.
>
>
> *Documentation /  href="/admin/password_change/">Change password /  href="/admin/logout/">Log out *
> 
>
>
> unit test output
> http://dpaste.com/23XGR4M.txt
>
> ==
> FAIL: test_Reset_no_login (userprofile.tests.PasswordResetTest)
> --
> Traceback (most recent call last):
>   File "/home/Python/Projects/Navi/Django/navi/userprofile/tests.py", line
> 132, in test_Reset_no_login
>
> self.assertEqual("Profile", resp.content)
>
> AssertionError: 'Profile' != '\n >\n\nPassword reset - v.2\n type="text/css" href="/static/admin/css/base.css" />\n\n\n\n type="text/javascript">window.__admin_media_prefix__ =
> "/static/admin/";\n\n />\n\n\n\n\n\n\n id="container">\n\n\n\n id="header">\n\n\n id="site-name">Navi administration - v.1\n\n\n
> \nAdmin navigation\n\n\n
> \n\nHome\n\n
> \n\n\n\n\n\n\n\n\n
> \n\n\n\nPassword
> reset\nForgotten your password? Enter your email address below, and
> we\'ll email instructions for setting a new one.\n\n method="post"> value=\'iXJku3wGmCRg95SlHqC5QfHEH48XCRRZ\' />\n\n for="id_email">Email address:  name="email" type="text" />  />\n\n\n\n\n\n
> \n\n\n\n\n\n\n\n'
>
> --
> Ran 36 tests in 5.981s
>
> FAILED (failures=1)
> Destroying test database for alias 'default' (':memory:')...
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c20a58c5-fad3-4ba6-906e-ca99158f9db6%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD3RGrSygOn%3D_J2hmMFB87QezLwZSMNfLoN27WL5fwHjvKwi%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Unit testing - self.assertEqual("Break it!", resp.content)

2014-07-06 Thread Pepsodent Cola
When I run this unit test to make it break so it can output a bunch of html 
data.

self.assertEqual("Break it!", *resp.content*)


test.py
# Reset password no login

def test_Reset_no_login(self):
self.assertTrue(isinstance(self.user, User))
login = self.client.login(username='captain', password='america')

self.assertEqual("Profile", *resp.content*)

self.assertNotContains(resp, 'Documentation')
self.assertNotContains(resp, 'Change 
password')
self.assertNotContains(resp, 'Log out')



Then I can't find these html tags in unit test's *resp.content* but when I 
manually check the html source page from the web browser then I see those 3 
html tags.
Why isn't unit test *resp.content* output displaying these 3 html lines?


html source page
http://dpaste.com/0PCZJ0D

 Welcome, joe. 


*Documentation / Change password / Log out *



unit test output
http://dpaste.com/23XGR4M.txt

==
FAIL: test_Reset_no_login (userprofile.tests.PasswordResetTest)
--
Traceback (most recent call last):
  File "/home/Python/Projects/Navi/Django/navi/userprofile/tests.py", line 
132, in test_Reset_no_login

self.assertEqual("Profile", resp.content)

AssertionError: 'Profile' != '\n\n\nPassword reset - v.2\n\n\n\n\nwindow.__admin_media_prefix__ = 
"/static/admin/";\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nNavi administration - v.1\n\n\n
\nAdmin navigation\n\n\n
\n\nHome\n\n
\n\n\n\n\n\n\n\n\n
\n\n\n\nPassword 
reset\nForgotten your password? Enter your email address below, and 
we\'ll email instructions for setting a new one.\n\n\n\nEmail address:  \n\n\n\n\n\n
\n\n\n\n\n\n\n\n'

--
Ran 36 tests in 5.981s

FAILED (failures=1)
Destroying test database for alias 'default' (':memory:')...


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c20a58c5-fad3-4ba6-906e-ca99158f9db6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Unit testing - return HttpResponseRedirect('/accounts/loggedin')

2014-07-04 Thread Pepsodent Cola
Hi coverage has highlighted that I have no unit test for the line, 
regarding *HttpResponseRedirect('/accounts/loggedin')*.
How can I write a test that makes Coverage happy regarding this?


views.py

def auth_view(request): 
username = request.POST.get('username', '') 
password = request.POST.get('password', '') 
user = auth.authenticate(username=username, password=password) 

if user is not None: 
auth.login(request, user)   
return HttpResponseRedirect('*/accounts/loggedin*')   
else:
return HttpResponseRedirect('/accounts/invalid') 
#___

def loggedin(request):
return render_to_response('loggedin.html',
   {'full_name': 
request.user.username})
#___

def invalid_login(request):
return render_to_response('invalid_login.html')
#___




url.py

# user auth urls
url(r'^accounts/login/$', 'navi.views.login'),
url(r'^accounts/auth/$', 'navi.views.*auth_view*'),
url(r'^accounts/logout/$', 'navi.views.logout'),
url(r'^accounts/loggedin/$', 'navi.views.loggedin'),
url(r'^accounts/invalid/$', 'navi.views.invalid_login'),



test.py

###
#Forms
###

class FormTest(TestCase):
# Create User
def setUp(self):
self.user = User.objects.create_user(username='captain', 
password='america')

# Logged in
def test_Logged_in(self):
self.assertTrue(isinstance(self.user, User))
login = self.client.login(username='captain', password='america')
self.assertEqual(login, True)

resp = self.client.get('/accounts/profile/')
#  resp = self.client.get(reverse('userprofile:user_profile'))
self.assertEqual(resp.status_code, 200)

#  resp = self.client.post('/accounts/profile/', {'username':'captain', 
'password':'america'}, follow=True)
resp = self.client.post('/accounts/profile/', follow=True)
self.assertEqual(resp.status_code, 200)

resp = self.client.get('/accounts/fakepage/')
resp = self.client.get('/accounts/loggedin/')


# Invalid login
def test_Invalid_login(self):
resp = self.client.get('/accounts/profile/', follow=True)
self.assertEqual(resp.status_code, 200)
self.assertRedirects(resp, 
'/accounts/login/?next=/accounts/profile/')

self.assertTrue(isinstance(self.user, User))
login = self.client.login(username='captain', password='america')
self.assertEqual(login, True)
resp = self.client.get(reverse('userprofile:user_profile'), 
follow=True)
self.assertEqual(resp.status_code, 200)

#  resp = self.client.post('/accounts/profile/', {'username':'captain', 
'password':'america'}, follow=True)
resp = self.client.post('/accounts/profile/', follow=True)
self.assertEqual(resp.status_code, 200)


class AuthTest(TestCase):
def test_auth_view(self):
resp = self.client.get('/accounts/auth/', follow=True)
self.assertEqual(resp.status_code, 200)
self.assertRedirects(resp, '/accounts/invalid/')

def test_loggedin(self):
resp = self.client.post('/accounts/loggedin/')
self.assertEqual(resp.status_code, 200)

def test_logout(self):
resp = self.client.get('/accounts/logout/')
self.assertEqual(resp.status_code, 200)
#___



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3528b26d-52f9-4e26-aaab-631e955936e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit testing - self.assertEqual(login, True)

2014-07-03 Thread Pepsodent Cola
Thanks!  I see what I did wrong now.


class UserProfileTest(TestCase):
# Create User
def setUp(self):
self.user = *User.objects.create_user*(username='captain', 
password='america')

# Logged in
def test_VIEW_USER__Logged_in(self):
self.assertTrue(isinstance(self.user, User))
login = self.client.login(username='captain', password='america')
self.assertEqual(login, True)



https://docs.djangoproject.com/en/1.5/intro/tutorial05/#testing-our-new-view

class UserProfileTest(TestCase):
*# User factory method*
def create_user(self, username='joe', password='joe'):
return *User.objects.create*(username=username, password=password)

# Create User
def test_creation_USER(self):
u = self.create_user()
self.assertTrue(isinstance(u, User))
login = self.client.login(username='joe', password='joe')
self.assertEqual(login, True)






On Thursday, July 3, 2014 2:57:24 PM UTC+2, Amim Knabben wrote:
>
> duplicated question
>
> https://groups.google.com/forum/#!topic/django-users/I4wmYKNMNn8
>
>
> On Thu, Jul 3, 2014 at 9:09 AM, Pepsodent Cola <pepsod...@gmail.com 
> > wrote:
>
>> I want to run a unit test for a user logging in but I get error.  What am 
>> I doing wrong?
>>
>>
>> from django.test import TestCase
>> from userprofile.models import UserProfile
>> from django.contrib.auth.models import User
>>
>> class UserProfileTest(TestCase):
>> # User factory method
>> def create_user(self, username='joe', password='joe'):
>> return User.objects.create(username=username, password=password)
>>
>> # Create User
>> def test_creation_USER(self):
>> u = self.create_user()
>> self.assertTrue(isinstance(u, User))
>> login = self.client.login(username='joe', password='joe')
>> *self.assertEqual(login, True)*
>>
>> ==
>> FAIL: test_creation_USER (userprofile.tests.UserProfileTest)
>> --
>> Traceback (most recent call last):
>>   File "/home/Django/project/userprofile/tests.py", line 44, in 
>> test_creation_USER
>> self.assertEqual(login, True)
>> *AssertionError: False != True*
>>
>> --
>>
>>
>>  -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/5d49c776-fe1f-4702-abc1-d2c99468d82a%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/5d49c776-fe1f-4702-abc1-d2c99468d82a%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
>
> *AMIM KNABBEN*
> +55 48 9680 9126 (m)
>
>  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9974fc0b-a1ec-4048-9a24-3773b9f3540d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit testing - self.assertEqual(login, True)

2014-07-03 Thread Amim Knabben
duplicated question

https://groups.google.com/forum/#!topic/django-users/I4wmYKNMNn8


On Thu, Jul 3, 2014 at 9:09 AM, Pepsodent Cola 
wrote:

> I want to run a unit test for a user logging in but I get error.  What am
> I doing wrong?
>
>
> from django.test import TestCase
> from userprofile.models import UserProfile
> from django.contrib.auth.models import User
>
> class UserProfileTest(TestCase):
> # User factory method
> def create_user(self, username='joe', password='joe'):
> return User.objects.create(username=username, password=password)
>
> # Create User
> def test_creation_USER(self):
> u = self.create_user()
> self.assertTrue(isinstance(u, User))
> login = self.client.login(username='joe', password='joe')
> *self.assertEqual(login, True)*
>
> ==
> FAIL: test_creation_USER (userprofile.tests.UserProfileTest)
> --
> Traceback (most recent call last):
>   File "/home/Django/project/userprofile/tests.py", line 44, in
> test_creation_USER
> self.assertEqual(login, True)
> *AssertionError: False != True*
>
> --
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5d49c776-fe1f-4702-abc1-d2c99468d82a%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 

*AMIM KNABBEN*
+55 48 9680 9126 (m)

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAODc%2BXaWUytkQGo1PCrRkE4zLzc-TM0P4cdC%3Dxf8bK8%3DCMNgPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Unit testing - self.assertEqual(login, True)

2014-07-03 Thread Pepsodent Cola
I want to run a unit test for a user logging in but I get error.  What am I 
doing wrong?


from django.test import TestCase
from userprofile.models import UserProfile
from django.contrib.auth.models import User

class UserProfileTest(TestCase):
# User factory method
def create_user(self, username='joe', password='joe'):
return User.objects.create(username=username, password=password)

# Create User
def test_creation_USER(self):
u = self.create_user()
self.assertTrue(isinstance(u, User))
login = self.client.login(username='joe', password='joe')
*self.assertEqual(login, True)*

==
FAIL: test_creation_USER (userprofile.tests.UserProfileTest)
--
Traceback (most recent call last):
  File "/home/Django/project/userprofile/tests.py", line 44, in 
test_creation_USER
self.assertEqual(login, True)
*AssertionError: False != True*

--


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5d49c776-fe1f-4702-abc1-d2c99468d82a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: testing equality in template tag

2014-06-26 Thread Tom Evans
On Wed, Jun 25, 2014 at 7:34 PM, Lee Hinde  wrote:
> with view code like so:
>
> import calendar
> months_choices = []
> for i in range(1,13):
> months_choices.append((i, calendar.month_name[i]))
> context['months'] = months_choices
>
>
> and
>
> context['default_month'] = today.month
>
> I have this snippet in a template (my first use of lists like this):
>
> 
> {% for month in months %}
>  value="{{ month.0 }}">
> {{ month.1 }}
> {% endfor %}
> 
>
>
> The issue is the  {% if default_month == month.0 %} always returns false...
> The rest of the select is properly built - I get a number for the value and
> the month name as the label.
>
> Why?
>

Differing types? "1" != 1

Log the repr of both values and see.

Cheers

Tom

PS: Django forms are very good at rendering selects and determining
which one is selected.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1L%2B7USiPBr3LN66AB3ZSFQOc44aqvbu9_6G%3DOwETHEAjw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: testing equality in template tag

2014-06-26 Thread Roman Klesel
Ugh , sorry of course we know ... forget what i said ...

2014-06-26 9:48 GMT+02:00 Roman Klesel :
> hard to tell since we do not know what values default_month and month.0 have 
> ...
> try to print in the view and examine:
> print type(month[0]), month[0], type(today.month), today.month
>
> 2014-06-25 20:34 GMT+02:00 Lee Hinde :
>> with view code like so:
>>
>> import calendar
>> months_choices = []
>> for i in range(1,13):
>> months_choices.append((i, calendar.month_name[i]))
>> context['months'] = months_choices
>>
>>
>> and
>>
>> context['default_month'] = today.month
>>
>> I have this snippet in a template (my first use of lists like this):
>>
>> 
>> {% for month in months %}
>> > value="{{ month.0 }}">
>> {{ month.1 }}
>> {% endfor %}
>> 
>>
>>
>> The issue is the  {% if default_month == month.0 %} always returns false...
>> The rest of the select is properly built - I get a number for the value and
>> the month name as the label.
>>
>> Why?
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2BePoMzx%2B4774Ne21djP-EdSAHDL_64DWhZVQYrUYdND%3DBk2%2Bw%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL2Rd%3DKB6MxR22LTYQjVmxiee%2BhktpkqttPmemZQhvm9r9_%3DBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: testing equality in template tag

2014-06-26 Thread Roman Klesel
hard to tell since we do not know what values default_month and month.0 have ...
try to print in the view and examine:
print type(month[0]), month[0], type(today.month), today.month

2014-06-25 20:34 GMT+02:00 Lee Hinde :
> with view code like so:
>
> import calendar
> months_choices = []
> for i in range(1,13):
> months_choices.append((i, calendar.month_name[i]))
> context['months'] = months_choices
>
>
> and
>
> context['default_month'] = today.month
>
> I have this snippet in a template (my first use of lists like this):
>
> 
> {% for month in months %}
>  value="{{ month.0 }}">
> {{ month.1 }}
> {% endfor %}
> 
>
>
> The issue is the  {% if default_month == month.0 %} always returns false...
> The rest of the select is properly built - I get a number for the value and
> the month name as the label.
>
> Why?
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BePoMzx%2B4774Ne21djP-EdSAHDL_64DWhZVQYrUYdND%3DBk2%2Bw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL2Rd%3DJo__TO_U3OKAeehv4mRzBQEH4nMf0LfNxfoEZB4%2B9j%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


testing equality in template tag

2014-06-25 Thread Lee Hinde
with view code like so:

import calendar
months_choices = []
for i in range(1,13):
months_choices.append((i, calendar.month_name[i]))
context['months'] = months_choices


and

context['default_month'] = today.month

I have this snippet in a template (my first use of lists like this):


{% for month in months %}

{{ month.1 }}
{% endfor %}



The issue is the  {% if default_month == month.0 %} always returns false...
The rest of the select is properly built - I get a number for the value and
the month name as the label.

Why?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzx%2B4774Ne21djP-EdSAHDL_64DWhZVQYrUYdND%3DBk2%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Expected URL with primary key when testing SimpleTestCase.assertRedirects()

2014-06-18 Thread Antonio Alaniz
Thanks, K. I think one of my main issues, after looking at your tests, is 
that I'm not currently using the client to test the redirect. I have this 
test as a part of my functional_tests.py, but it sounds like I need to 
possibly build this into my unit tests as I see your test is in tests.py. 
I'm going move some of this work around between functional and unit tests 
and then try out your suggestion with the client. 

Tony

On Tuesday, June 17, 2014 7:26:27 PM UTC-7, Antonio Alaniz wrote:
>
> I'm testing a redirect that would include the primary key. Can anyone tell 
> me how I can test the redirect URL if it involves the primary key? Will the 
> following work?:
>
> self.assertRedirects(response, 'message/(?P\d+)/', 200)
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/268c0cf6-2829-445a-a97d-8c7832121247%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Expected URL with primary key when testing SimpleTestCase.assertRedirects()

2014-06-18 Thread Kelvin Wong
This is how I usually do redirect tests:

self.assertEqual(response.status_code, 302)
self.assertRedirects(
response,
'http://testserver' + reverse('pizza:deleted')
)

I recommend using named URLs, that way your message_id would be similar to 
this:

reverse('pizza:delete', args=[pizza.id])

Here is the complete app's tests if you want to take a look

https://github.com/kelvinwong-ca/django-select-multiple-field/blob/master/test_projects/django14/pizzagigi/tests.py

K



On Tuesday, June 17, 2014 7:26:27 PM UTC-7, Antonio Alaniz wrote:
>
> I'm testing a redirect that would include the primary key. Can anyone tell 
> me how I can test the redirect URL if it involves the primary key? Will the 
> following work?:
>
> self.assertRedirects(response, 'message/(?P\d+)/', 200)
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f0ddc82c-67f8-4b2d-aef1-6fcde2eb3c72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Expected URL with primary key when testing SimpleTestCase.assertRedirects()

2014-06-17 Thread Antonio Alaniz
I'm testing a redirect that would include the primary key. Can anyone tell 
me how I can test the redirect URL if it involves the primary key? Will the 
following work?:

self.assertRedirects(response, 'message/(?P\d+)/', 200)

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d676d6a7-5ab5-408e-902b-958b39798ddd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: newcomer to django testing

2014-06-09 Thread Andromeda Yelton
You can also add a depends_on statement to your south migrations, if you
really need them to run in a particular order:
http://south.readthedocs.org/en/latest/dependencies.html


On Sun, Jun 8, 2014 at 2:09 PM, monoBOT <monobot.s...@gmail.com> wrote:

> Hi Esau.
>
> Funny to see you here ;.D
>
> I checked what you told me and its true ... if I try to create the
> database starting with the comunidad table it  raises the error but when
> starting the migrations with usuario it goes smooth.
>
> Simply changing the app order in the settings.py file fixed the problem ...
>
> Thanks mate
>
>
> 2014-06-08 15:39 GMT+01:00 Esau Rodriguez <esa...@gmail.com>:
>
> The testing process creates  db itself when using south it migrate all
>> apps with migrations. Could you have a problem with your migrations
>> when run from zero?.
>>
>> Regards
>> Esau Rodriguez.
>>
>>
>>
>> On Sun, Jun 8, 2014 at 10:20 AM, monoBOT <monobot.s...@gmail.com> wrote:
>> > Im new on testing ... to be honest its my first django test XD
>> >
>> > Now i wanted to test one of my applications and after the innitial
>> tweaking
>> > of allowing the django user to be able to create databases i get this
>> error:
>> >
>> > The error was: relation "usuario_usuario" does not exist
>> >
>> > Error in migration: comunidad:0001_initial
>> > Traceback (most recent call last):
>> >   File "manage.py", line 10, in 
>> > execute_from_command_line(sys.argv)
>> >   File
>> >
>> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
>> > line 399, in execute_from_command_line
>> > utility.execute()
>> >   File
>> >
>> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
>> > line 392, in execute
>> > self.fetch_command(subcommand).run_from_argv(self.argv)
>> >   File
>> >
>> "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
>> > line 50, in run_from_argv
>> > super(Command, self).run_from_argv(argv)
>> >   File
>> > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
>> > line 242, in run_from_argv
>> > self.execute(*args, **options.__dict__)
>> >   File
>> >
>> "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
>> > line 71, in execute
>> > super(Command, self).execute(*args, **options)
>> >   File
>> > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
>> > line 285, in execute
>> > output = self.handle(*args, **options)
>> >   File
>> >
>> "/home/monobot/.local/lib/python2.7/site-packages/south/management/commands/test.py",
>> > line 8, in handle
>> > super(Command, self).handle(*args, **kwargs)
>> >   File
>> >
>> "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
>> > line 88, in handle
>> > failures = test_runner.run_tests(test_labels)
>> >   File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py",
>> line
>> > 145, in run_tests
>> > old_config = self.setup_databases()
>> >   File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py",
>> line
>> > 107, in setup_databases
>> > return setup_databases(self.verbosity, self.interactive, **kwargs)
>> >   File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py",
>> line
>> > 279, in setup_databases
>> > verbosity, autoclobber=not interactive)
>> >   File
>> >
>> "/home/monobot/.local/lib/python2.7/site-packages/south/hacks/django_1_0.py",
>> > line 104, in wrapper
>> > return f(*args, **kwargs)
>> >   File
>> > "/usr/local/lib/python2.7/dist-packages/django/db/backends/creation.py",
>> > line 339, in create_test_db
>> > load_initial_data=False)
>> >   File
>> >
>> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
>> > line 159, in call_command
>> > return klass.execute(*args, **defaults)
>> >   File
>> > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
>> > line 285, in execute
>> > output = self.handle(*args, **options)
>

Re: newcomer to django testing

2014-06-08 Thread monoBOT
Hi Esau.

Funny to see you here ;.D

I checked what you told me and its true ... if I try to create the database
starting with the comunidad table it  raises the error but when starting
the migrations with usuario it goes smooth.

Simply changing the app order in the settings.py file fixed the problem ...

Thanks mate


2014-06-08 15:39 GMT+01:00 Esau Rodriguez <esa...@gmail.com>:

> The testing process creates  db itself when using south it migrate all
> apps with migrations. Could you have a problem with your migrations
> when run from zero?.
>
> Regards
> Esau Rodriguez.
>
>
>
> On Sun, Jun 8, 2014 at 10:20 AM, monoBOT <monobot.s...@gmail.com> wrote:
> > Im new on testing ... to be honest its my first django test XD
> >
> > Now i wanted to test one of my applications and after the innitial
> tweaking
> > of allowing the django user to be able to create databases i get this
> error:
> >
> > The error was: relation "usuario_usuario" does not exist
> >
> > Error in migration: comunidad:0001_initial
> > Traceback (most recent call last):
> >   File "manage.py", line 10, in 
> > execute_from_command_line(sys.argv)
> >   File
> >
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> > line 399, in execute_from_command_line
> > utility.execute()
> >   File
> >
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> > line 392, in execute
> > self.fetch_command(subcommand).run_from_argv(self.argv)
> >   File
> >
> "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
> > line 50, in run_from_argv
> > super(Command, self).run_from_argv(argv)
> >   File
> > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> > line 242, in run_from_argv
> > self.execute(*args, **options.__dict__)
> >   File
> >
> "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
> > line 71, in execute
> > super(Command, self).execute(*args, **options)
> >   File
> > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> > line 285, in execute
> > output = self.handle(*args, **options)
> >   File
> >
> "/home/monobot/.local/lib/python2.7/site-packages/south/management/commands/test.py",
> > line 8, in handle
> > super(Command, self).handle(*args, **kwargs)
> >   File
> >
> "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
> > line 88, in handle
> > failures = test_runner.run_tests(test_labels)
> >   File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py",
> line
> > 145, in run_tests
> > old_config = self.setup_databases()
> >   File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py",
> line
> > 107, in setup_databases
> > return setup_databases(self.verbosity, self.interactive, **kwargs)
> >   File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py",
> line
> > 279, in setup_databases
> > verbosity, autoclobber=not interactive)
> >   File
> >
> "/home/monobot/.local/lib/python2.7/site-packages/south/hacks/django_1_0.py",
> > line 104, in wrapper
> > return f(*args, **kwargs)
> >   File
> > "/usr/local/lib/python2.7/dist-packages/django/db/backends/creation.py",
> > line 339, in create_test_db
> > load_initial_data=False)
> >   File
> >
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> > line 159, in call_command
> > return klass.execute(*args, **defaults)
> >   File
> > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> > line 285, in execute
> > output = self.handle(*args, **options)
> >   File
> > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> > line 415, in handle
> > return self.handle_noargs(**options)
> >   File
> >
> "/home/monobot/.local/lib/python2.7/site-packages/south/management/commands/syncdb.py",
> > line 103, in handle_noargs
> > management.call_command('migrate', **options)
> >   File
> >
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> > line 159, in call_command
> > return klass.execute(*args, **defaults)
> >   File
> > "/usr/local/lib/python2.7

Re: newcomer to django testing

2014-06-08 Thread Esau Rodriguez
The testing process creates  db itself when using south it migrate all
apps with migrations. Could you have a problem with your migrations
when run from zero?.

Regards
Esau Rodriguez.



On Sun, Jun 8, 2014 at 10:20 AM, monoBOT <monobot.s...@gmail.com> wrote:
> Im new on testing ... to be honest its my first django test XD
>
> Now i wanted to test one of my applications and after the innitial tweaking
> of allowing the django user to be able to create databases i get this error:
>
> The error was: relation "usuario_usuario" does not exist
>
> Error in migration: comunidad:0001_initial
> Traceback (most recent call last):
>   File "manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> line 399, in execute_from_command_line
> utility.execute()
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> line 392, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
> line 50, in run_from_argv
> super(Command, self).run_from_argv(argv)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 242, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
> line 71, in execute
> super(Command, self).execute(*args, **options)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 285, in execute
> output = self.handle(*args, **options)
>   File
> "/home/monobot/.local/lib/python2.7/site-packages/south/management/commands/test.py",
> line 8, in handle
> super(Command, self).handle(*args, **kwargs)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
> line 88, in handle
> failures = test_runner.run_tests(test_labels)
>   File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line
> 145, in run_tests
> old_config = self.setup_databases()
>   File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line
> 107, in setup_databases
> return setup_databases(self.verbosity, self.interactive, **kwargs)
>   File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line
> 279, in setup_databases
> verbosity, autoclobber=not interactive)
>   File
> "/home/monobot/.local/lib/python2.7/site-packages/south/hacks/django_1_0.py",
> line 104, in wrapper
> return f(*args, **kwargs)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/creation.py",
> line 339, in create_test_db
> load_initial_data=False)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> line 159, in call_command
> return klass.execute(*args, **defaults)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 285, in execute
> output = self.handle(*args, **options)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 415, in handle
> return self.handle_noargs(**options)
>   File
> "/home/monobot/.local/lib/python2.7/site-packages/south/management/commands/syncdb.py",
> line 103, in handle_noargs
> management.call_command('migrate', **options)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> line 159, in call_command
> return klass.execute(*args, **defaults)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 285, in execute
> output = self.handle(*args, **options)
>   File
> "/home/monobot/.local/lib/python2.7/site-packages/south/management/commands/migrate.py",
> line 111, in handle
> ignore_ghosts = ignore_ghosts,
>   File
> "/home/monobot/.local/lib/python2.7/site-packages/south/migration/__init__.py",
> line 220, in migrate_app
> success = migrator.migrate_many(target, workplan, database)
>   File
> "/home/monobot/.local/lib/python2.7/site-packages/south/migration/migrators.py",
> line 305, in migrate_many
> result = self.migrate(migration, database)
>   File
> "/home/monobot/.local/lib/python2.7/site-packages/south/migration/migrators.py",
> line 134, in migrate
> result = self.run(migration, database)
>   File
> "/home/monobot/.loca

newcomer to django testing

2014-06-08 Thread monoBOT
Im new on testing ... to be honest its my first django test XD

Now i wanted to test one of my applications and after the innitial tweaking
of allowing the django user to be able to create databases i get this error:

​The error was: relation "usuario_usuario" does not exist

Error in migration: comunidad:0001_initial
Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
line 399, in execute_from_command_line
utility.execute()
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
line 242, in run_from_argv
self.execute(*args, **options.__dict__)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
line 71, in execute
super(Command, self).execute(*args, **options)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
line 285, in execute
output = self.handle(*args, **options)
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/management/commands/test.py",
line 8, in handle
super(Command, self).handle(*args, **kwargs)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py",
line 88, in handle
failures = test_runner.run_tests(test_labels)
  File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line
145, in run_tests
old_config = self.setup_databases()
  File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line
107, in setup_databases
return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/test/runner.py", line
279, in setup_databases
verbosity, autoclobber=not interactive)
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/hacks/django_1_0.py",
line 104, in wrapper
return f(*args, **kwargs)
  File
"/usr/local/lib/python2.7/dist-packages/django/db/backends/creation.py",
line 339, in create_test_db
load_initial_data=False)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
line 159, in call_command
return klass.execute(*args, **defaults)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
line 285, in execute
output = self.handle(*args, **options)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
line 415, in handle
return self.handle_noargs(**options)
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/management/commands/syncdb.py",
line 103, in handle_noargs
management.call_command('migrate', **options)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
line 159, in call_command
return klass.execute(*args, **defaults)
  File
"/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
line 285, in execute
output = self.handle(*args, **options)
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/management/commands/migrate.py",
line 111, in handle
ignore_ghosts = ignore_ghosts,
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/migration/__init__.py",
line 220, in migrate_app
success = migrator.migrate_many(target, workplan, database)
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/migration/migrators.py",
line 305, in migrate_many
result = self.migrate(migration, database)
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/migration/migrators.py",
line 134, in migrate
result = self.run(migration, database)
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/migration/migrators.py",
line 115, in run
return self.run_migration(migration, database)
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/migration/migrators.py",
line 86, in run_migration
south.db.db.execute_deferred_sql()
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/db/generic.py",
line 318, in execute_deferred_sql
self.execute(sql)
  File
"/home/monobot/.local/lib/python2.7/site-packages/south/db/generic.py",
line 282, in execute
cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py",
line 53, in execute
return self.cursor.execute(sql, params)
  File "/usr/local/l

Re: why does django user require create database privlages for testing

2014-04-23 Thread Alex Mandel
If you don't want to setup a test db with permissions for a test app,
use sqlite. I can't see why you'd ever want to give your web app carte
blanc permissions to run all over your db server.

Seems to me "you create a test database as super user" is the same as
changing to a db admin user, creating a db and auth for access to that db.

Thanks,
Alex

On 04/23/2014 01:51 PM, Bill Freeman wrote:
> Because virtually all of us don't want our production database used for
> testing.
> 
> 
> On Wed, Apr 23, 2014 at 4:18 PM, dacresni <vivacar...@gmail.com> wrote:
> 
>> Rails doesn't require this, you create a test database as super user and
>> it uses it for testing. Why doesn't django allow this?
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/79bc208a-8e2e-4b8c-a442-19e0f489ecf2%40googlegroups.com<https://groups.google.com/d/msgid/django-users/79bc208a-8e2e-4b8c-a442-19e0f489ecf2%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/535829E6.1090109%40wildintellect.com.
For more options, visit https://groups.google.com/d/optout.


Re: why does django user require create database privlages for testing

2014-04-23 Thread Bill Freeman
Because virtually all of us don't want our production database used for
testing.


On Wed, Apr 23, 2014 at 4:18 PM, dacresni <vivacar...@gmail.com> wrote:

> Rails doesn't require this, you create a test database as super user and
> it uses it for testing. Why doesn't django allow this?
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/79bc208a-8e2e-4b8c-a442-19e0f489ecf2%40googlegroups.com<https://groups.google.com/d/msgid/django-users/79bc208a-8e2e-4b8c-a442-19e0f489ecf2%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%2BAj0s3x7shESgF3aMe2qzF-E_Kt5edNrHtL_tHYgKtdsa4YA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


why does django user require create database privlages for testing

2014-04-23 Thread dacresni
Rails doesn't require this, you create a test database as super user and it 
uses it for testing. Why doesn't django allow this?  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/79bc208a-8e2e-4b8c-a442-19e0f489ecf2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


<    1   2   3   4   5   6   7   8   9   10   >