Skip to content

Commit

Permalink
Example of using webtest. The full testcase was not converted because…
Browse files Browse the repository at this point in the history
… the add_rule form is modified in-flight by javascript when a control value is changed. Commit ready for merge.

 - Legacy-Id: 16590
  • Loading branch information
rjsparks committed Jul 25, 2019
1 parent d3b70a4 commit e89f200
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
32 changes: 19 additions & 13 deletions ietf/community/tests.py
Expand Up @@ -9,6 +9,8 @@
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
Expand All @@ -20,13 +22,13 @@
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')
Expand Down Expand Up @@ -108,25 +110,29 @@ def test_manage_personal_list(self):
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, {
Expand Down
4 changes: 2 additions & 2 deletions ietf/templates/community/manage_list.html
Expand Up @@ -33,7 +33,7 @@ <h2>Individual documents</h2>
<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>
Expand All @@ -55,7 +55,7 @@ <h2>Individual documents</h2>
<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>
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -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
factory-boy>=2.9.0
Expand Down

0 comments on commit e89f200

Please sign in to comment.