Skip to content

Commit

Permalink
Backup, adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Benkevich committed Nov 30, 2020
1 parent 6205ec5 commit dd956e3
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 53 deletions.
4 changes: 2 additions & 2 deletions almdrlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,10 @@ def add_xof(item):
else:
return item

allprops = reduce(lambda acc, s: acc + list(s.get(OpenAPIKeyWord.PROPERTIES).items()), compound_schema, [])
allprops = reduce(lambda acc, s: acc + list(s.get(OpenAPIKeyWord.PROPERTIES, {}).items()), compound_schema, [])
reduced = reduce(reduce_props, allprops, OrderedDict())
compound_props = OrderedDict(map(add_xof, reduced.items()))
properties = compound_props
properties = compound_props

if not properties:
properties = OrderedDict({
Expand Down
29 changes: 29 additions & 0 deletions tests/apis/testapi/testapi.v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@ servers:
description: integration
x-alertlogic-session-endpoint: true
paths:
'/testapi/v1/postdata':
post:
operationId: post_data_compound
requestBody:
content:
application/json:
schema:
oneOf:
- type: object
properties:
prop:
type: string
additionalProperties: true
- type: object
properties:
prop:
type: integer
- type: string
responses:
'200':
description: 200 resp
content:
application/json:
schema:
type: object
properties:
prop:
type: string

'/testapi/v1/{account_id}/test_get_data':
get:
summary: Test Get Data Operation
Expand Down
113 changes: 62 additions & 51 deletions tests/test_open_api_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from almdrlib.client import Config
from almdrlib.client import Operation
from alsdkdefs import OpenAPIKeyWord

from collections import OrderedDict

class TestSdk_open_api_support(unittest.TestCase):
"""Tests for `python_boilerplate` package."""
Expand All @@ -32,54 +32,65 @@ def setUp(self):
def tearDown(self):
"""Tear down test fixtures, if any."""

def test_000_getting_schemas(self):
"""Test listing services."""
self.assertTrue(len(Session.get_service_api("testapi")))
print(f"SCHEMA: {json.dumps(Session.get_service_api('testapi'))}")

def test_001_test_client_initialization(self):
"""Test OpenAPI Client initialization."""
# def test_000_getting_schemas(self):
# """Test listing services."""
# self.assertTrue(len(Session.get_service_api("testapi")))
# print(f"SCHEMA: {json.dumps(Session.get_service_api('testapi'))}")
#
# def test_001_test_client_initialization(self):
# """Test OpenAPI Client initialization."""
# client = Client(self._service_name)
# self.assertIsInstance(client, Client)
# self.assertIsNotNone(client.description)
# self.assertNotEqual(client.name, "")
# self.assertIsNotNone(client.server)
# self.assertNotEqual(client.info, {})
# self.assertIsNotNone(client.operations)
# self.assertNotEqual(client.spec, {})
# self.assertNotEqual(client.operations, {})
#
# def test_002_test_operations_schema(self):
# """Test Operations Schema Validity."""
# client = Client(self._service_name)
#
# for t_operation_name, t_operation_schema in \
# self.test_data['operations'].items():
# operation = client.operations.get(t_operation_name)
# self.assertIsInstance(operation, Operation)
# self.assertEqual(operation.operation_id, t_operation_name)
# self.assertEqual(operation.description,
# t_operation_schema[OpenAPIKeyWord.DESCRIPTION])
#
# schema = operation.get_schema()
# self.assertIsNot(schema, {})
#
# t_operation_parameters = t_operation_schema[
# OpenAPIKeyWord.PARAMETERS]
#
# operation_parameters = schema[OpenAPIKeyWord.PARAMETERS]
# for name, value in t_operation_parameters.items():
# self.assertEqual(value, operation_parameters[name])
#
# if OpenAPIKeyWord.CONTENT in t_operation_schema:
# t_operation_content = t_operation_schema[
# OpenAPIKeyWord.CONTENT]
# operation_content = schema[OpenAPIKeyWord.CONTENT]
# for name, value in t_operation_content.items():
# self.assertEqual(value, operation_content[name])
#
# def test_003_default_objects_creation(self):
# """Checks initialisation at least happens"""
# self.assertIsInstance(Session(), Session)
# self.assertIsInstance(Config(), Config)
# self.assertIsInstance(Client(self._service_name), Client)

def test_004_test_operations_compound_schema(self):
"""Test request body properties are properly normalized when schema is compound at the top level"""
client = Client(self._service_name)
self.assertIsInstance(client, Client)
self.assertIsNotNone(client.description)
self.assertNotEqual(client.name, "")
self.assertIsNotNone(client.server)
self.assertNotEqual(client.info, {})
self.assertIsNotNone(client.operations)
self.assertNotEqual(client.spec, {})
self.assertNotEqual(client.operations, {})

def test_002_test_operations_schema(self):
"""Test Operations Schema Validity."""
client = Client(self._service_name)

for t_operation_name, t_operation_schema in \
self.test_data['operations'].items():
operation = client.operations.get(t_operation_name)
self.assertIsInstance(operation, Operation)
self.assertEqual(operation.operation_id, t_operation_name)
self.assertEqual(operation.description,
t_operation_schema[OpenAPIKeyWord.DESCRIPTION])

schema = operation.get_schema()
self.assertIsNot(schema, {})

t_operation_parameters = t_operation_schema[
OpenAPIKeyWord.PARAMETERS]

operation_parameters = schema[OpenAPIKeyWord.PARAMETERS]
for name, value in t_operation_parameters.items():
self.assertEqual(value, operation_parameters[name])

if OpenAPIKeyWord.CONTENT in t_operation_schema:
t_operation_content = t_operation_schema[
OpenAPIKeyWord.CONTENT]
operation_content = schema[OpenAPIKeyWord.CONTENT]
for name, value in t_operation_content.items():
self.assertEqual(value, operation_content[name])

def test_003_default_objects_creation(self):
"""Checks initialisation at least happens"""
self.assertIsInstance(Session(), Session)
self.assertIsInstance(Config(), Config)
self.assertIsInstance(Client(self._service_name), Client)
operation = client.operations.get('post_data_compound')
self.assertEqual(OrderedDict([('prop',
OrderedDict([('oneOf', [
OrderedDict([('type', 'integer')]),
OrderedDict([('type', 'string')])
])]))]),
operation.body._content['application/json']._properties)

0 comments on commit dd956e3

Please sign in to comment.