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
|
from pathlib import Path
from posting.collection import Collection, Options, QueryParam, RequestModel, Scripts
from posting.importing.postman import Variable, import_postman_spec
def test_import_postman_spec():
# Write mock Postman spec to a temporary file
collection, postman_collection = import_postman_spec(
spec_path="tests/sample-importable-collections/test-postman-collection.json",
output_path="foo/bar/baz",
)
assert collection == Collection(
path=Path("foo/bar/baz"),
name="Test API",
requests=[],
children=[
Collection(
path=Path("foo/bar/baz/Users"),
name="Users",
requests=[
RequestModel(
name="Get Users",
description="",
method="GET",
url="$HOST/api/users",
path=Path("foo/bar/baz/Users/GetUsers.posting.yaml"),
body=None,
auth=None,
headers=[],
params=[
QueryParam(
name="email", value="example@gmail.com", enabled=True
),
QueryParam(
name="relations",
value="organization,impersonating_user",
enabled=True,
),
],
cookies=[],
posting_version="2.6.0",
scripts=Scripts(setup=None, on_request=None, on_response=None),
options=Options(
follow_redirects=True,
verify_ssl=True,
attach_cookies=True,
proxy_url="",
timeout=5.0,
),
)
],
children=[
Collection(
path=Path("foo/bar/baz/Users/User Details"),
name="User Details",
requests=[
RequestModel(
name="Get User",
description="",
method="GET",
url="$BASE_URL/users/{id}",
path=Path(
"foo/bar/baz/Users/User Details/GetUser.posting.yaml"
),
body=None,
auth=None,
headers=[],
params=[],
cookies=[],
posting_version="2.6.0",
scripts=Scripts(
setup=None, on_request=None, on_response=None
),
options=Options(
follow_redirects=True,
verify_ssl=True,
attach_cookies=True,
proxy_url="",
timeout=5.0,
),
)
],
children=[],
readme=None,
)
],
readme=None,
)
],
readme="# Test API\n\nA test API\n\nVersion: 2.0.0",
)
assert postman_collection.variable == [
Variable(key="baseUrl", value="https://api.example.com")
]
|