polyapi-python 0.2.5.dev3__tar.gz → 0.2.5.dev4__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.
Files changed (39) hide show
  1. {polyapi_python-0.2.5.dev3/polyapi_python.egg-info → polyapi_python-0.2.5.dev4}/PKG-INFO +1 -1
  2. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/cli.py +11 -5
  3. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/rendered_spec.py +28 -1
  4. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4/polyapi_python.egg-info}/PKG-INFO +1 -1
  5. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi_python.egg-info/SOURCES.txt +2 -0
  6. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/pyproject.toml +1 -1
  7. polyapi_python-0.2.5.dev4/tests/test_rendered_spec.py +52 -0
  8. polyapi_python-0.2.5.dev4/tests/test_schema.py +14 -0
  9. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/LICENSE +0 -0
  10. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/README.md +0 -0
  11. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/__init__.py +0 -0
  12. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/__main__.py +0 -0
  13. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/api.py +0 -0
  14. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/auth.py +0 -0
  15. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/client.py +0 -0
  16. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/config.py +0 -0
  17. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/constants.py +0 -0
  18. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/error_handler.py +0 -0
  19. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/exceptions.py +0 -0
  20. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/execute.py +0 -0
  21. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/function_cli.py +0 -0
  22. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/generate.py +0 -0
  23. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/py.typed +0 -0
  24. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/schema.py +0 -0
  25. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/server.py +0 -0
  26. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/typedefs.py +0 -0
  27. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/utils.py +0 -0
  28. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/variables.py +0 -0
  29. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi/webhook.py +0 -0
  30. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi_python.egg-info/dependency_links.txt +0 -0
  31. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi_python.egg-info/requires.txt +0 -0
  32. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/polyapi_python.egg-info/top_level.txt +0 -0
  33. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/setup.cfg +0 -0
  34. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/tests/test_api.py +0 -0
  35. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/tests/test_auth.py +0 -0
  36. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/tests/test_function_cli.py +0 -0
  37. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/tests/test_server.py +0 -0
  38. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/tests/test_utils.py +0 -0
  39. {polyapi_python-0.2.5.dev3 → polyapi_python-0.2.5.dev4}/tests/test_variables.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.5.dev3
3
+ Version: 0.2.5.dev4
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -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 save_rendered_specs
8
+ from .rendered_spec import get_and_update_rendered_spec
9
9
 
10
10
 
11
- CLI_COMMANDS = ["setup", "generate", "function", "clear", "help", "save_rendered_specs"]
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 == "save_rendered_specs":
47
- save_rendered_specs()
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()
@@ -1,4 +1,7 @@
1
- from typing import Dict
1
+ from typing import Dict, Optional
2
+
3
+ import requests
4
+ from polyapi.config import get_api_key_and_url
2
5
  from polyapi.generate import read_cached_specs, render_spec
3
6
  from polyapi.execute import execute_post
4
7
  from polyapi.typedefs import SpecificationDto
@@ -19,11 +22,35 @@ def update_rendered_spec(spec: SpecificationDto):
19
22
  else:
20
23
  raise NotImplementedError("todo")
21
24
 
25
+ # use super key on develop-k8s here!
22
26
  resp = execute_post("/functions/rendered-specs", data)
23
27
  assert resp.status_code == 201, (resp.text, resp.status_code)
24
28
  # this needs to run with something like `kn func run...`
25
29
 
26
30
 
31
+ def _get_spec(api_key: str, spec_id: str) -> Optional[SpecificationDto]:
32
+ _, base_url = get_api_key_and_url()
33
+ url = f"{base_url}/specs"
34
+ headers = {"Authorization": f"Bearer {api_key}"}
35
+ resp = requests.get(url, headers=headers)
36
+ if resp.status_code == 200:
37
+ specs = resp.json()
38
+ for spec in specs:
39
+ if spec['id'] == spec_id:
40
+ return spec
41
+ return None
42
+ else:
43
+ raise NotImplementedError(resp.content)
44
+
45
+
46
+ def get_and_update_rendered_spec(api_key: str, spec_id: str) -> bool:
47
+ spec = _get_spec(api_key, spec_id)
48
+ if spec:
49
+ update_rendered_spec(spec)
50
+ return True
51
+ return False
52
+
53
+
27
54
  def save_rendered_specs() -> None:
28
55
  specs = read_cached_specs()
29
56
  # right now we just support rendered apiFunctions
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.5.dev3
3
+ Version: 0.2.5.dev4
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -30,6 +30,8 @@ polyapi_python.egg-info/top_level.txt
30
30
  tests/test_api.py
31
31
  tests/test_auth.py
32
32
  tests/test_function_cli.py
33
+ tests/test_rendered_spec.py
34
+ tests/test_schema.py
33
35
  tests/test_server.py
34
36
  tests/test_utils.py
35
37
  tests/test_variables.py
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
3
3
 
4
4
  [project]
5
5
  name = "polyapi-python"
6
- version = "0.2.5.dev3"
6
+ version = "0.2.5.dev4"
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.execute_post")
44
+ @patch("polyapi.rendered_spec._get_spec")
45
+ def test_get_and_update_rendered_spec_success(self, _get_spec, execute_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
+ execute_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