Skip to content

Commit 2b1dd0f

Browse files
committed
Merged in [16590] from rjsparks@nostrum.com:
Example of using webtest. The full testcase was not converted because the add_rule form is modified in-flight by javascript when a control value is changed. - Legacy-Id: 16609 Note: SVN reference [16590] has been migrated to Git commit e89f200
1 parent b873af1 commit 2b1dd0f

4 files changed

Lines changed: 24 additions & 15 deletions

File tree

ietf/community/tests.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from django.urls import reverse as urlreverse
1010
from django.contrib.auth.models import User
1111

12+
from django_webtest import WebTest
13+
1214
import debug # pyflakes:ignore
1315

1416
from ietf.community.models import CommunityList, SearchRule, EmailSubscription
@@ -20,13 +22,13 @@
2022
from ietf.doc.models import State
2123
from ietf.doc.utils import add_state_change_event
2224
from ietf.person.models import Person, Email
23-
from ietf.utils.test_utils import login_testing_unauthorized, TestCase
25+
from ietf.utils.test_utils import login_testing_unauthorized
2426
from ietf.utils.mail import outbox
2527
from ietf.doc.factories import WgDraftFactory
2628
from ietf.group.factories import GroupFactory, RoleFactory
2729
from ietf.person.factories import PersonFactory
2830

29-
class CommunityListTests(TestCase):
31+
class CommunityListTests(WebTest):
3032
def test_rule_matching(self):
3133
plain = PersonFactory(user__username='plain')
3234
ad = Person.objects.get(user__username='ad')
@@ -108,25 +110,29 @@ def test_manage_personal_list(self):
108110
url = urlreverse(ietf.community.views.manage_list, kwargs={ "username": "plain" })
109111
login_testing_unauthorized(self, "plain", url)
110112

111-
r = self.client.get(url)
112-
self.assertEqual(r.status_code, 200)
113+
page = self.app.get(url, user='plain')
114+
self.assertEqual(page.status_int, 200)
113115

114116
# add document
115-
r = self.client.post(url, { "action": "add_documents", "documents": draft.pk })
116-
self.assertEqual(r.status_code, 302)
117+
self.assertIn('add_document', page.forms)
118+
form = page.forms['add_document']
119+
form['documents']=draft.pk
120+
page = form.submit('action',value='add_documents')
121+
self.assertEqual(page.status_int, 302)
117122
clist = CommunityList.objects.get(user__username="plain")
118-
self.assertTrue(clist.added_docs.filter(pk=draft.pk))
123+
self.assertTrue(clist.added_docs.filter(pk=draft.pk))
124+
page = page.follow()
119125

120-
# document shows up on GET
121-
r = self.client.get(url)
122-
self.assertEqual(r.status_code, 200)
123-
self.assertContains(r, draft.name)
126+
self.assertContains(page, draft.name)
124127

125128
# remove document
126-
r = self.client.post(url, { "action": "remove_document", "document": draft.pk })
127-
self.assertEqual(r.status_code, 302)
129+
self.assertIn('remove_document_%s' % draft.pk, page.forms)
130+
form = page.forms['remove_document_%s' % draft.pk]
131+
page = form.submit('action',value='remove_document')
132+
self.assertEqual(page.status_int, 302)
128133
clist = CommunityList.objects.get(user__username="plain")
129134
self.assertTrue(not clist.added_docs.filter(pk=draft.pk))
135+
page = page.follow()
130136

131137
# add rule
132138
r = self.client.post(url, {

ietf/templates/community/manage_list.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h2>Individual documents</h2>
3333
<tr>
3434
<td>{{ d.name }}</td>
3535
<td>
36-
<form method="post">
36+
<form method="post" id="remove_document_{{d.pk}}">
3737
{% csrf_token %}
3838
<input type="hidden" name="document" value="{{ d.pk }}">
3939
<button class="btn btn-danger btn-xs" name="action" value="remove_document">Remove</button>
@@ -55,7 +55,7 @@ <h2>Individual documents</h2>
5555
<p>You can also add documents here:</p>
5656
{% endif %}
5757

58-
<form class="form add-document" method="post">
58+
<form class="form add-document" method="post" id="add_document">
5959
{% csrf_token %}
6060
{% bootstrap_field add_doc_form.documents show_label=False %}
6161
<button class="btn btn-primary" name="action" value="add_documents">Add documents</button>

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ django-password-strength>=1.2.1
2121
django-referrer-policy>=1.0
2222
django-simple-history>=2.3.0
2323
django-tastypie>=0.13.2
24+
django-webtest>=1.9.7
2425
django-widget-tweaks>=1.3
2526
docutils>=0.12,!=0.15
2627
factory-boy>=2.9.0
@@ -32,6 +33,7 @@ httplib2>=0.10.3
3233
jsonfield>=1.0.3 # for SubmissionCheck. This is https://github.com/bradjasper/django-jsonfield/.
3334
jwcrypto>=0.4.0 # for signed notifications
3435
#lxml>=3.4.0 # from PyQuery;
36+
markdown2>=2.3.8
3537
mock>=2.0.0
3638
mysqlclient>=1.3.13
3739
oauth2client>=4.0.0 # required by google-api-python-client, but not always pulled in

requirements3.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ django-password-strength>=1.2.1
2121
django-referrer-policy>=1.0
2222
django-simple-history>=2.3.0
2323
django-tastypie>=0.13.2
24+
django-webtest>=1.9.7
2425
django-widget-tweaks>=1.3
2526
docutils>=0.12,!=0.15
2627
factory-boy>=2.9.0

0 commit comments

Comments
 (0)