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