polyapi-python 0.2.5.dev3__tar.gz → 0.2.5.dev5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {polyapi_python-0.2.5.dev3/polyapi_python.egg-info → polyapi_python-0.2.5.dev5}/PKG-INFO +1 -1
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/cli.py +11 -5
- polyapi_python-0.2.5.dev5/polyapi/rendered_spec.py +63 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5/polyapi_python.egg-info}/PKG-INFO +1 -1
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi_python.egg-info/SOURCES.txt +2 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/pyproject.toml +1 -1
- polyapi_python-0.2.5.dev5/tests/test_rendered_spec.py +52 -0
- polyapi_python-0.2.5.dev5/tests/test_schema.py +14 -0
- polyapi_python-0.2.5.dev3/polyapi/rendered_spec.py +0 -34
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/LICENSE +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/README.md +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/__init__.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/__main__.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/api.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/auth.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/client.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/config.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/constants.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/error_handler.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/exceptions.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/execute.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/function_cli.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/generate.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/py.typed +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/schema.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/server.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/typedefs.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/utils.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/variables.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi/webhook.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi_python.egg-info/dependency_links.txt +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi_python.egg-info/requires.txt +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi_python.egg-info/top_level.txt +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/setup.cfg +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/tests/test_api.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/tests/test_auth.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/tests/test_function_cli.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/tests/test_server.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/tests/test_utils.py +0 -0
- {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/tests/test_variables.py +0 -0
|
@@ -5,10 +5,10 @@ from polyapi.utils import print_green
|
|
|
5
5
|
from .config import clear_config, set_api_key_and_url
|
|
6
6
|
from .generate import generate, clear
|
|
7
7
|
from .function_cli import function_add_or_update
|
|
8
|
-
from .rendered_spec import
|
|
8
|
+
from .rendered_spec import get_and_update_rendered_spec
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
CLI_COMMANDS = ["setup", "generate", "function", "clear", "help", "
|
|
11
|
+
CLI_COMMANDS = ["setup", "generate", "function", "clear", "help", "update_rendered_spec"]
|
|
12
12
|
|
|
13
13
|
CLIENT_DESC = """Commands
|
|
14
14
|
python -m polyapi setup Setup your Poly connection
|
|
@@ -18,7 +18,7 @@ CLIENT_DESC = """Commands
|
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def execute_from_cli():
|
|
21
|
+
def execute_from_cli() -> None:
|
|
22
22
|
parser = argparse.ArgumentParser(
|
|
23
23
|
prog="python -m polyapi", description=CLIENT_DESC, formatter_class=argparse.RawTextHelpFormatter
|
|
24
24
|
)
|
|
@@ -43,8 +43,14 @@ def execute_from_cli():
|
|
|
43
43
|
elif command == "setup":
|
|
44
44
|
clear_config()
|
|
45
45
|
generate()
|
|
46
|
-
elif command == "
|
|
47
|
-
|
|
46
|
+
elif command == "update_rendered_spec":
|
|
47
|
+
assert len(args.subcommands) == 2
|
|
48
|
+
updated = get_and_update_rendered_spec(args.subcommands[0], args.subcommands[1])
|
|
49
|
+
if updated:
|
|
50
|
+
print("Updated rendered spec!")
|
|
51
|
+
else:
|
|
52
|
+
print("Failed to update rendered spec!")
|
|
53
|
+
exit(1)
|
|
48
54
|
elif command == "clear":
|
|
49
55
|
print("Clearing the generated library...")
|
|
50
56
|
clear()
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from typing import Dict, Optional
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
from polyapi.config import get_api_key_and_url
|
|
5
|
+
from polyapi.generate import read_cached_specs, render_spec
|
|
6
|
+
from polyapi.typedefs import SpecificationDto
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def update_rendered_spec(api_key: str, spec: SpecificationDto):
|
|
10
|
+
print("Updating rendered spec...")
|
|
11
|
+
func_str, type_defs = render_spec(spec)
|
|
12
|
+
data = {
|
|
13
|
+
"language": "python",
|
|
14
|
+
"signature": func_str,
|
|
15
|
+
"typedefs": type_defs,
|
|
16
|
+
}
|
|
17
|
+
if spec["type"] == "apiFunction":
|
|
18
|
+
data["apiFunctionId"] = spec["id"]
|
|
19
|
+
elif spec["type"] == "serverFunction":
|
|
20
|
+
data["customFunctionId"] = spec["id"]
|
|
21
|
+
else:
|
|
22
|
+
raise NotImplementedError("todo")
|
|
23
|
+
|
|
24
|
+
# use super key on develop-k8s here!
|
|
25
|
+
_, base_url = get_api_key_and_url()
|
|
26
|
+
url = f"{base_url}/functions/rendered-specs"
|
|
27
|
+
headers = {"Authorization": f"Bearer {api_key}"}
|
|
28
|
+
resp = requests.post(url, json=data, headers=headers)
|
|
29
|
+
assert resp.status_code == 201, (resp.text, resp.status_code)
|
|
30
|
+
# this needs to run with something like `kn func run...`
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _get_spec(api_key: str, spec_id: str) -> Optional[SpecificationDto]:
|
|
34
|
+
_, base_url = get_api_key_and_url()
|
|
35
|
+
url = f"{base_url}/specs"
|
|
36
|
+
headers = {"Authorization": f"Bearer {api_key}"}
|
|
37
|
+
resp = requests.get(url, headers=headers)
|
|
38
|
+
if resp.status_code == 200:
|
|
39
|
+
specs = resp.json()
|
|
40
|
+
for spec in specs:
|
|
41
|
+
if spec['id'] == spec_id:
|
|
42
|
+
return spec
|
|
43
|
+
return None
|
|
44
|
+
else:
|
|
45
|
+
raise NotImplementedError(resp.content)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def get_and_update_rendered_spec(api_key: str, spec_id: str) -> bool:
|
|
49
|
+
spec = _get_spec(api_key, spec_id)
|
|
50
|
+
if spec:
|
|
51
|
+
update_rendered_spec(api_key, spec)
|
|
52
|
+
return True
|
|
53
|
+
return False
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def save_rendered_specs() -> None:
|
|
57
|
+
specs = read_cached_specs()
|
|
58
|
+
# right now we just support rendered apiFunctions
|
|
59
|
+
api_specs = [spec for spec in specs if spec["type"] == "apiFunction"]
|
|
60
|
+
for spec in api_specs:
|
|
61
|
+
assert spec["function"]
|
|
62
|
+
print("adding", spec["context"], spec["name"])
|
|
63
|
+
update_rendered_spec("FIXME", spec)
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
|
|
|
3
3
|
|
|
4
4
|
[project]
|
|
5
5
|
name = "polyapi-python"
|
|
6
|
-
version = "0.2.5.
|
|
6
|
+
version = "0.2.5.dev5"
|
|
7
7
|
description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
|
|
8
8
|
authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
|
|
9
9
|
dependencies = [
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from mock import patch, Mock
|
|
3
|
+
|
|
4
|
+
from polyapi.rendered_spec import get_and_update_rendered_spec
|
|
5
|
+
|
|
6
|
+
GET_PRODUCTS_COUNT = {
|
|
7
|
+
"id": "8f7d24b0-4a29-40c0-9091",
|
|
8
|
+
"type": "serverFunction",
|
|
9
|
+
"context": "test",
|
|
10
|
+
"name": "getProductsCount111",
|
|
11
|
+
"description": "An API call to retrieve the count of products in the product list.",
|
|
12
|
+
"requirements": ["snabbdom"],
|
|
13
|
+
"function": {
|
|
14
|
+
"arguments": [
|
|
15
|
+
{
|
|
16
|
+
"name": "products",
|
|
17
|
+
"required": False,
|
|
18
|
+
"type": {
|
|
19
|
+
"kind": "array",
|
|
20
|
+
"items": {"kind": "primitive", "type": "string"},
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"returnType": {"kind": "plain", "value": "number"},
|
|
25
|
+
"synchronous": True,
|
|
26
|
+
},
|
|
27
|
+
"code": "",
|
|
28
|
+
"language": "javascript",
|
|
29
|
+
"visibilityMetadata": {"visibility": "ENVIRONMENT"},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class T(unittest.TestCase):
|
|
34
|
+
@patch("polyapi.rendered_spec._get_spec")
|
|
35
|
+
def test_get_and_update_rendered_spec_fail(self, _get_spec):
|
|
36
|
+
""" pass in a bad id to update and make sure it returns False
|
|
37
|
+
"""
|
|
38
|
+
_get_spec.return_value = None
|
|
39
|
+
updated = get_and_update_rendered_spec("abc", "123")
|
|
40
|
+
self.assertEqual(_get_spec.call_count, 1)
|
|
41
|
+
self.assertFalse(updated)
|
|
42
|
+
|
|
43
|
+
@patch("polyapi.rendered_spec.requests.post")
|
|
44
|
+
@patch("polyapi.rendered_spec._get_spec")
|
|
45
|
+
def test_get_and_update_rendered_spec_success(self, _get_spec, post):
|
|
46
|
+
""" pass in a bad id to update and make sure it returns False
|
|
47
|
+
"""
|
|
48
|
+
_get_spec.return_value = GET_PRODUCTS_COUNT
|
|
49
|
+
post.return_value = Mock(status_code=201, text="Created")
|
|
50
|
+
updated = get_and_update_rendered_spec("abc", "123")
|
|
51
|
+
self.assertEqual(_get_spec.call_count, 1)
|
|
52
|
+
self.assertTrue(updated)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from polyapi.schema import generate_schema_types
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class T(unittest.TestCase):
|
|
6
|
+
def test_fix_titles(self):
|
|
7
|
+
# schema = json.loads(SCHEMA)
|
|
8
|
+
schema = {"$schema": "http://json-schema.org/draft-06/schema#"}
|
|
9
|
+
try:
|
|
10
|
+
a, b = generate_schema_types(schema)
|
|
11
|
+
except AssertionError:
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
# should not throw with unknown dialect error
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
from typing import Dict
|
|
2
|
-
from polyapi.generate import read_cached_specs, render_spec
|
|
3
|
-
from polyapi.execute import execute_post
|
|
4
|
-
from polyapi.typedefs import SpecificationDto
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def update_rendered_spec(spec: SpecificationDto):
|
|
8
|
-
print("Updating rendered spec...")
|
|
9
|
-
func_str, type_defs = render_spec(spec)
|
|
10
|
-
data = {
|
|
11
|
-
"language": "python",
|
|
12
|
-
"signature": func_str,
|
|
13
|
-
"typedefs": type_defs,
|
|
14
|
-
}
|
|
15
|
-
if spec["type"] == "apiFunction":
|
|
16
|
-
data["apiFunctionId"] = spec["id"]
|
|
17
|
-
elif spec["type"] == "serverFunction":
|
|
18
|
-
data["customFunctionId"] = spec["id"]
|
|
19
|
-
else:
|
|
20
|
-
raise NotImplementedError("todo")
|
|
21
|
-
|
|
22
|
-
resp = execute_post("/functions/rendered-specs", data)
|
|
23
|
-
assert resp.status_code == 201, (resp.text, resp.status_code)
|
|
24
|
-
# this needs to run with something like `kn func run...`
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def save_rendered_specs() -> None:
|
|
28
|
-
specs = read_cached_specs()
|
|
29
|
-
# right now we just support rendered apiFunctions
|
|
30
|
-
api_specs = [spec for spec in specs if spec["type"] == "apiFunction"]
|
|
31
|
-
for spec in api_specs:
|
|
32
|
-
assert spec["function"]
|
|
33
|
-
print("adding", spec["context"], spec["name"])
|
|
34
|
-
update_rendered_spec(spec)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi_python.egg-info/requires.txt
RENAMED
|
File without changes
|
{polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev5}/polyapi_python.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|