annotate tests/suite_12_methods/__init__.py @ 71:88adf10be709 draft

Add tests.
author David Barts <n5jrn@me.com>
date Mon, 15 Jul 2019 13:16:31 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
71
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 # I m p o r t s
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
2
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 import os, sys
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 import requests
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
5 import urllib.parse
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 from bs4 import BeautifulSoup
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 from .. import ServerFixture, RoutesFixture
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
8
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 # C l a s s e s
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
10
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 class Fixture01(RoutesFixture):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 def _doform(self, page):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 url = "http://localhost:{0}/{1}".format(self.port, page)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 response = requests.get(url)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 self.assertEqual(response.status_code, 200)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 soup = BeautifulSoup(response.text, 'html.parser')
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 self.assertIsNotNone(soup.find(
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 "input", attrs={"type": "text", "name": "name"}))
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 self.assertIsNotNone(soup.find(
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 "input", attrs={"type": "submit", "value": "Submit"}))
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 form = soup.find("form")
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 self.assertIsNotNone(form)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 action_url = urllib.parse.urljoin(url, form.get("action", page))
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 response = requests.post(url, {"name": "Barney Dinosaur"})
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
25 self.assertEqual(response.status_code, 200)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 self.assertTrue("Hello, Barney" in response.text)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
27 self.assertTrue("Pleased to meet you!" in response.text)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
28
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 # Methods with their standard, uppercase names
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 def test_01_methods(self):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 self._doform("name.pspx")
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
32
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 # Methods with alternate capitalizations. This also tests #python
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
34 def test_02_methods_lc(self):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 self._doform("name_lc.pspx")