When I run my tests in a python script it modifies my production database.  
If I run from the command line it doesn't.  When I say modify, it wipes out 
my existing users and replaces them with the users I create for testing.  

I followed this for the setup: 
https://docs.djangoproject.com/en/1.4/topics/testing/#django.test.LiveServerTestCase
I created a <setUp> to setup users.  

When I run this the production database isn't modified:
  python2.7 manage.py test yPayment

In my python script I have:
  from django.utils import unittest
  class yPaymentTest(LiveServerTestCase)
  ...
  suite_payment = unittest.TestLoader().loadTestsFromTestCase(yPaymentTest)
  unittest.TextTestRunner(verbosity=2).run(suite_payment)

Here is the full output from the command line
[brian@centos-dv7 yPaymentProj]$ 
/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/bin/python2.7
 
manage.py test yPayment
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "/usr/local/python2.7/lib/python2.7/wsgiref/handlers.py", line 85, 
in run
    self.result = application(self.environ, self.start_response)
  File 
"/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py",
 
line 67, in __call__
    return self.application(environ, start_response)
  File 
"/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py",
 
line 67, in __call__
    return self.application(environ, start_response)
  File 
"/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/core/handlers/wsgi.py",
 
line 241, in __call__
    response = self.get_response(request)
  File 
"/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/core/handlers/base.py",
 
line 151, in get_response
    response = self.handle_uncaught_exception(request, resolver, 
sys.exc_info())
  File 
"/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/core/handlers/base.py",
 
line 226, in handle_uncaught_exception
    return callback(request, **param_dict)
  File 
"/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/utils/decorators.py",
 
line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File 
"/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/views/defaults.py",
 
line 32, in server_error
    t = loader.get_template(template_name) # You need to create a 500.html 
template.
  File 
"/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/template/loader.py",
 
line 145, in get_template
    template, origin = find_template(template_name)
  File 
"/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/template/loader.py",
 
line 138, in find_template
    raise TemplateDoesNotExist(name)
TemplateDoesNotExist: 500.html
/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808:
 
RuntimeWarning: DateTimeField received a naive datetime (2014-06-08 
22:54:32.927908) while time zone support is active.
  RuntimeWarning)
/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808:
 
RuntimeWarning: DateTimeField received a naive datetime (2014-06-08 
22:54:32.927916) while time zone support is active.
  RuntimeWarning)
/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808:
 
RuntimeWarning: DateTimeField received a naive datetime (2014-06-08 
22:54:34.690671) while time zone support is active.
  RuntimeWarning)
.sss
----------------------------------------------------------------------
Ran 4 tests in 12.259s

OK (skipped=3)
Destroying test database for alias 'default'...



Here is the output from the python script.   
test_custom_admin_add_card (__main__.yPaymentTest) ... 
/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808:
 
RuntimeWarning: DateTimeField received a naive datetime (2014-06-08 
22:57:54.016573) while time zone support is active.
  RuntimeWarning)
/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808:
 
RuntimeWarning: DateTimeField received a naive datetime (2014-06-08 
22:57:54.016584) while time zone support is active.
  RuntimeWarning)
/usr/local/python2.7/lib/python2.7/site-packages/virt_env/django1p4/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808:
 
RuntimeWarning: DateTimeField received a naive datetime (2014-06-08 
22:57:55.843861) while time zone support is active.
  RuntimeWarning)
ok
test_custom_admin_login (__main__.yPaymentTest) ... skipped 'skipping while 
debugging other functions'
test_custom_admin_no_card (__main__.yPaymentTest) ... skipped 'skipping 
while debugging other functions'
test_custom_admin_required_login (__main__.yPaymentTest) ... skipped 
'skipping while debugging other functions'

----------------------------------------------------------------------
Ran 4 tests in 24.278s

OK (skipped=3)


I'm running the script with an IDE.

This is a similar problem: 
http://stackoverflow.com/questions/17435155/django-functional-liveservertestcase-after-submitting-form-with-selenium-obje
but it doesn't apply since I'm using self.live_server_url instead of hard 
coding a url.

I posted this to SO without a response: 
http://stackoverflow.com/questions/24113636/liveservertestcase-modifies-production-database-when-ran-in-python-script

-- 
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/8f7c13ab-156f-43ce-a936-71c53fdf6fad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to