Moved the ietf/names/generate_fixtures.py command to a management command generate_name_fixture, and updated it to include a necessary dbtemplate object.

- Legacy-Id: 16976
This commit is contained in:
Henrik Levkowetz 2019-11-07 15:40:10 +00:00
parent a69459623c
commit 48fd1a165e
5 changed files with 114 additions and 71 deletions

View file

@ -1,12 +1,15 @@
[
{
"fields": {
"content": "{{ assigner.ascii }} has assigned you as a reviewer for this document.\n\n{% if prev_team_reviews %}This team has completed other reviews of this document:{% endif %}{% for assignment in prev_team_reviews %}\n- {{ assignment.completed_on }} {{ assignment.reviewer.person.ascii }} -{% if assignment.reviewed_rev %}{{ assignment.reviewed_rev }}{% else %}{{ assignment.review_request.requested_rev }}{% endif %} {{ assignment.result.name }}\n{% endfor %}",
"content": "{{ assigner.ascii }} has assigned you as a reviewer for this document.\n\n{% if prev_team_reviews %}This team has completed other reviews of this document:{% endif %}{% for assignment in prev_team_reviews %}\n- {{ assignment.completed_on }} {{ assignment.reviewer.person.ascii }} -{% if assignment.reviewed_rev %}{{ assignment.reviewed_rev }}{% else %}{{ assignment.review_request.requested_rev }}{% endif %} {{ assignment.result.name }} \n{% endfor %}\n",
"group": null,
"path": "/group/defaults/email/review_assigned.txt",
"type_id": "django"
"title": "",
"type": "django",
"variables": null
},
"model": "dbtemplate.dbtemplate",
"pk": "1000"
"pk": 354
},
{
"fields": {
@ -14089,7 +14092,7 @@
"fields": {
"command": "xym",
"switch": "--version",
"time": "2019-10-09T00:11:52.857",
"time": "2019-11-06T00:13:08.631",
"used": true,
"version": "xym 0.4"
},
@ -14100,9 +14103,9 @@
"fields": {
"command": "pyang",
"switch": "--version",
"time": "2019-10-09T00:11:54.264",
"time": "2019-11-06T00:13:09.565",
"used": true,
"version": "pyang 2.0.2"
"version": "pyang 2.1"
},
"model": "utils.versioninfo",
"pk": 2
@ -14111,7 +14114,7 @@
"fields": {
"command": "yanglint",
"switch": "--version",
"time": "2019-10-09T00:11:54.535",
"time": "2019-11-06T00:13:09.715",
"used": true,
"version": "yanglint 0.14.80"
},
@ -14122,9 +14125,9 @@
"fields": {
"command": "xml2rfc",
"switch": "--version",
"time": "2019-10-09T00:11:55.470",
"time": "2019-11-06T00:13:10.849",
"used": true,
"version": "xml2rfc 2.32.0"
"version": "xml2rfc 2.34.0"
},
"model": "utils.versioninfo",
"pk": 4

View file

@ -1,62 +0,0 @@
# Copyright The IETF Trust 2011-2019, All Rights Reserved
#!/usr/bin/python
# simple script for exporting name related base data for the tests
# boiler plate
import io
import os, sys
import django
import six
if six.PY3:
from typing import Any, List # pyflakes:ignore
basedir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../..'))
sys.path.insert(0, basedir)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
django.setup()
# script
from django.core.serializers import serialize
def output(name, seq):
try:
f = io.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures/%s.json" % name), 'w')
f.write(serialize("json", seq, indent=1))
f.close()
except:
from django.db import connection
from pprint import pprint
pprint(connection.queries)
raise
# pick all name models directly out of the module
objects = [] # type: List[object]
import inspect
import ietf.name.models
for n in dir(ietf.name.models):
symbol = getattr(ietf.name.models, n)
if inspect.isclass(symbol) and issubclass(symbol, ietf.name.models.NameModel):
if not symbol._meta.abstract:
objects.extend(symbol.objects.all())
import ietf.doc.models # also pick some other name-like types while we're at it
objects += ietf.doc.models.StateType.objects.all()
objects += ietf.doc.models.State.objects.all()
objects += ietf.doc.models.BallotType.objects.all()
import ietf.group.models
objects += ietf.group.models.GroupFeatures.objects.all()
import ietf.mailtrigger.models
objects += ietf.mailtrigger.models.Recipient.objects.all()
objects += ietf.mailtrigger.models.MailTrigger.objects.all()
import ietf.utils.models
objects += ietf.utils.models.VersionInfo.objects.all()
output("names", objects)

View file

@ -0,0 +1 @@
# Copyright The IETF Trust 2019, All Rights Reserved

View file

@ -0,0 +1 @@
# Copyright The IETF Trust 2019, All Rights Reserved

View file

@ -0,0 +1,100 @@
# Copyright The IETF Trust 2011-2019, All Rights Reserved
#!/usr/bin/python
# simple script for exporting name related base data for the tests
import inspect
import io
import os, sys
import six
if six.PY3:
from typing import Any, List # pyflakes:ignore
from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.serializers import serialize
from django.core.serializers.json import DjangoJSONEncoder
import debug # pyflakes:ignore
class SortedJsonEncoder(DjangoJSONEncoder):
def __init__(self, *args, **kwargs):
kwargs['sort_keys'] = True
return super(SortedJsonEncoder, self).__init__(*args, **kwargs)
class Command(BaseCommand):
help = """
Generate a custom fixture for all objects needed by the datatracker test suite.
The recommended way to use this is unfortunately not the default, as the ordering
of the resulting fixture isn't quite stable. Instead use:
"ietf/manage.py generate_name_fixture --stdout | jq --sort-keys 'sort_by(.model, .pk)' > ietf/name/fixtures/names.json"
"""
def add_arguments(self, parser):
parser.add_argument('--stdout', action='store_true', default=False, help="Send fixture to stdout instead of ietf/name/fixtures/names.json")
def say(self, msg):
if self.verbosity > 0:
sys.stdout.write(msg)
sys.stdout.write('\n')
def note(self, msg):
if self.verbosity > 1:
sys.stdout.write(msg)
sys.stdout.write('\n')
def mutter(self, msg):
if self.verbosity > 2:
sys.stdout.write(msg)
sys.stdout.write('\n')
def handle(self, *args, **options):
self.output = sys.stdout if options.get('stdout') else io.open(os.path.join(settings.BASE_DIR, "name/fixtures/names.json"), 'w')
def model_name(m):
return '%s.%s' % (m._meta.app_label, m.__name__)
def output(seq):
try:
f = self.output
f.write(serialize("json", seq, cls=SortedJsonEncoder, indent=2))
f.close()
except:
from django.db import connection
from pprint import pprint
pprint(connection.queries)
raise
objects = [] # type: List[object]
model_objects = {}
import ietf.name.models
from ietf.dbtemplate.models import DBTemplate
from ietf.doc.models import BallotType, State, StateType
from ietf.group.models import GroupFeatures
from ietf.mailtrigger.models import MailTrigger, Recipient
from ietf.stats.models import CountryAlias
from ietf.utils.models import VersionInfo
# Grab all ietf.name.models
for n in dir(ietf.name.models):
item = getattr(ietf.name.models, n)
if inspect.isclass(item) and issubclass(item, ietf.name.models.NameModel):
if not item._meta.abstract:
model_objects[model_name(item)] = list(item.objects.all().order_by('pk'))
for m in ( BallotType, State, StateType, GroupFeatures, MailTrigger, Recipient, CountryAlias, VersionInfo ):
model_objects[model_name(m)] = list(m.objects.all().order_by('pk'))
for m in ( DBTemplate, ):
model_objects[model_name(m)] = [ m.objects.get(pk=354) ]
for model_name in sorted(model_objects.keys()):
objects += model_objects[model_name]
output(objects)