forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
118 lines (101 loc) · 4.34 KB
/
Copy pathtests.py
File metadata and controls
118 lines (101 loc) · 4.34 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
# Copyright The IETF Trust 2013-2020, All Rights Reserved
# -*- coding: utf-8 -*-
from pyquery import PyQuery
from django.urls import reverse
import debug # pyflakes:ignore
from ietf.utils.test_utils import TestCase
from ietf.group.factories import RoleFactory
from ietf.group.models import Group
from ietf.message.models import Message
from ietf.name.models import RoleName
from ietf.nomcom.test_data import nomcom_test_data
from ietf.message.models import AnnouncementFrom
from ietf.utils.mail import outbox, empty_outbox
SECR_USER = "secretary"
WG_USER = ""
AD_USER = ""
class SecrAnnouncementTestCase(TestCase):
def setUp(self):
super().setUp()
chair = RoleName.objects.get(slug="chair")
secr = RoleName.objects.get(slug="secr")
ietf = Group.objects.get(acronym="ietf")
iab = Group.objects.get(acronym="iab")
secretariat = Group.objects.get(acronym="secretariat")
AnnouncementFrom.objects.create(
name=secr,
group=secretariat,
address="IETF Secretariat <ietf-secretariat@ietf.org>",
)
AnnouncementFrom.objects.create(
name=chair, group=ietf, address="IETF Chair <chair@ietf.org>"
)
AnnouncementFrom.objects.create(
name=chair, group=iab, address="IAB Chair <iab-chair@iab.org>"
)
def test_main(self):
"Main Test"
url = reverse("ietf.secr.announcement.views.main")
self.client.login(username="secretary", password="secretary+password")
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
def test_main_announce_from(self):
url = reverse("ietf.secr.announcement.views.main")
# Secretariat
self.client.login(username="secretary", password="secretary+password")
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
q = PyQuery(r.content)
self.assertEqual(len(q("#id_frm option")), 4)
# IAB Chair
self.client.login(username="iab-chair", password="iab-chair+password")
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
q = PyQuery(r.content)
self.assertEqual(len(q("#id_frm option")), 1)
self.assertTrue("<iab-chair@iab.org>" in q("#id_frm option").val())
# IETF Chair
self.client.login(username="ietf-chair", password="ietf-chair+password")
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
q = PyQuery(r.content)
self.assertEqual(len(q("#id_frm option")), 1)
self.assertTrue("<chair@ietf.org>" in q("#id_frm option").val())
class UnauthorizedAnnouncementCase(TestCase):
def test_unauthorized(self):
"Unauthorized Test"
url = reverse("ietf.secr.announcement.views.main")
person = RoleFactory(name_id="chair", group__acronym="mars").person
self.client.login(
username=person.user.username, password=person.user.username + "+password"
)
r = self.client.get(url)
self.assertEqual(r.status_code, 403)
class SubmitAnnouncementCase(TestCase):
def test_valid_submit(self):
"Valid Submit"
nomcom_test_data()
empty_outbox()
url = reverse("ietf.secr.announcement.views.main")
confirm_url = reverse("ietf.secr.announcement.views.confirm")
nomcom = Group.objects.get(type="nomcom")
post_data = {
"nomcom": nomcom.pk,
"to": "Other...",
"to_custom": "phil@example.com",
"frm": "IETF Secretariat <ietf-secretariat@ietf.org>",
"reply_to": "secretariat@ietf.org",
"subject": "Test Subject",
"body": "This is a test.",
}
self.client.login(username="secretary", password="secretary+password")
response = self.client.post(url, post_data)
self.assertContains(response, "Confirm Announcement")
response = self.client.post(confirm_url, post_data, follow=True)
self.assertRedirects(response, url)
self.assertEqual(len(outbox), 1)
self.assertEqual(outbox[0]["subject"], "Test Subject")
self.assertEqual(outbox[0]["to"], "<phil@example.com>")
message = Message.objects.filter(by__user__username="secretary").last()
self.assertEqual(message.subject, "Test Subject")
self.assertTrue(nomcom in message.related_groups.all())