Debian Codegraph @

hitch/story/email-url.story

raw
1 Email and URL validators:
2 based on: strictyaml
3 docs: scalar/email-and-url
4 description: |
5 StrictYAML can validate emails (using a simplified regex) and
6 URLs.
7 given:
8 setup: |
9 from strictyaml import Email, Url, Map, load
10 from ensure import Ensure
11
12 schema = Map({"a": Email(), "b": Url()})
13 variations:
14 Parsed:
15 given:
16 yaml_snippet: |
17 a: [email protected]
18 b: https://user:[email protected]:443/path?k=v#frag
19 steps:
20 - Run: |
21 Ensure(load(yaml_snippet, schema)).equals({"a": "[email protected]", "b": "https://user:[email protected]:443/path?k=v#frag"})
22
23 Exception:
24 given:
25 yaml_snippet: |
26 a: notanemail
27 b: notaurl
28 steps:
29 - Run:
30 code: load(yaml_snippet, schema)
31 raises:
32 type: strictyaml.exceptions.YAMLValidationError
33 message: |-
34 when expecting an email address
35 found non-matching string
36 in "<unicode string>", line 1, column 1:
37 a: notanemail
38 ^ (line: 1)