comparison tests/suite_12_methods/files/name.py @ 71:88adf10be709 draft

Add tests.
author David Barts <n5jrn@me.com>
date Mon, 15 Jul 2019 13:16:31 -0700
parents
children
comparison
equal deleted inserted replaced
70:a78c74c73d98 71:88adf10be709
1 # It is *technically* an HTTP violation to use POST for an idempotent
2 # page like this, but it is a good simple test.
3
4 from tincan import Page
5 from jsdict import JSDict
6
7 class Name(Page):
8 def handle(self):
9 self._error_message = JSDict({"subject": "Error", "style": "color: red;"})
10 if "name" not in self.request.forms:
11 if self.request.method == "GET":
12 self.message = None
13 else:
14 self.message = self.error("This should not happen!")
15 else:
16 name = self.request.forms["name"]
17 if name.strip() == "":
18 self.message = self.error("Please enter your name above.")
19 else:
20 self.message = JSDict({
21 "subject": "Hello, {0}".format(name.split()[0]),
22 "style": None,
23 "body": "Pleased to meet you!"
24 })
25
26 def error(self, message):
27 self._error_message.body = message
28 return self._error_message