forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests_views.py
More file actions
265 lines (237 loc) · 12.7 KB
/
Copy pathtests_views.py
File metadata and controls
265 lines (237 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# Copyright The IETF Trust 2013-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import datetime
import io
import os
import shutil
from collections import OrderedDict
from django.conf import settings
from django.urls import reverse as urlreverse
from django.utils.http import urlencode
from pyquery import PyQuery
import debug # pyflakes:ignore
from ietf.doc.expire import expire_draft
from ietf.doc.factories import WgDraftFactory
from ietf.doc.models import Document
from ietf.group.factories import RoleFactory
from ietf.meeting.factories import MeetingFactory
from ietf.person.factories import PersonFactory, EmailFactory
from ietf.person.models import Person
from ietf.submit.models import Preapproval
from ietf.utils.mail import outbox
from ietf.utils.test_utils import TestCase, login_testing_unauthorized
from ietf.secr.drafts.email import get_email_initial
SECR_USER='secretary'
class SecrDraftsTestCase(TestCase):
def setUp(self):
self.saved_internet_draft_path = settings.INTERNET_DRAFT_PATH
self.repository_dir = self.tempdir('submit-repository')
settings.INTERNET_DRAFT_PATH = self.repository_dir
self.saved_internet_draft_archive_dir = settings.INTERNET_DRAFT_ARCHIVE_DIR
self.archive_dir = self.tempdir('submit-archive')
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.archive_dir
self.saved_idsubmit_manual_staging_dir = settings.IDSUBMIT_MANUAL_STAGING_DIR
self.manual_dir = self.tempdir('submit-manual')
settings.IDSUBMIT_MANUAL_STAGING_DIR = self.manual_dir
def tearDown(self):
shutil.rmtree(self.repository_dir)
shutil.rmtree(self.archive_dir)
shutil.rmtree(self.manual_dir)
settings.INTERNET_DRAFT_PATH = self.saved_internet_draft_path
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.saved_internet_draft_archive_dir
settings.IDSUBMIT_MANUAL_STAGING_DIR = self.saved_idsubmit_manual_staging_dir
def test_abstract(self):
draft = WgDraftFactory()
url = urlreverse('ietf.secr.drafts.views.abstract', kwargs={'id':draft.name})
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_approvals(self):
Preapproval.objects.create(name='draft-dummy',
by=Person.objects.get(name="(System)"))
url = urlreverse('ietf.secr.drafts.views.approvals')
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(url)
self.assertContains(response, 'draft-dummy')
def test_edit(self):
draft = WgDraftFactory(states=[('draft','active'),('draft-stream-ietf','wg-doc'),('draft-iesg','ad-eval')], shepherd=EmailFactory())
url = urlreverse('ietf.secr.drafts.views.edit', kwargs={'id':draft.name})
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
response = self.client.post(url,{'title':draft.title,'name':draft.name,'rev':draft.rev,'state':4,'group':draft.group.pk,'iesg_state':draft.get_state('draft-iesg').pk})
self.assertEqual(response.status_code, 302)
draft = Document.objects.get(pk=draft.pk)
self.assertEqual(draft.get_state().slug,'repl')
def test_email(self):
# can't test this directly, test via drafts actions
pass
def test_get_email_initial(self):
# Makes sure that a manual posting by the Secretariat of an I-D that is
# in the RFC Editor Queue will result in notification of the RFC Editor
draft = WgDraftFactory(authors=PersonFactory.create_batch(1),shepherd=EmailFactory())
RoleFactory(group=draft.group, name_id='chair')
data = get_email_initial(draft,action='extend',input={'expiration_date': '2050-01-01'})
self.assertTrue('Extension of Expiration Date' in data['subject'])
def test_makerfc(self):
draft = WgDraftFactory(intended_std_level_id='ps')
url = urlreverse('ietf.secr.drafts.views.edit', kwargs={'id':draft.name})
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
# It's not clear what this is testing. Was there supposed to be a POST here?
self.assertTrue(draft.intended_std_level)
def test_search(self):
WgDraftFactory() # Test exercises branch that requires >1 doc found
draft = WgDraftFactory()
url = urlreverse('ietf.secr.drafts.views.search')
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
post = dict(filename='draft',state=1,submit='submit')
response = self.client.post(url, post)
self.assertContains(response, draft.name)
def test_view(self):
draft = WgDraftFactory()
url = urlreverse('ietf.secr.drafts.views.view', kwargs={'id':draft.name})
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_author_delete(self):
draft = WgDraftFactory(authors=PersonFactory.create_batch(2))
author = draft.documentauthor_set.first()
id = author.id
url = urlreverse('ietf.secr.drafts.views.author_delete', kwargs={'id':draft.name, 'oid':id})
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
redirect_url = urlreverse('ietf.secr.drafts.views.authors', kwargs={'id':draft.name})
response = self.client.post(url, {'post':'yes'})
self.assertRedirects(response, redirect_url)
self.assertFalse(draft.documentauthor_set.filter(id=id))
def test_resurrect(self):
draft = WgDraftFactory()
path = os.path.join(self.repository_dir, draft.filename_with_rev())
with io.open(path, 'w') as file:
file.write('test')
expire_draft(draft)
email_url = urlreverse('ietf.secr.drafts.views.email', kwargs={'id':draft.name}) + "?action=resurrect"
confirm_url = urlreverse('ietf.secr.drafts.views.confirm', kwargs={'id':draft.name})
do_action_url = urlreverse('ietf.secr.drafts.views.do_action', kwargs={'id':draft.name})
view_url = urlreverse('ietf.secr.drafts.views.view', kwargs={'id':draft.name})
subject = 'Resurrection of %s' % draft.get_base_name()
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(email_url)
self.assertContains(response, '<title>Drafts - Email</title>')
q = PyQuery(response.content)
self.assertEqual(q("#id_subject").val(), subject)
post_data = {
'action': 'resurrect',
'to': 'john@example.com',
'cc': 'joe@example.com',
'subject': subject,
'body': 'draft resurrected',
'submit': 'Save'
}
response = self.client.post(confirm_url, post_data)
self.assertContains(response, '<title>Drafts - Confirm</title>')
self.assertEqual(response.context['email']['subject'], subject)
response = self.client.post(do_action_url, post_data)
self.assertRedirects(response, view_url)
draft = Document.objects.get(name=draft.name)
self.assertTrue(draft.get_state_slug('draft') == 'active')
recv = outbox[-1]
self.assertEqual(recv['Subject'], subject)
def test_extend(self):
draft = WgDraftFactory()
url = urlreverse('ietf.secr.drafts.views.extend', kwargs={'id':draft.name})
email_url = urlreverse('ietf.secr.drafts.views.email', kwargs={'id':draft.name})
confirm_url = urlreverse('ietf.secr.drafts.views.confirm', kwargs={'id':draft.name})
do_action_url = urlreverse('ietf.secr.drafts.views.do_action', kwargs={'id':draft.name})
view_url = urlreverse('ietf.secr.drafts.views.view', kwargs={'id':draft.name})
expiration = datetime.datetime.today() + datetime.timedelta(days=180)
expiration = expiration.replace(hour=0,minute=0,second=0,microsecond=0)
subject = 'Extension of Expiration Date for %s' % draft.get_base_name()
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
extend_data = {
'action': 'extend',
'expiration_date': expiration.strftime('%Y-%m-%d'),
}
post_data = {
'action': 'extend',
'expiration_date': expiration.strftime('%Y-%m-%d'),
'to': 'john@example.com',
'cc': 'joe@example.com',
'subject': subject,
'body': 'draft extended',
'submit': 'Save'
}
response = self.client.post(url, extend_data)
self.assertRedirects(response, email_url + '?' + urlencode(extend_data))
response = self.client.post(confirm_url, post_data)
self.assertContains(response, '<title>Drafts - Confirm</title>')
self.assertEqual(response.context['email']['subject'], subject)
response = self.client.post(do_action_url, post_data)
self.assertRedirects(response, view_url)
draft = Document.objects.get(name=draft.name)
self.assertTrue(draft.expires == expiration)
recv = outbox[-1]
self.assertEqual(recv['Subject'], subject)
def test_withdraw(self):
draft = WgDraftFactory()
url = urlreverse('ietf.secr.drafts.views.withdraw', kwargs={'id':draft.name})
email_url = urlreverse('ietf.secr.drafts.views.email', kwargs={'id':draft.name})
confirm_url = urlreverse('ietf.secr.drafts.views.confirm', kwargs={'id':draft.name})
do_action_url = urlreverse('ietf.secr.drafts.views.do_action', kwargs={'id':draft.name})
view_url = urlreverse('ietf.secr.drafts.views.view', kwargs={'id':draft.name})
subject = 'Withdraw of %s' % draft.get_base_name()
self.client.login(username="secretary", password="secretary+password")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
withdraw_data = OrderedDict([('action', 'withdraw'), ('withdraw_type', 'ietf')])
post_data = {
'action': 'withdraw',
'withdraw_type': 'ietf',
'to': 'john@example.com',
'cc': 'joe@example.com',
'subject': subject,
'body': 'draft resurrected',
'submit': 'Save'
}
response = self.client.post(url, withdraw_data)
self.assertRedirects(response, email_url + '?' + urlencode(withdraw_data))
response = self.client.post(confirm_url, post_data)
self.assertContains(response, '<title>Drafts - Confirm</title>')
self.assertEqual(response.context['email']['subject'], subject)
response = self.client.post(do_action_url, post_data)
self.assertRedirects(response, view_url)
draft = Document.objects.get(name=draft.name)
self.assertTrue(draft.get_state_slug('draft') == 'ietf-rm')
recv = outbox[-1]
self.assertEqual(recv['Subject'], subject)
def test_authors(self):
draft = WgDraftFactory()
person = PersonFactory()
url = urlreverse('ietf.secr.drafts.views.authors',kwargs={'id':draft.name})
login_testing_unauthorized(self, "secretary", url)
response = self.client.get(url)
self.assertEqual(response.status_code,200)
response = self.client.post(url, {'submit':'Done'})
self.assertEqual(response.status_code,302)
response = self.client.post(url, {'person':'%s - (%s)'%(person.plain_name(),person.pk),'email':person.email_set.first().pk})
self.assertEqual(response.status_code,302)
self.assertTrue(draft.documentauthor_set.filter(person=person).exists)
def test_dates(self):
MeetingFactory(type_id='ietf',date=datetime.datetime.today()+datetime.timedelta(days=14))
url = urlreverse('ietf.secr.drafts.views.dates')
login_testing_unauthorized(self, "secretary", url)
response = self.client.get(url)
self.assertEqual(response.status_code,200)
def test_nudge_report(self):
url = urlreverse('ietf.secr.drafts.views.nudge_report')
login_testing_unauthorized(self, "secretary", url)
response = self.client.get(url)
self.assertEqual(response.status_code,200)