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 e89f200abc0d9af7609e4bff3592f87eddee1359
This commit is contained in:
Henrik Levkowetz 2019-08-01 15:09:51 +00:00
parent b873af1eac
commit 2b1dd0f3e8
4 changed files with 24 additions and 15 deletions

View file

@ -9,6 +9,8 @@ from pyquery import PyQuery
from django.urls import reverse as urlreverse
from django.contrib.auth.models import User
from django_webtest import WebTest
import debug # pyflakes:ignore
from ietf.community.models import CommunityList, SearchRule, EmailSubscription
@ -20,13 +22,13 @@ from ietf.group.utils import setup_default_community_list_for_group
from ietf.doc.models import State
from ietf.doc.utils import add_state_change_event
from ietf.person.models import Person, Email
from ietf.utils.test_utils import login_testing_unauthorized, TestCase
from ietf.utils.test_utils import login_testing_unauthorized
from ietf.utils.mail import outbox
from ietf.doc.factories import WgDraftFactory
from ietf.group.factories import GroupFactory, RoleFactory
from ietf.person.factories import PersonFactory
class CommunityListTests(TestCase):
class CommunityListTests(WebTest):
def test_rule_matching(self):
plain = PersonFactory(user__username='plain')
ad = Person.objects.get(user__username='ad')
@ -108,25 +110,29 @@ class CommunityListTests(TestCase):
url = urlreverse(ietf.community.views.manage_list, kwargs={ "username": "plain" })
login_testing_unauthorized(self, "plain", url)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
page = self.app.get(url, user='plain')
self.assertEqual(page.status_int, 200)
# add document
r = self.client.post(url, { "action": "add_documents", "documents": draft.pk })
self.assertEqual(r.status_code, 302)
self.assertIn('add_document', page.forms)
form = page.forms['add_document']
form['documents']=draft.pk
page = form.submit('action',value='add_documents')
self.assertEqual(page.status_int, 302)
clist = CommunityList.objects.get(user__username="plain")
self.assertTrue(clist.added_docs.filter(pk=draft.pk))
self.assertTrue(clist.added_docs.filter(pk=draft.pk))
page = page.follow()
# document shows up on GET
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertContains(r, draft.name)
self.assertContains(page, draft.name)
# remove document
r = self.client.post(url, { "action": "remove_document", "document": draft.pk })
self.assertEqual(r.status_code, 302)
self.assertIn('remove_document_%s' % draft.pk, page.forms)
form = page.forms['remove_document_%s' % draft.pk]
page = form.submit('action',value='remove_document')
self.assertEqual(page.status_int, 302)
clist = CommunityList.objects.get(user__username="plain")
self.assertTrue(not clist.added_docs.filter(pk=draft.pk))
page = page.follow()
# add rule
r = self.client.post(url, {

View file

@ -33,7 +33,7 @@
<tr>
<td>{{ d.name }}</td>
<td>
<form method="post">
<form method="post" id="remove_document_{{d.pk}}">
{% csrf_token %}
<input type="hidden" name="document" value="{{ d.pk }}">
<button class="btn btn-danger btn-xs" name="action" value="remove_document">Remove</button>
@ -55,7 +55,7 @@
<p>You can also add documents here:</p>
{% endif %}
<form class="form add-document" method="post">
<form class="form add-document" method="post" id="add_document">
{% csrf_token %}
{% bootstrap_field add_doc_form.documents show_label=False %}
<button class="btn btn-primary" name="action" value="add_documents">Add documents</button>

View file

@ -21,6 +21,7 @@ django-password-strength>=1.2.1
django-referrer-policy>=1.0
django-simple-history>=2.3.0
django-tastypie>=0.13.2
django-webtest>=1.9.7
django-widget-tweaks>=1.3
docutils>=0.12,!=0.15
factory-boy>=2.9.0
@ -32,6 +33,7 @@ httplib2>=0.10.3
jsonfield>=1.0.3 # for SubmissionCheck. This is https://github.com/bradjasper/django-jsonfield/.
jwcrypto>=0.4.0 # for signed notifications
#lxml>=3.4.0 # from PyQuery;
markdown2>=2.3.8
mock>=2.0.0
mysqlclient>=1.3.13
oauth2client>=4.0.0 # required by google-api-python-client, but not always pulled in

View file

@ -21,6 +21,7 @@ django-password-strength>=1.2.1
django-referrer-policy>=1.0
django-simple-history>=2.3.0
django-tastypie>=0.13.2
django-webtest>=1.9.7
django-widget-tweaks>=1.3
docutils>=0.12,!=0.15
factory-boy>=2.9.0