﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22860	LiveServerTestCase modifies production database when ran in python script	brian.downing@…	nobody	"I posted this to:
stack overflow: http://stackoverflow.com/questions/24113636/liveservertestcase-modifies-production-database-when-ran-in-python-script
and the django list:
https://groups.google.com/forum/#!topic/django-users/hNzwDfDo_qc

I haven't got a response from either. I read the doc and I don't see anything that I did that would cause this.  

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."	Bug	closed	Testing framework	1.4	Normal	invalid	testing		Unreviewed	0	0	0	0	0	0
