Converted the liaisons tests to use factories. Commit ready for merge.

- Legacy-Id: 15523
This commit is contained in:
Robert Sparks 2018-10-05 21:50:20 +00:00
parent 775addc616
commit 5e29f56494
2 changed files with 162 additions and 175 deletions

View file

@ -0,0 +1,51 @@
import factory
from ietf.group.factories import GroupFactory
from ietf.liaisons.models import LiaisonStatement, LiaisonStatementEvent, LiaisonStatementAttachment
class LiaisonStatementFactory(factory.DjangoModelFactory):
class Meta:
model = LiaisonStatement
title = factory.Faker('sentence')
from_contact = factory.SubFactory('ietf.person.factories.EmailFactory')
purpose_id = 'comment'
body = factory.Faker('paragraph')
state_id = 'posted'
@factory.post_generation
def from_groups(obj, create, extracted, **kwargs):
if create:
if extracted:
obj.from_groups.set(extracted)
else:
obj.from_groups.add(GroupFactory(type_id='sdo'))
@factory.post_generation
def to_groups(obj, create, extracted, **kwargs):
if create:
if extracted:
obj.to_groups.set(extracted)
else:
obj.to_groups.add(GroupFactory(type_id='wg'))
class LiaisonStatementEventFactory(factory.DjangoModelFactory):
class Meta:
model = LiaisonStatementEvent
type_id = 'posted'
by = factory.SubFactory('ietf.person.factories.PersonFactory')
statement = factory.SubFactory(LiaisonStatementFactory)
desc = factory.Faker('sentence')
class LiaisonStatementAttachmentFactory(factory.DjangoModelFactory):
class Meta:
model = LiaisonStatementAttachment
statement = factory.SubFactory(LiaisonStatementFactory)
document = factory.SubFactory('ietf.doc.factories.BaseDocumentFactory',
type_id='liai-att',
# TODO: Make name more convenient (the default now is to try to generate a draftname)
)

View file

