-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_cli.py
131 lines (91 loc) · 2.12 KB
/
test_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from bddcli import Given, when, stdout, status, stderr, Application
from bddrest.tests.helpers import standard_files_mockup
app = Application('bddrest', 'bddrest.cli:main')
def test_document_cli():
with Given(app, ['document']):
when(stdin=yamlstory)
assert stderr == ''
assert status == 0
assert stdout == expected_markdown
def test_help():
with Given(app):
assert stdout == expected_help
yamlstory = '''
base_call:
as_: visitor
description: As a member I have to POST a book to the library.
form:
name: BDD Book
query:
a: b
response:
headers:
- 'Content-Type: application/json;charset=utf-8'
json:
foo: bar
status: 200 OK
title: Posting a book
url: /books/:id
url_parameters:
id: '1'
verb: GET
calls:
- response:
headers:
- 'Content-Type: text/plain;charset=utf-8'
status: 404 Not Found
title: Trying invalid book id
url_parameters:
id: None
'''
expected_markdown = '''\
## Posting a book
### GET /books/:id
As a member I have to POST a book to the library.
### Url Parameters
Name | Example
--- | ---
id | 1
### Query Strings
Name | Example
--- | ---
a | b
### Form
Name | Required | Nullable | Type | Example
--- | --- | --- | --- | ---
name | ? | ? | ? | BDD Book
### CURL
```bash
curl -F "name=BDD Book" -- "$URL/books/1?a=b"
```
### Response: 200 OK
#### Body
Content-Type: application/json
```json
{"foo": "bar"}
```
---
## WHEN: Trying invalid book id
### GET /books/:id
### Url Parameters
Name | Example
--- | ---
id | None
### CURL
```bash
curl -F "name=BDD Book" -- "$URL/books/None?a=b"
```
### Response: 404 Not Found
'''
expected_help = '''\
usage: bddrest [-h] {document,mockupserver,completion} ...
bddrest
optional arguments:
-h, --help show this help message and exit
Sub commands:
{document,mockupserver,completion}
document Generates REST API Documentation from standard input
to standard output.
mockupserver Generates a mockup from YAML file.
completion Bash auto completion using argcomplete python package.
'''