forked from django-cms/django-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtestserver.py
executable file
·57 lines (53 loc) · 2.04 KB
/
runtestserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
from cms.test_utils.cli import configure
from cms.test_utils.tmpdir import temp_dir
import argparse
import os
import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port', default='8000')
parser.add_argument('-b', '--bind', default='127.0.0.1')
args = parser.parse_args()
new_db = not os.path.exists('cmstestdb.sqlite')
with temp_dir() as STATIC_ROOT:
with temp_dir() as MEDIA_ROOT:
configure(
ROOT_URLCONF='cms.test_utils.project.urls',
STATIC_ROOT=STATIC_ROOT,
MEDIA_ROOT=MEDIA_ROOT,
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'cmstestdb.sqlite',
}
}
)
from django.core.management import call_command
call_command('syncdb', interactive=False, migrate_all=new_db)
call_command('migrate', interactive=False, fake=new_db)
from django.contrib.auth.models import User
if not User.objects.filter(is_superuser=True).exists():
usr = User()
usr.username = 'admin'
usr.email = '[email protected]'
usr.set_password('admin')
usr.is_superuser = True
usr.is_staff = True
usr.is_active = True
usr.save()
print
print "A admin user (username: admin, password: admin) has been created."
print
from django.contrib.staticfiles.management.commands import runserver
rs = runserver.Command()
rs.stdout = sys.stdout
rs.stderr = sys.stderr
rs.use_ipv6 = False
rs._raw_ipv6 = False
rs.addr = args.bind
rs.port = args.port
rs.inner_run(addrport='%s:%s' % (args.bind, args.port),
insecure_serving=True)
if __name__ == '__main__':
main()