Skip to content

Commit

Permalink
Use factories for ietf.idindex.tests. Commit ready for merge.
Browse files Browse the repository at this point in the history
 - Legacy-Id: 15380
  • Loading branch information
rjsparks committed Jul 18, 2018
1 parent 61932cb commit 2159fdd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ietf/doc/factories.py
Expand Up @@ -52,7 +52,7 @@ def authors(obj, create, extracted, **kwargs): # pylint: disable=no-self-argumen
if create and extracted:
order = 0
for person in extracted:
DocumentAuthor.objects.create(document=obj, person=person, order=order)
DocumentAuthor.objects.create(document=obj, person=person, email=person.email(), order=order)
order += 1

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions ietf/idindex/index.py
Expand Up @@ -3,6 +3,8 @@

import datetime, os

import debug # pyflakes:ignore

import pytz

from django.conf import settings
Expand Down
33 changes: 18 additions & 15 deletions ietf/idindex/tests.py
@@ -1,14 +1,20 @@
# -*- coding: utf-8 -*-

import os
import datetime
import shutil

import debug # pyflakes:ignore

from django.conf import settings

from ietf.doc.factories import WgDraftFactory
from ietf.doc.models import Document, DocAlias, RelatedDocument, State, LastCallDocEvent, NewRevisionDocEvent
from ietf.group.factories import GroupFactory
from ietf.name.models import DocRelationshipName
from ietf.idindex.index import all_id_txt, all_id2_txt, id_index_txt
from ietf.person.factories import PersonFactory, EmailFactory
from ietf.utils.test_utils import TestCase
from ietf.utils.test_data import make_test_data

class IndexTests(TestCase):
def setUp(self):
Expand All @@ -25,11 +31,7 @@ def write_draft_file(self, name, size):
f.write("a" * size)

def test_all_id_txt(self):
draft = make_test_data()

# active in IESG process
draft.set_state(State.objects.get(type="draft", slug="active"))
draft.set_state(State.objects.get(type="draft-iesg", slug="lc"))
draft = WgDraftFactory(states=[('draft','active'),('draft-iesg','lc')])

txt = all_id_txt()

Expand Down Expand Up @@ -64,17 +66,20 @@ def test_all_id_txt(self):
self.assertTrue("Replaced replaced by draft-test-replacement" in txt)

def test_all_id2_txt(self):
draft = make_test_data()

draft = WgDraftFactory(
states=[('draft','active'),('draft-iesg','review-e')],
ad=PersonFactory(),
shepherd=EmailFactory(address='shepherd@example.com',person__name=u'Draft δραφτυ Shepherd'),
group__parent=GroupFactory(type_id='area'),
intended_std_level_id = 'ps',
authors=[EmailFactory().person]
)
def get_fields(content):
self.assertTrue(draft.name + "-" + draft.rev in content)

for line in content.splitlines():
if line.startswith(draft.name + "-" + draft.rev):
return line.split("\t")
# test Active
draft.set_state(State.objects.get(type="draft", slug="active"))
draft.set_state(State.objects.get(type="draft-iesg", slug="review-e"))

NewRevisionDocEvent.objects.create(doc=draft, rev=draft.rev, type="new_revision", by=draft.ad)

Expand All @@ -98,7 +103,7 @@ def get_fields(content):
self.assertEqual(t[13], draft.title)
author = draft.documentauthor_set.order_by("order").get()
self.assertEqual(t[14], u"%s <%s>" % (author.person.name, author.email.address))
self.assertEqual(t[15], u"%s <%s>" % (draft.shepherd.person.name, draft.shepherd.address))
self.assertEqual(t[15], u"%s <%s>" % (draft.shepherd.person.plain_ascii(), draft.shepherd.address))
self.assertEqual(t[16], u"%s <%s>" % (draft.ad.plain_ascii(), draft.ad.email_address()))


Expand Down Expand Up @@ -129,9 +134,7 @@ def get_fields(content):


def test_id_index_txt(self):
draft = make_test_data()

draft.set_state(State.objects.get(type="draft", slug="active"))
draft = WgDraftFactory(states=[('draft','active')],abstract='a'*20,authors=[PersonFactory()])

txt = id_index_txt()

Expand Down

0 comments on commit 2159fdd

Please sign in to comment.