view tests/suite_12_methods/__init__.py @ 72:e8b3b336e63e draft default tip

Update version.
author David Barts <n5jrn@me.com>
date Mon, 15 Jul 2019 13:17:48 -0700
parents 88adf10be709
children
line wrap: on
line source

# I m p o r t s

import os, sys
import requests
import urllib.parse
from bs4 import BeautifulSoup
from .. import ServerFixture, RoutesFixture

# C l a s s e s

class Fixture01(RoutesFixture):
    def _doform(self, page):
        url = "http://localhost:{0}/{1}".format(self.port, page)
        response = requests.get(url)
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.text, 'html.parser')
        self.assertIsNotNone(soup.find(
            "input", attrs={"type": "text", "name": "name"}))
        self.assertIsNotNone(soup.find(
            "input", attrs={"type": "submit", "value": "Submit"}))
        form = soup.find("form")
        self.assertIsNotNone(form)
        action_url = urllib.parse.urljoin(url, form.get("action", page))
        response = requests.post(url, {"name": "Barney Dinosaur"})
        self.assertEqual(response.status_code, 200)
        self.assertTrue("Hello, Barney" in response.text)
        self.assertTrue("Pleased to meet you!" in response.text)

    # Methods with their standard, uppercase names
    def test_01_methods(self):
        self._doform("name.pspx")

    # Methods with alternate capitalizations. This also tests #python
    def test_02_methods_lc(self):
        self._doform("name_lc.pspx")