Skip to content

Commit 48fd1a1

Browse files
committed
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
1 parent a694596 commit 48fd1a1

5 files changed

Lines changed: 114 additions & 71 deletions

File tree

ietf/name/fixtures/names.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
[
22
{
33
"fields": {
4-
"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 %}",
4+
"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",
5+
"group": null,
56
"path": "/group/defaults/email/review_assigned.txt",
6-
"type_id": "django"
7+
"title": "",
8+
"type": "django",
9+
"variables": null
710
},
811
"model": "dbtemplate.dbtemplate",
9-
"pk": "1000"
12+
"pk": 354
1013
},
1114
{
1215
"fields": {
@@ -14089,7 +14092,7 @@
1408914092
"fields": {
1409014093
"command": "xym",
1409114094
"switch": "--version",
14092-
"time": "2019-10-09T00:11:52.857",
14095+
"time": "2019-11-06T00:13:08.631",
1409314096
"used": true,
1409414097
"version": "xym 0.4"
1409514098
},
@@ -14100,9 +14103,9 @@
1410014103
"fields": {
1410114104
"command": "pyang",
1410214105
"switch": "--version",
14103-
"time": "2019-10-09T00:11:54.264",
14106+
"time": "2019-11-06T00:13:09.565",
1410414107
"used": true,
14105-
"version": "pyang 2.0.2"
14108+
"version": "pyang 2.1"
1410614109
},
1410714110
"model": "utils.versioninfo",
1410814111
"pk": 2
@@ -14111,7 +14114,7 @@
1411114114
"fields": {
1411214115
"command": "yanglint",
1411314116
"switch": "--version",
14114-
"time": "2019-10-09T00:11:54.535",
14117+
"time": "2019-11-06T00:13:09.715",
1411514118
"used": true,
1411614119
"version": "yanglint 0.14.80"
1411714120
},
@@ -14122,9 +14125,9 @@
1412214125
"fields": {
1412314126
"command": "xml2rfc",
1412414127
"switch": "--version",
14125-
"time": "2019-10-09T00:11:55.470",
14128+
"time": "2019-11-06T00:13:10.849",
1412614129
"used": true,
14127-
"version": "xml2rfc 2.32.0"
14130+
"version": "xml2rfc 2.34.0"
1412814131
},
1412914132
"model": "utils.versioninfo",
1413014133
"pk": 4

ietf/name/generate_fixtures.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

ietf/name/management/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Copyright The IETF Trust 2019, All Rights Reserved
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Copyright The IETF Trust 2019, All Rights Reserved
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Copyright The IETF Trust 2011-2019, All Rights Reserved
2+
#!/usr/bin/python
3+
4+
# simple script for exporting name related base data for the tests
5+
6+
import inspect
7+
import io
8+
import os, sys
9+
import six
10+
if six.PY3:
11+
from typing import Any, List # pyflakes:ignore
12+
13+
14+
from django.conf import settings
15+
from django.core.management.base import BaseCommand
16+
from django.core.serializers import serialize
17+
from django.core.serializers.json import DjangoJSONEncoder
18+
19+
import debug # pyflakes:ignore
20+
21+
class SortedJsonEncoder(DjangoJSONEncoder):
22+
def __init__(self, *args, **kwargs):
23+
kwargs['sort_keys'] = True
24+
return super(SortedJsonEncoder, self).__init__(*args, **kwargs)
25+
26+
class Command(BaseCommand):
27+
help = """
28+
Generate a custom fixture for all objects needed by the datatracker test suite.
29+
30+
The recommended way to use this is unfortunately not the default, as the ordering
31+
of the resulting fixture isn't quite stable. Instead use:
32+
33+
"ietf/manage.py generate_name_fixture --stdout | jq --sort-keys 'sort_by(.model, .pk)' > ietf/name/fixtures/names.json"
34+
"""
35+
36+
def add_arguments(self, parser):
37+
parser.add_argument('--stdout', action='store_true', default=False, help="Send fixture to stdout instead of ietf/name/fixtures/names.json")
38+
39+
def say(self, msg):
40+
if self.verbosity > 0:
41+
sys.stdout.write(msg)
42+
sys.stdout.write('\n')
43+
44+
def note(self, msg):
45+
if self.verbosity > 1:
46+
sys.stdout.write(msg)
47+
sys.stdout.write('\n')
48+
49+
def mutter(self, msg):
50+
if self.verbosity > 2:
51+
sys.stdout.write(msg)
52+
sys.stdout.write('\n')
53+
54+
def handle(self, *args, **options):
55+
self.output = sys.stdout if options.get('stdout') else io.open(os.path.join(settings.BASE_DIR, "name/fixtures/names.json"), 'w')
56+
57+
def model_name(m):
58+
return '%s.%s' % (m._meta.app_label, m.__name__)
59+
60+
def output(seq):
61+
try:
62+
f = self.output
63+
f.write(serialize("json", seq, cls=SortedJsonEncoder, indent=2))
64+
f.close()
65+
except:
66+
from django.db import connection
67+
from pprint import pprint
68+
pprint(connection.queries)
69+
raise
70+
71+
objects = [] # type: List[object]
72+
model_objects = {}
73+
74+
import ietf.name.models
75+
from ietf.dbtemplate.models import DBTemplate
76+
from ietf.doc.models import BallotType, State, StateType
77+
from ietf.group.models import GroupFeatures
78+
from ietf.mailtrigger.models import MailTrigger, Recipient
79+
from ietf.stats.models import CountryAlias
80+
from ietf.utils.models import VersionInfo
81+
82+
# Grab all ietf.name.models
83+
for n in dir(ietf.name.models):
84+
item = getattr(ietf.name.models, n)
85+
if inspect.isclass(item) and issubclass(item, ietf.name.models.NameModel):
86+
if not item._meta.abstract:
87+
model_objects[model_name(item)] = list(item.objects.all().order_by('pk'))
88+
89+
90+
for m in ( BallotType, State, StateType, GroupFeatures, MailTrigger, Recipient, CountryAlias, VersionInfo ):
91+
model_objects[model_name(m)] = list(m.objects.all().order_by('pk'))
92+
93+
for m in ( DBTemplate, ):
94+
model_objects[model_name(m)] = [ m.objects.get(pk=354) ]
95+
96+
for model_name in sorted(model_objects.keys()):
97+
objects += model_objects[model_name]
98+
99+
output(objects)
100+

0 commit comments

Comments
 (0)