Skip to content

Commit 3105101

Browse files
committed
Changed test running and test data generation to work with database rollback
(for instance with InnoDB). Added settings.DATABASE_TEST_OPTIONS which can be used to force for instance InnoDB use during testing. Using this has the potential of reducing the time it takes to run the test suite substantially; a few test runs indicate a reduction in test run time by 50% on a run-of-the-mill linux server. - Legacy-Id: 5823
1 parent eb10724 commit 3105101

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

ietf/settings.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
'ENGINE': 'django.db.backends.mysql',
4848
'USER': 'ietf',
4949
#'PASSWORD': 'ietf',
50+
#'OPTIONS': {},
5051
},
5152
# 'legacy': {
5253
# 'NAME': 'ietf',
@@ -56,6 +57,11 @@
5657
# },
5758
}
5859

60+
DATABASE_TEST_OPTIONS = {
61+
# Uncomment this to speed up testing if your database supports InnoDB:
62+
# 'init_command': 'SET storage_engine=InnoDB',
63+
}
64+
5965
# Local time zone for this installation. Choices can be found here:
6066
# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
6167
# although not all variations may be possible on all operating systems.
@@ -87,9 +93,6 @@
8793
# Examples: "http://foo.com/media/", "/media/".
8894
ADMIN_MEDIA_PREFIX = '/media/'
8995

90-
#DAJAXICE_MEDIA_PREFIX="dajaxice"
91-
DAJAXICE_MEDIA_PREFIX=""
92-
9396
AUTH_PROFILE_MODULE = 'person.Person'
9497
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.RemoteUserBackend', )
9598

ietf/utils/test_data.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,48 @@ def make_test_data():
2020
date4 = TelechatDate.objects.create(date=t + datetime.timedelta(days=14 * 3)).date
2121

2222
# groups
23-
secretariat = Group.objects.create(
23+
secretariat, created = Group.objects.get_or_create(
2424
name="Secretariat",
2525
acronym="secretariat",
2626
state_id="active",
2727
type_id="ietf",
2828
parent=None)
29-
ietf = Group.objects.create(
29+
ietf, created = Group.objects.get_or_create(
3030
name="IETF",
3131
acronym="ietf",
3232
state_id="active",
3333
type_id="ietf",
3434
parent=None)
3535
for x in ["irtf", "iab", "ise", "iesg"]:
36-
Group.objects.create(
36+
Group.objects.get_or_create(
3737
name=x.upper(),
3838
acronym=x,
3939
state_id="active",
4040
type_id="ietf",
4141
parent=None)
42-
area = Group.objects.create(
42+
area, created = Group.objects.get_or_create(
4343
name="Far Future",
4444
acronym="farfut",
4545
state_id="active",
4646
type_id="area",
4747
parent=ietf)
48-
individ = Group.objects.create(
48+
individ, created = Group.objects.get_or_create(
4949
name="Individual submissions",
5050
acronym="none",
5151
state_id="active",
5252
type_id="individ",
5353
parent=None)
5454
# mars WG
55-
mars_wg = group = Group.objects.create(
55+
group, created = Group.objects.get_or_create(
5656
name="Martian Special Interest Group",
5757
acronym="mars",
5858
state_id="active",
5959
type_id="wg",
6060
parent=area,
6161
list_email="mars-wg@ietf.org",
6262
)
63-
charter = Document.objects.create(
63+
mars_wg = group
64+
charter, created = Document.objects.get_or_create(
6465
name="charter-ietf-" + group.acronym,
6566
type_id="charter",
6667
title=group.name,
@@ -111,11 +112,12 @@ def make_test_data():
111112

112113
# system
113114
system_person = Person.objects.create(
114-
id=0, # special value
115+
# id=0, # special value
115116
name="(System)",
116117
ascii="(System)",
117118
address="",
118119
)
120+
system_person.save()
119121

120122
# IANA and RFC Editor groups
121123
iana = Group.objects.create(
@@ -137,7 +139,8 @@ def make_test_data():
137139
Person.objects.filter(id=system_person.id).update(id=0)
138140
system_person = Person.objects.get(id=0)
139141

140-
Alias.objects.get_or_create(person=system_person, name=system_person.name)
142+
alias = Alias(person=system_person, name=system_person.name)
143+
alias.save()
141144
Email.objects.get_or_create(address="", person=system_person)
142145

143146
# plain IETF'er
@@ -304,6 +307,21 @@ def make_test_data():
304307
person=p,
305308
)
306309

310+
# Secretariat user
311+
u = User.objects.create(id=509, username="wnl")
312+
p = Person.objects.create(
313+
name="Wanda Lo",
314+
ascii="Wanda Lo",
315+
user=u)
316+
email = Email.objects.create(
317+
address="wnl@amsl.com",
318+
person=p)
319+
Role.objects.create(
320+
name_id="auth",
321+
group=secretariat,
322+
email=email,
323+
person=p,
324+
)
307325

308326
# draft
309327
draft = Document.objects.create(
@@ -392,6 +410,7 @@ def make_test_data():
392410

393411
# an independent submission before review
394412
doc = Document.objects.create(name='draft-imaginary-independent-submission',type_id='draft')
413+
doc.set_state(State.objects.get(used=True, type="draft", slug="active"))
395414
DocAlias.objects.create( name='draft-imaginary-independent-submission',document=doc)
396415

397416
# an irtf submission mid review

ietf/utils/test_runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
def safe_create_1(self, verbosity, *args, **kwargs):
5151
global test_database_name, old_create
5252
print " Creating test database..."
53+
settings.DATABASES["default"]["OPTIONS"] = settings.DATABASE_TEST_OPTIONS
54+
print " Using OPTIONS: %s" % settings.DATABASES["default"]["OPTIONS"]
5355
x = old_create(self, 0, *args, **kwargs)
5456
print " Saving test database name "+settings.DATABASES["default"]["NAME"]+"..."
5557
test_database_name = settings.DATABASES["default"]["NAME"]

0 commit comments

Comments
 (0)