Skip to content

Commit

Permalink
Merge pull request #75 from stevepiercy/issue_103
Browse files Browse the repository at this point in the history
Adding test case for deform #103
  • Loading branch information
stevepiercy authored Aug 17, 2020
2 parents 3e863a4 + 979e751 commit df5d13c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
10 changes: 5 additions & 5 deletions deformdemo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def render_form(

reqts = form.get_widget_resources()

printer = pprint.PrettyPrinter(width=1)
printer = pprint.PrettyPrinter()
printer.format = my_safe_repr
output = printer.pformat(captured)
captured = highlight(output, PythonLexer(), formatter)
Expand Down Expand Up @@ -291,8 +291,7 @@ class Schema(colander.Schema):
@view_config(renderer="templates/form.pt", name="autocomplete_input")
@demonstrate("Autocomplete Input Widget")
def autocomplete_input(self):

choices = ["bar", "baz", "two", "three"]
choices = ["bar", "baz", "two", "three", "foo & bar", "one < two"]
widget = deform.widget.AutocompleteInputWidget(
values=choices, min_length=1
)
Expand Down Expand Up @@ -340,7 +339,9 @@ class Schema(colander.Schema):
def autocomplete_input_values(self):
text = self.request.params.get("term", "")
return [
x for x in ["bar", "baz", "two", "three"] if x.startswith(text)
x
for x in ["bar", "baz", "two", "three", "foo & bar", "one < two"]
if x.startswith(text)
]

@view_config(renderer="templates/form.pt", name="textarea")
Expand Down Expand Up @@ -2387,7 +2388,6 @@ def multiple_forms(self):
# forms do not overlap so accessibility features continue to work,
# such as focusing the field related to a legend when the
# legend is clicked on.

# We do so by creating an ``itertools.count`` object and
# passing that object as the ``counter`` keyword argument to
# the constructor of both forms. As a result, the second
Expand Down
48 changes: 37 additions & 11 deletions deformdemo/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import print_function

import ast
import datetime
from decimal import Decimal
import logging
Expand Down Expand Up @@ -100,6 +101,10 @@ def action_chains_xpath_on_select(option_xpath):
)


def action_chains_on_css_selector(css_selector):
return ActionChains(browser).move_to_element(findcss(css_selector))


@give_selenium_some_time
def findid(elid, clickable=True):
"""Find Selenium element by CSS id.
Expand Down Expand Up @@ -350,9 +355,9 @@ def test_submit_three_checked(self):
self.assertTrue(findid("deformField1-1").is_selected())
self.assertTrue(findid("deformField1-2").is_selected())
captured = findid("captured").text
self.assertSimilarRepr(
captured, "{'pepper': {'chipotle', 'habanero', 'jalapeno'}}"
)
expected = {'pepper': {'jalapeno', 'habanero', 'chipotle'}}
captured = ast.literal_eval(captured)
self.assertEqual(expected, captured)


class CheckboxChoiceWidgetInlineTests(Base, unittest.TestCase):
Expand Down Expand Up @@ -396,9 +401,9 @@ def test_submit_three_checked(self):
self.assertTrue(findid("deformField1-1").is_selected())
self.assertTrue(findid("deformField1-2").is_selected())
captured = findid("captured").text
self.assertSimilarRepr(
captured, "{'pepper': {'chipotle', 'habanero', 'jalapeno'}}"
)
expected = {'pepper': {'jalapeno', 'habanero', 'chipotle'}}
captured = ast.literal_eval(captured)
self.assertEqual(expected, captured)


class CheckboxChoiceReadonlyTests(Base, unittest.TestCase):
Expand Down Expand Up @@ -2586,9 +2591,9 @@ def test_submit_new_options(self):
# after form submission typed value appear in captured
findid("deformsubmit").click()
captured = findid("captured").text
self.assertSimilarRepr(
captured, "{'pepper': {'hello', 'qwerty'} }",
)
captured = ast.literal_eval(captured)
expected = {'pepper': {'hello', 'qwerty'}}
self.assertEqual(expected, captured)


class SelectWithDefaultTests(Base, unittest.TestCase):
Expand Down Expand Up @@ -2736,6 +2741,27 @@ def test_submit_filled(self):
# py2/py3 compat, py2 adds extra u prefix
self.assertTrue("bar" in text)

def test_ampersand(self):
findid("deformField1").send_keys("foo")
self.assertTrue(findxpath('//p[text()="foo & bar"]').is_displayed())
action_chains_on_css_selector(".tt-suggestion").click().perform()
findid("deformsubmit").click()
self.assertRaises(NoSuchElementException, findcss, ".has-error")
text = findid("captured").text
# py2/py3 compat, py2 adds extra u prefix
self.assertTrue("foo & bar" in text)

def test_less_than(self):
findid("deformField1").send_keys("one")
self.assertTrue(findxpath('//p[text()="one < two"]').is_displayed())
findid("deformField1").send_keys(Keys.ARROW_DOWN)
findid("deformField1").send_keys(Keys.ENTER)
findid("deformsubmit").click()
self.assertRaises(NoSuchElementException, findcss, ".has-error")
text = findid("captured").text
# py2/py3 compat, py2 adds extra u prefix
self.assertTrue("one < two" in text)


class AutocompleteRemoteInputWidgetTests(Base, unittest.TestCase):
url = test_url("/autocomplete_remote_input/")
Expand Down Expand Up @@ -2769,8 +2795,8 @@ def test_submit_filled(self):
self.assertTrue(findxpath('//p[text()="two"]').is_displayed())
self.assertTrue(findxpath('//p[text()="three"]').is_displayed())

action_chains_on_xpath('//p[text()="two"]').click().perform()

findid("deformField1").send_keys(Keys.ARROW_DOWN)
findid("deformField1").send_keys(Keys.ENTER)
findid("deformsubmit").click()
self.assertRaises(NoSuchElementException, findcss, ".has-error")

Expand Down

0 comments on commit df5d13c

Please sign in to comment.