@ -1,6 +1,8 @@
import datetime, os, shutil import datetime, os, shutil
import json import json
import debug # pyflakes:ignore
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.urls import reverse as urlreverse from django.urls import reverse as urlreverse
@ -9,14 +11,14 @@ from StringIO import StringIO
from pyquery import PyQuery from pyquery import PyQuery
from ietf.utils.test_utils import TestCase, login_testing_unauthorized, unicontent from ietf.utils.test_utils import TestCase, login_testing_unauthorized, unicontent
from ietf.utils.test_data import make_test_data, create_person
from ietf.utils.mail import outbox from ietf.utils.mail import outbox
from ietf.doc.models import Document from ietf.group.factories import GroupFactory, RoleFactory
from ietf.liaisons.factories import ( LiaisonStatementFactory,
LiaisonStatementEventFactory, LiaisonStatementAttachmentFactory, )
from ietf.liaisons.models import (LiaisonStatement, LiaisonStatementPurposeName, from ietf.liaisons.models import (LiaisonStatement, LiaisonStatementPurposeName,
LiaisonStatementState, LiaisonStatementEvent, LiaisonStatementGroupContacts, LiaisonStatementGroupContacts, LiaisonStatementAttachment)
LiaisonStatementAttachment) from ietf.person.models import Person
from ietf.person.models import Person, Email
from ietf.group.models import Group from ietf.group.models import Group
from ietf.liaisons.mails import send_sdo_reminder, possibly_send_deadline_reminder from ietf.liaisons.mails import send_sdo_reminder, possibly_send_deadline_reminder
from ietf.liaisons.views import contacts_from_roles from ietf.liaisons.views import contacts_from_roles
@ -25,63 +27,6 @@ from ietf.liaisons.views import contacts_from_roles
# Helper Functions # Helper Functions
# ------------------------------------------------- # -------------------------------------------------
def make_liaison_models():
sdo = Group.objects.create(
name="United League of Marsmen",
acronym="ulm",
state_id="active",
type_id="sdo",
)
Group.objects.create(
name="Standards Development Organization",
acronym="sdo",
state_id="active",
type_id="sdo",
)
# liaison manager
create_person(sdo, 'liaiman')
create_person(sdo, 'auth')
by = Person.objects.get(name='Ulm Liaiman')
mars_group = Group.objects.get(acronym="mars")
create_person(mars_group, 'secr')
create_person(Group.objects.get(acronym='iab'), "execdir")
# add an incoming liaison
s = LiaisonStatement.objects.create(
title="Comment from United League of Marsmen",
purpose_id="comment",
body="The recently proposed Martian Standard for Communication Links neglects the special ferro-magnetic conditions of the Martian soil.",
deadline=datetime.date.today() + datetime.timedelta(days=7),
from_contact=Email.objects.last(),
to_contacts="%s@ietf.org" % mars_group.acronym,
state_id='posted',
)
s.from_groups.add(sdo)
s.to_groups.add(mars_group)
LiaisonStatementEvent.objects.create(type_id='submitted',by=by,statement=s,desc='Statement Submitted')
LiaisonStatementEvent.objects.create(type_id='posted',by=by,statement=s,desc='Statement Posted')
doc = Document.objects.first()
LiaisonStatementAttachment.objects.create(statement=s,document=doc)
# add an outgoing liaison (dated 2010)
s2 = LiaisonStatement.objects.create(
title="Comment from Mars Group on video codec",
purpose_id="comment",
body="Hello, this is an interesting statement.",
from_contact=Email.objects.last(),
to_contacts="%s@ietf.org" % mars_group.acronym,
state_id='posted',
)
s2.from_groups.add(mars_group)
s2.to_groups.add(sdo)
LiaisonStatementEvent.objects.create(type_id='submitted',by=by,statement=s2,desc='Statement Submitted')
LiaisonStatementEvent.objects.create(type_id='posted',by=by,statement=s2,desc='Statement Posted')
s2.liaisonstatementevent_set.update(time=datetime.datetime(2010,1,1))
return s
def get_liaison_post_data(type='incoming'): def get_liaison_post_data(type='incoming'):
'''Return a dictionary containing basic liaison entry data''' '''Return a dictionary containing basic liaison entry data'''
@ -108,24 +53,21 @@ def get_liaison_post_data(type='incoming'):
class LiaisonTests(TestCase): class LiaisonTests(TestCase):
def test_overview(self): def test_overview(self):
make_test_data() liaison = LiaisonStatementFactory()
liaison = make_liaison_models()
r = self.client.get(urlreverse('ietf.liaisons.views.liaison_list')) r = self.client.get(urlreverse('ietf.liaisons.views.liaison_list'))
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
self.assertTrue(liaison.title in unicontent(r)) self.assertTrue(liaison.title in unicontent(r))
def test_details(self): def test_details(self):
make_test_data() liaison = LiaisonStatementFactory()
liaison = make_liaison_models()
r = self.client.get(urlreverse("ietf.liaisons.views.liaison_detail", kwargs={ 'object_id': liaison.pk })) r = self.client.get(urlreverse("ietf.liaisons.views.liaison_detail", kwargs={ 'object_id': liaison.pk }))
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
self.assertTrue(liaison.title in unicontent(r)) self.assertTrue(liaison.title in unicontent(r))
def test_feeds(self): def test_feeds(self):
make_test_data() liaison = LiaisonStatementFactory(title="Comment from United League of Marsmen")
liaison = make_liaison_models()
r = self.client.get('/feed/liaison/recent/') r = self.client.get('/feed/liaison/recent/')
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
@ -144,8 +86,7 @@ class LiaisonTests(TestCase):
self.assertTrue(liaison.title in unicontent(r)) self.assertTrue(liaison.title in unicontent(r))
def test_sitemap(self): def test_sitemap(self):
make_test_data() liaison = LiaisonStatementFactory()
liaison = make_liaison_models()
r = self.client.get('/sitemap-liaison.xml') r = self.client.get('/sitemap-liaison.xml')
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
@ -160,8 +101,6 @@ class LiaisonTests(TestCase):
class UnitTests(TestCase): class UnitTests(TestCase):
def test_get_cc(self): def test_get_cc(self):
make_test_data()
make_liaison_models()
from ietf.liaisons.views import get_cc,EMAIL_ALIASES from ietf.liaisons.views import get_cc,EMAIL_ALIASES
# test IETF # test IETF
@ -184,17 +123,15 @@ class UnitTests(TestCase):
self.assertTrue(contacts_from_roles([wg.parent.ad_role()]) in cc) self.assertTrue(contacts_from_roles([wg.parent.ad_role()]) in cc)
self.assertTrue(contacts_from_roles([wg.get_chair()]) in cc) self.assertTrue(contacts_from_roles([wg.get_chair()]) in cc)
# test an SDO # test an SDO
sdo = Group.objects.filter(type='sdo').first() sdo = RoleFactory(name_id='liaiman',group__type_id='sdo',).group
cc = get_cc(sdo) cc = get_cc(sdo)
self.assertTrue(contacts_from_roles([sdo.role_set.filter(name='liaiman').first()]) in cc) self.assertTrue(contacts_from_roles([sdo.role_set.filter(name='liaiman').first()]) in cc)
def test_get_contacts_for_group(self): def test_get_contacts_for_group(self):
make_test_data()
make_liaison_models()
from ietf.liaisons.views import get_contacts_for_group, EMAIL_ALIASES from ietf.liaisons.views import get_contacts_for_group, EMAIL_ALIASES
# test explicit # test explicit
sdo = Group.objects.filter(type='sdo').first() sdo = GroupFactory(type_id='sdo')
LiaisonStatementGroupContacts.objects.create(group=sdo,contacts='bob@world.com') LiaisonStatementGroupContacts.objects.create(group=sdo,contacts='bob@world.com')
contacts = get_contacts_for_group(sdo) contacts = get_contacts_for_group(sdo)
self.assertTrue('bob@world.com' in contacts) self.assertTrue('bob@world.com' in contacts)
@ -218,8 +155,6 @@ class UnitTests(TestCase):
self.assertTrue(EMAIL_ALIASES['IESG'] in contacts) self.assertTrue(EMAIL_ALIASES['IESG'] in contacts)
def test_needs_approval(self): def test_needs_approval(self):
make_test_data()
make_liaison_models()
from ietf.liaisons.views import needs_approval from ietf.liaisons.views import needs_approval
group = Group.objects.get(acronym='ietf') group = Group.objects.get(acronym='ietf')
@ -232,8 +167,8 @@ class UnitTests(TestCase):
self.assertFalse(needs_approval(wg,wg.parent.ad_role().person)) self.assertFalse(needs_approval(wg,wg.parent.ad_role().person))
def test_approvable_liaison_statements(self): def test_approvable_liaison_statements(self):
make_test_data() source_wg = RoleFactory(name_id='ad',group__type_id='wg').group
make_liaison_models() LiaisonStatementFactory(from_groups = [ source_wg, ], to_groups = [ GroupFactory(type_id='sdo'), ])
from ietf.liaisons.utils import approvable_liaison_statements from ietf.liaisons.utils import approvable_liaison_statements
outgoing = LiaisonStatement.objects.filter(to_groups__type='sdo').first() outgoing = LiaisonStatement.objects.filter(to_groups__type='sdo').first()
@ -246,9 +181,7 @@ class UnitTests(TestCase):
class AjaxTests(TestCase): class AjaxTests(TestCase):
def test_ajax(self): def test_ajax(self):
make_test_data() LiaisonStatementFactory() # This test needs improvement. It passes without this object present.
make_liaison_models()
url = urlreverse('ietf.liaisons.views.ajax_get_liaison_info') + "?to_groups=&from_groups=" url = urlreverse('ietf.liaisons.views.ajax_get_liaison_info') + "?to_groups=&from_groups="
self.client.login(username="secretary", password="secretary+password") self.client.login(username="secretary", password="secretary+password")
r = self.client.get(url) r = self.client.get(url)
@ -262,9 +195,9 @@ class AjaxTests(TestCase):
self.assertTrue('response_contacts' in data) self.assertTrue('response_contacts' in data)
def test_ajax_to_contacts(self): def test_ajax_to_contacts(self):
make_test_data() area = RoleFactory(name_id='ad',group__type_id='area').group
liaison = make_liaison_models() group = GroupFactory(parent=area)
group = liaison.to_groups.first() LiaisonStatementFactory(to_groups=[group,])
LiaisonStatementGroupContacts.objects.create(group=group,contacts='test@example.com') LiaisonStatementGroupContacts.objects.create(group=group,contacts='test@example.com')
url = urlreverse('ietf.liaisons.views.ajax_get_liaison_info') + "?to_groups={}&from_groups=".format(group.pk) url = urlreverse('ietf.liaisons.views.ajax_get_liaison_info') + "?to_groups={}&from_groups=".format(group.pk)
@ -275,8 +208,7 @@ class AjaxTests(TestCase):
self.assertEqual(data["to_contacts"],[u'test@example.com']) self.assertEqual(data["to_contacts"],[u'test@example.com'])
def test_ajax_select2_search_liaison_statements(self): def test_ajax_select2_search_liaison_statements(self):
make_test_data() liaison = LiaisonStatementFactory()
liaison = make_liaison_models()
# test text search # test text search
url = urlreverse('ietf.liaisons.views.ajax_select2_search_liaison_statements') + "?q=%s" % liaison.title[:5] url = urlreverse('ietf.liaisons.views.ajax_select2_search_liaison_statements') + "?q=%s" % liaison.title[:5]
@ -296,22 +228,20 @@ class AjaxTests(TestCase):
class ManagementCommandTests(TestCase): class ManagementCommandTests(TestCase):
def test_check_liaison_deadlines(self): def test_check_liaison_deadlines(self):
make_test_data()
liaison = make_liaison_models()
from django.core.management import call_command from django.core.management import call_command
LiaisonStatementFactory(deadline=datetime.date.today()+datetime.timedelta(days=1))
out = StringIO() out = StringIO()
liaison.deadline = datetime.datetime.today() + datetime.timedelta(1)
liaison.save()
mailbox_before = len(outbox) mailbox_before = len(outbox)
call_command('check_liaison_deadlines',stdout=out) call_command('check_liaison_deadlines',stdout=out)
self.assertEqual(len(outbox), mailbox_before + 1) self.assertEqual(len(outbox), mailbox_before + 1)
def test_remind_update_sdo_list(self): def test_remind_update_sdo_list(self):
make_test_data()
make_liaison_models()
from django.core.management import call_command from django.core.management import call_command
RoleFactory(name_id='liaiman',group__type_id='sdo')
out = StringIO() out = StringIO()
mailbox_before = len(outbox) mailbox_before = len(outbox)
call_command('remind_update_sdo_list',stdout=out) call_command('remind_update_sdo_list',stdout=out)
@ -329,9 +259,6 @@ class LiaisonManagementTests(TestCase):
shutil.rmtree(self.liaison_dir) shutil.rmtree(self.liaison_dir)
def test_add_restrictions(self): def test_add_restrictions(self):
make_test_data()
make_liaison_models()
# incoming restrictions # incoming restrictions
url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'}) url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'})
self.client.login(username="secretary", password="secretary+password") self.client.login(username="secretary", password="secretary+password")
@ -339,8 +266,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
def test_add_comment(self): def test_add_comment(self):
make_test_data() liaison = LiaisonStatementFactory()
liaison = make_liaison_models()
# test unauthorized # test unauthorized
addurl = urlreverse('ietf.liaisons.views.add_comment',kwargs=dict(object_id=liaison.pk)) addurl = urlreverse('ietf.liaisons.views.add_comment',kwargs=dict(object_id=liaison.pk))
@ -379,8 +305,7 @@ class LiaisonManagementTests(TestCase):
self.assertFalse('Private comment' in r.content) self.assertFalse('Private comment' in r.content)
def test_taken_care_of(self): def test_taken_care_of(self):
make_test_data() liaison = LiaisonStatementFactory(deadline=datetime.date.today()+datetime.timedelta(days=1))
liaison = make_liaison_models()
url = urlreverse('ietf.liaisons.views.liaison_detail', kwargs=dict(object_id=liaison.pk)) url = urlreverse('ietf.liaisons.views.liaison_detail', kwargs=dict(object_id=liaison.pk))
# normal get # normal get
@ -406,15 +331,12 @@ class LiaisonManagementTests(TestCase):
self.assertTrue(liaison.action_taken) self.assertTrue(liaison.action_taken)
def test_approval_process(self): def test_approval_process(self):
make_test_data()
liaison = make_liaison_models()
# must be outgoing liaison to need approval # must be outgoing liaison to need approval
liaison.from_groups.clear() liaison = LiaisonStatementFactory(
liaison.to_groups.clear() state_id = 'pending',
liaison.from_groups.add(Group.objects.get(acronym="mars")) from_groups = [GroupFactory(type_id='wg'),],
liaison.to_groups.add(Group.objects.get(acronym='ulm')) to_groups = [RoleFactory(name_id='liaiman', person__user__username='ulm-liaiman', group__type_id='sdo').group],
liaison.state=LiaisonStatementState.objects.get(slug='pending') )
liaison.save()
# check the overview page # check the overview page
url = urlreverse('ietf.liaisons.views.liaison_list', kwargs=dict(state='pending')) url = urlreverse('ietf.liaisons.views.liaison_list', kwargs=dict(state='pending'))
@ -457,8 +379,9 @@ class LiaisonManagementTests(TestCase):
self.assertTrue(liaison.liaisonstatementevent_set.filter(type='posted')) self.assertTrue(liaison.liaisonstatementevent_set.filter(type='posted'))
def test_edit_liaison(self): def test_edit_liaison(self):
make_test_data() liaison = LiaisonStatementFactory(deadline=datetime.date.today()+datetime.timedelta(days=1))
liaison = make_liaison_models() LiaisonStatementEventFactory(statement=liaison,type_id='submitted', time=datetime.datetime.now()-datetime.timedelta(days=1))
LiaisonStatementEventFactory(statement=liaison,type_id='posted')
from_group = liaison.from_groups.first() from_group = liaison.from_groups.first()
to_group = liaison.to_groups.first() to_group = liaison.to_groups.first()
@ -519,8 +442,11 @@ class LiaisonManagementTests(TestCase):
'''Ensure only Secretariat, Liaison Managers, and Authorized Individuals '''Ensure only Secretariat, Liaison Managers, and Authorized Individuals
have access to incoming liaisons. have access to incoming liaisons.
''' '''
make_test_data() sdo = RoleFactory(name_id='liaiman',group__type_id='sdo', person__user__username='ulm-liaiman').group
make_liaison_models() RoleFactory(name_id='auth',group=sdo,person__user__username='ulm-auth')
stmt = LiaisonStatementFactory(from_groups=[sdo,])
LiaisonStatementEventFactory(statement=stmt,type_id='posted')
RoleFactory(name_id='chair',person__user__username='marschairman',group__acronym='mars')
url = urlreverse('ietf.liaisons.views.liaison_list') url = urlreverse('ietf.liaisons.views.liaison_list')
addurl = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'}) addurl = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'})
@ -569,8 +495,13 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
def test_outgoing_access(self): def test_outgoing_access(self):
make_test_data()
make_liaison_models() sdo = RoleFactory(name_id='liaiman',group__type_id='sdo', person__user__username='ulm-liaiman').group
RoleFactory(name_id='auth',group=sdo,person__user__username='ulm-auth')
mars = RoleFactory(name_id='chair',person__user__username='marschairman',group__acronym='mars').group
RoleFactory(name_id='secr',group=mars,person__user__username='mars-secr')
RoleFactory(name_id='execdir',group=Group.objects.get(acronym='iab'),person__user__username='iab-execdir')
url = urlreverse('ietf.liaisons.views.liaison_list') url = urlreverse('ietf.liaisons.views.liaison_list')
addurl = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'outgoing'}) addurl = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'outgoing'})
@ -583,7 +514,7 @@ class LiaisonManagementTests(TestCase):
self.assertRedirects(r,settings.LOGIN_URL + '?next=/liaison/add/outgoing/') self.assertRedirects(r,settings.LOGIN_URL + '?next=/liaison/add/outgoing/')
# AD has access # AD has access
self.client.login(username="ad", password="ad+password") self.assertTrue(self.client.login(username="ad", password="ad+password"))
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
q = PyQuery(r.content) q = PyQuery(r.content)
@ -592,7 +523,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
# WG Chair has access # WG Chair has access
self.client.login(username="marschairman", password="marschairman+password") self.assertTrue(self.client.login(username="marschairman", password="marschairman+password"))
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
q = PyQuery(r.content) q = PyQuery(r.content)
@ -601,7 +532,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
# WG Secretary has access # WG Secretary has access
self.client.login(username="mars-secr", password="mars-secr+password") self.assertTrue(self.client.login(username="mars-secr", password="mars-secr+password"))
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
q = PyQuery(r.content) q = PyQuery(r.content)
@ -610,7 +541,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
# IETF Chair has access # IETF Chair has access
self.client.login(username="ietf-chair", password="ietf-chair+password") self.assertTrue(self.client.login(username="ietf-chair", password="ietf-chair+password"))
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
q = PyQuery(r.content) q = PyQuery(r.content)
@ -619,7 +550,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
# IAB Chair has access # IAB Chair has access
self.client.login(username="iab-chair", password="iab-chair+password") self.assertTrue(self.client.login(username="iab-chair", password="iab-chair+password"))
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
q = PyQuery(r.content) q = PyQuery(r.content)
@ -628,7 +559,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
# IAB Executive Director # IAB Executive Director
self.client.login(username="iab-execdir", password="iab-execdir+password") self.assertTrue(self.client.login(username="iab-execdir", password="iab-execdir+password"))
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
q = PyQuery(r.content) q = PyQuery(r.content)
@ -637,7 +568,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
# Liaison Manager has access # Liaison Manager has access
self.client.login(username="ulm-liaiman", password="ulm-liaiman+password") self.assertTrue(self.client.login(username="ulm-liaiman", password="ulm-liaiman+password"))
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
q = PyQuery(r.content) q = PyQuery(r.content)
@ -646,7 +577,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
# Authorized Individual has no access # Authorized Individual has no access
self.client.login(username="ulm-auth", password="ulm-auth+password") self.assertTrue(self.client.login(username="ulm-auth", password="ulm-auth+password"))
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
q = PyQuery(r.content) q = PyQuery(r.content)
@ -655,7 +586,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 403) self.assertEqual(r.status_code, 403)
# Secretariat has access # Secretariat has access
self.client.login(username="secretary", password="secretary+password") self.assertTrue(self.client.login(username="secretary", password="secretary+password"))
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
q = PyQuery(r.content) q = PyQuery(r.content)
@ -665,8 +596,9 @@ class LiaisonManagementTests(TestCase):
def test_incoming_options(self): def test_incoming_options(self):
'''Check from_groups, to_groups options for different user classes''' '''Check from_groups, to_groups options for different user classes'''
make_test_data()
make_liaison_models() RoleFactory(name_id='liaiman',group__type_id='sdo', person__user__username='ulm-liaiman')
url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'}) url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'})
# get count of all IETF entities for to_group options # get count of all IETF entities for to_group options
@ -697,8 +629,9 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(len(q('select#id_to_groups option')), all_entity_count) self.assertEqual(len(q('select#id_to_groups option')), all_entity_count)
def test_outgoing_options(self): def test_outgoing_options(self):
make_test_data() RoleFactory(name_id='liaiman',group__type_id='sdo', person__user__username='ulm-liaiman')
make_liaison_models() RoleFactory(name_id='chair',person__user__username='marschairman',group__acronym='mars')
url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'outgoing'}) url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'outgoing'})
# get count of all IETF entities for to_group options # get count of all IETF entities for to_group options
@ -737,8 +670,10 @@ class LiaisonManagementTests(TestCase):
def test_add_incoming_liaison(self): def test_add_incoming_liaison(self):
make_test_data() sdo = RoleFactory(name_id='liaiman',group__type_id='sdo', person__user__username='ulm-liaiman').group
liaison = make_liaison_models() GroupFactory(type_id='sdo') # This test assumes there are two sdo groups in the database
wg = RoleFactory(name_id='chair',person__user__username='marschairman',group__acronym='mars').group
liaison = LiaisonStatementFactory(from_groups=[wg,],to_groups=[sdo,])
url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'}) url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'})
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
@ -814,8 +749,10 @@ class LiaisonManagementTests(TestCase):
self.assertTrue('cc@' in outbox[-1]['Cc']) self.assertTrue('cc@' in outbox[-1]['Cc'])
def test_add_outgoing_liaison(self): def test_add_outgoing_liaison(self):
make_test_data() RoleFactory(name_id='liaiman',group__type_id='sdo', person__user__username='ulm-liaiman').group
liaison = make_liaison_models() wg = RoleFactory(name_id='chair',person__user__username='marschairman',group__acronym='mars').group
RoleFactory(name_id='ad',person=Person.objects.get(user__username='ad'),group=wg)
liaison = LiaisonStatementFactory()
url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'outgoing'}) url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'outgoing'})
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
@ -889,8 +826,9 @@ class LiaisonManagementTests(TestCase):
self.assertTrue('aread@' in outbox[-1]['To']) self.assertTrue('aread@' in outbox[-1]['To'])
def test_add_outgoing_liaison_unapproved_post_only(self): def test_add_outgoing_liaison_unapproved_post_only(self):
make_test_data() RoleFactory(name_id='liaiman',group__type_id='sdo', person__user__username='ulm-liaiman')
make_liaison_models() mars = RoleFactory(name_id='chair',person__user__username='marschairman',group__acronym='mars').group
RoleFactory(name_id='ad',group=mars)
url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'outgoing'}) url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'outgoing'})
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
@ -919,8 +857,11 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(len(outbox), mailbox_before + 1) self.assertEqual(len(outbox), mailbox_before + 1)
def test_liaison_add_attachment(self): def test_liaison_add_attachment(self):
make_test_data() liaison = LiaisonStatementFactory(deadline=datetime.date.today()+datetime.timedelta(days=1))
liaison = make_liaison_models() LiaisonStatementEventFactory(statement=liaison,type_id='submitted')
self.assertEqual(liaison.attachments.count(),0)
# get minimum edit post data # get minimum edit post data
file = StringIO('dummy file') file = StringIO('dummy file')
@ -942,33 +883,31 @@ class LiaisonManagementTests(TestCase):
url = urlreverse('ietf.liaisons.views.liaison_edit', kwargs=dict(object_id=liaison.pk)) url = urlreverse('ietf.liaisons.views.liaison_edit', kwargs=dict(object_id=liaison.pk))
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
r = self.client.post(url,post_data) r = self.client.post(url,post_data)
if r.status_code != 302: #if r.status_code != 302:
q = PyQuery(r.content) # q = PyQuery(r.content)
print(q('div.has-error div.alert').text()) # print(q('div.has-error div.alert').text())
print r.content # print r.content
self.assertEqual(r.status_code, 302) self.assertEqual(r.status_code, 302)
self.assertEqual(liaison.attachments.count(),2) self.assertEqual(liaison.attachments.count(),1)
event = liaison.liaisonstatementevent_set.order_by('id').last() event = liaison.liaisonstatementevent_set.order_by('id').last()
self.assertTrue(event.desc.startswith('Added attachment')) self.assertTrue(event.desc.startswith('Added attachment'))
def test_liaison_edit_attachment(self): def test_liaison_edit_attachment(self):
make_test_data()
make_liaison_models()
attachment = LiaisonStatementAttachment.objects.first() attachment = LiaisonStatementAttachmentFactory(document__name='liaiatt-1')
url = urlreverse('ietf.liaisons.views.liaison_edit_attachment', kwargs=dict(object_id=attachment.statement_id,doc_id=attachment.document_id)) url = urlreverse('ietf.liaisons.views.liaison_edit_attachment', kwargs=dict(object_id=attachment.statement_id,doc_id=attachment.document_id))
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
post_data = dict(title='New Title') post_data = dict(title='New Title')
r = self.client.post(url,post_data) r = self.client.post(url,post_data)
attachment = LiaisonStatementAttachment.objects.get(pk=attachment.pk)
self.assertEqual(r.status_code, 302) self.assertEqual(r.status_code, 302)
self.assertEqual(attachment.document.title,'New Title') self.assertEqual(attachment.document.title,'New Title')
def test_liaison_delete_attachment(self): def test_liaison_delete_attachment(self):
make_test_data() attachment = LiaisonStatementAttachmentFactory(document__name='liaiatt-1')
liaison = make_liaison_models() liaison = attachment.statement
attachment = LiaisonStatementAttachment.objects.get(statement=liaison)
url = urlreverse('ietf.liaisons.views.liaison_delete_attachment', kwargs=dict(object_id=liaison.pk,attach_id=attachment.pk)) url = urlreverse('ietf.liaisons.views.liaison_delete_attachment', kwargs=dict(object_id=liaison.pk,attach_id=attachment.pk))
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
r = self.client.get(url) r = self.client.get(url)
@ -977,8 +916,8 @@ class LiaisonManagementTests(TestCase):
def test_in_response(self): def test_in_response(self):
'''A statement with purpose=in_response must have related statement specified''' '''A statement with purpose=in_response must have related statement specified'''
make_test_data() GroupFactory(type_id='wg',acronym='mars')
make_liaison_models() GroupFactory(type_id='sdo',acronym='ulm')
url = urlreverse('ietf.liaisons.views.liaison_add',kwargs=dict(type='incoming')) url = urlreverse('ietf.liaisons.views.liaison_add',kwargs=dict(type='incoming'))
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
@ -990,8 +929,7 @@ class LiaisonManagementTests(TestCase):
self.assertTrue(q("form .has-error")) self.assertTrue(q("form .has-error"))
def test_liaison_history(self): def test_liaison_history(self):
make_test_data() liaison = LiaisonStatementFactory()
liaison = make_liaison_models()
url = urlreverse('ietf.liaisons.views.liaison_history',kwargs=dict(object_id=liaison.pk)) url = urlreverse('ietf.liaisons.views.liaison_history',kwargs=dict(object_id=liaison.pk))
r = self.client.get(url) r = self.client.get(url)
@ -1001,8 +939,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(len(q('tr')),event_count + 1) # +1 for header row self.assertEqual(len(q('tr')),event_count + 1) # +1 for header row
def test_resend_liaison(self): def test_resend_liaison(self):
make_test_data() liaison = LiaisonStatementFactory()
liaison = make_liaison_models()
url = urlreverse('ietf.liaisons.views.liaison_resend',kwargs=dict(object_id=liaison.pk)) url = urlreverse('ietf.liaisons.views.liaison_resend',kwargs=dict(object_id=liaison.pk))
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
@ -1015,8 +952,9 @@ class LiaisonManagementTests(TestCase):
self.assertTrue(liaison.liaisonstatementevent_set.filter(type='resent')) self.assertTrue(liaison.liaisonstatementevent_set.filter(type='resent'))
def test_kill_liaison(self): def test_kill_liaison(self):
make_test_data() mars = GroupFactory(type_id='wg',acronym='mars')
liaison = make_liaison_models() sdo = GroupFactory(type_id='sdo')
liaison = LiaisonStatementFactory(from_groups=[mars,], to_groups=[sdo,], state_id='pending')
# must be outgoing liaison to need approval # must be outgoing liaison to need approval
liaison.from_groups.clear() liaison.from_groups.clear()
liaison.from_groups.add(Group.objects.get(acronym="mars")) liaison.from_groups.add(Group.objects.get(acronym="mars"))
@ -1033,9 +971,7 @@ class LiaisonManagementTests(TestCase):
self.assertTrue(liaison.liaisonstatementevent_set.filter(type='killed')) self.assertTrue(liaison.liaisonstatementevent_set.filter(type='killed'))
def test_dead_view(self): def test_dead_view(self):
make_test_data() LiaisonStatementFactory(state_id='dead')
liaison = make_liaison_models()
liaison.set_state('dead')
url = urlreverse('ietf.liaisons.views.liaison_list', kwargs=dict(state='dead')) url = urlreverse('ietf.liaisons.views.liaison_list', kwargs=dict(state='dead'))
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
@ -1046,8 +982,8 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(len(q('tr')),dead_liaison_count + 1) # +1 for header row self.assertEqual(len(q('tr')),dead_liaison_count + 1) # +1 for header row
def test_liaison_reply(self): def test_liaison_reply(self):
make_test_data() sdo = RoleFactory(name_id='liaiman',person__user__username='ulm-liaiman',group__type_id='sdo').group
liaison = make_liaison_models() liaison = LiaisonStatementFactory(from_groups=[sdo,])
# unauthorized, no reply to button # unauthorized, no reply to button
url = urlreverse('ietf.liaisons.views.liaison_detail', kwargs=dict(object_id=liaison.pk)) url = urlreverse('ietf.liaisons.views.liaison_detail', kwargs=dict(object_id=liaison.pk))
@ -1075,8 +1011,12 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(q('#id_related_to').val(),str(liaison.pk)) self.assertEqual(q('#id_related_to').val(),str(liaison.pk))
def test_search(self): def test_search(self):
make_test_data() # Statement 1
make_liaison_models() LiaisonStatementEventFactory(type_id='posted', statement__body="Has recently in its body",statement__from_groups=[GroupFactory(type_id='sdo',acronym='ulm'),])
# Statement 2
s2 = LiaisonStatementEventFactory(type_id='posted', statement__body="That word does not occur here")
s2.time=datetime.datetime(2010,1,1)
s2.save()
# test list only, no search filters # test list only, no search filters
url = urlreverse('ietf.liaisons.views.liaison_list') url = urlreverse('ietf.liaisons.views.liaison_list')
@ -1123,9 +1063,7 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(r.status_code, 302) self.assertEqual(r.status_code, 302)
def test_redirect_for_approval(self): def test_redirect_for_approval(self):
make_test_data() liaison = LiaisonStatementFactory(state_id='pending')
liaison = make_liaison_models()
liaison.set_state('pending')
self.client.login(username="secretary", password="secretary+password") self.client.login(username="secretary", password="secretary+password")
url = urlreverse('ietf.liaisons.views.redirect_for_approval') url = urlreverse('ietf.liaisons.views.redirect_for_approval')
@ -1139,8 +1077,8 @@ class LiaisonManagementTests(TestCase):
# Form validations # Form validations
# ------------------------------------------------- # -------------------------------------------------
def test_post_and_send_fail(self): def test_post_and_send_fail(self):
make_test_data() RoleFactory(name_id='liaiman',person__user__username='ulm-liaiman',group__type_id='sdo',group__acronym='ulm')
make_liaison_models() GroupFactory(type_id='wg',acronym='mars')
url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'}) url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'})
login_testing_unauthorized(self, "ulm-liaiman", url) login_testing_unauthorized(self, "ulm-liaiman", url)
@ -1155,8 +1093,8 @@ class LiaisonManagementTests(TestCase):
pass pass
def test_email_validations(self): def test_email_validations(self):
make_test_data() GroupFactory(type_id='sdo', acronym='ulm')
make_liaison_models() GroupFactory(type_id='wg', acronym='mars')
url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'}) url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'})
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
@ -1177,8 +1115,8 @@ class LiaisonManagementTests(TestCase):
self.assertEqual(len(result), 1) self.assertEqual(len(result), 1)
def test_body_or_attachment(self): def test_body_or_attachment(self):
make_test_data() GroupFactory(type_id='sdo', acronym='ulm')
make_liaison_models() GroupFactory(type_id='wg', acronym='mars')
url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'}) url = urlreverse('ietf.liaisons.views.liaison_add', kwargs={'type':'incoming'})
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
@ -1191,8 +1129,7 @@ class LiaisonManagementTests(TestCase):
self.assertTrue('You must provide a body or attachment files' in unicontent(r)) self.assertTrue('You must provide a body or attachment files' in unicontent(r))
def test_send_sdo_reminder(self): def test_send_sdo_reminder(self):
make_test_data() RoleFactory(name_id='liaiman',person__user__username='ulm-liaiman',person__user__email='ulm-liaiman@somewhere.example',group__type_id='sdo',group__acronym='ulm')
make_liaison_models()
mailbox_before = len(outbox) mailbox_before = len(outbox)
send_sdo_reminder(Group.objects.filter(type="sdo")[0]) send_sdo_reminder(Group.objects.filter(type="sdo")[0])
@ -1201,8 +1138,7 @@ class LiaisonManagementTests(TestCase):
self.assertTrue('ulm-liaiman@' in outbox[-1]['To']) self.assertTrue('ulm-liaiman@' in outbox[-1]['To'])
def test_send_liaison_deadline_reminder(self): def test_send_liaison_deadline_reminder(self):
make_test_data() liaison = LiaisonStatementFactory(deadline=datetime.date.today()+datetime.timedelta(days=1))
liaison = make_liaison_models()
mailbox_before = len(outbox) mailbox_before = len(outbox)
possibly_send_deadline_reminder(liaison) possibly_send_deadline_reminder(liaison)