Skip to content

Commit

Permalink
LITE-28131 Add capability to upload PPR for a hub
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulmondal committed Jul 20, 2023
1 parent 9a7347a commit ecabb3e
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 89 deletions.
29 changes: 29 additions & 0 deletions connect_ext_ppr/services/cbc_hub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import base64
from functools import cached_property
from io import FileIO
import re
from typing import Dict

from connect_ext_ppr.client import CBCClient
from connect_ext_ppr.client.exception import ClientError
Expand All @@ -11,6 +13,7 @@ class CBCService:

PLM_TYPE = 'http://com.odin.platform/inhouse-products/application'
SUBSCRIPTION_TYPE = 'http://parallels.com/aps/types/pa/subscription'
ADAPTER_TYPE = 'http://connect.cloudblue.com/aps-openapi-adapter/app'

def __init__(self, hub_credential: HubCredential, verify_certificate: bool = False):
self.hub_credential = hub_credential
Expand Down Expand Up @@ -61,6 +64,10 @@ def plm_service(self):
def subscription_service(self):
return self.client(self.SUBSCRIPTION_TYPE)

@cached_property
def adapter_service(self):
return self.client(self.ADAPTER_TYPE)

def get_product_details(self, product_id: str):
return self.plm_service.appDetails[product_id].get(
fulfillmentSystem='connect',
Expand Down Expand Up @@ -93,3 +100,25 @@ def parse_ppr(self, file: FileIO):
'excelConfig': base64_content,
},
)

def apply_ppr(self, parsed_ppr: Dict):
headers = self.plm_service.action(
name='applyConfig',
payload=parsed_ppr,
output='headers',
)

task_info = headers['APS-Info'] if 'APS-Info' in headers.keys() else None

if task_info:
tracking_ids = re.findall(
r'[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}',
task_info,
)

return tracking_ids[0] if tracking_ids else None

def search_task_logs_by_name(self, partial_name: str):
return self.adapter_service.getTaskLog.get(
task_name=f'%{partial_name}%',
)
8 changes: 4 additions & 4 deletions tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
def test_client_get(
cbc_client,
cbc_endpoint,
flat_catalog_type_object,
service,
):
object_id = flat_catalog_type_object['aps']['id']
object_id = service['aps']['id']

responses.add(
method='GET',
url=f'{cbc_endpoint}/aps/2/resources/{object_id}',
json=flat_catalog_type_object,
json=service,
)

obj = cbc_client.get(object_id)

TestCase().assertDictEqual(obj, flat_catalog_type_object)
TestCase().assertDictEqual(obj, service)


@responses.activate
Expand Down
20 changes: 10 additions & 10 deletions tests/client/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ def test_collection_wrong_collection_value_type(cbc_client):
def test_collection_get(
cbc_endpoint,
cbc_client,
flat_catalog_type_objects,
services,
):
responses.add(
method='GET',
url=f'{cbc_endpoint}/flat-catalog',
json=flat_catalog_type_objects,
json=services,
)

objs = cbc_client.flat_catalog.get()

TestCase().assertListEqual(objs, flat_catalog_type_objects)
TestCase().assertListEqual(objs, services)


def test_sub_collection(cbc_endpoint, cbc_client):
Expand Down Expand Up @@ -74,39 +74,39 @@ def test_collection_resource_wrong_type(cbc_client):
def test_collection_get_with_identifier(
cbc_endpoint,
cbc_client,
flat_catalog_type_object,
service,
):
object_id = flat_catalog_type_object['aps']['id']
object_id = service['aps']['id']

responses.add(
method='GET',
url=f'{cbc_endpoint}/flat-catalog/wizard/{object_id}',
json=flat_catalog_type_object,
json=service,
)

obj = cbc_client.flat_catalog.wizard[object_id].get()

TestCase().assertDictEqual(obj, flat_catalog_type_object)
TestCase().assertDictEqual(obj, service)


@responses.activate
def test_collection_action(
cbc_endpoint,
cbc_client,
flat_catalog_type_object,
service,
):
responses.add(
method='POST',
url=f'{cbc_endpoint}/flat-catalog/wizard/upload',
json=flat_catalog_type_object,
json=service,
)

obj = cbc_client.flat_catalog.wizard.action(
name='upload',
payload={},
)

TestCase().assertDictEqual(obj, flat_catalog_type_object)
TestCase().assertDictEqual(obj, service)


def test_collection_action_with_both_payload_and_file(cbc_client):
Expand Down
30 changes: 15 additions & 15 deletions tests/client/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,44 @@ def test_resource(cbc_endpoint, cbc_client):
def test_resource_get(
cbc_endpoint,
cbc_client,
flat_catalog_type_object,
service,
):
responses.add(
method='GET',
url=f'{cbc_endpoint}/test-collection/identifier',
json=flat_catalog_type_object,
json=service,
)

obj = cbc_client.test_collection['identifier'].get()

TestCase().assertDictEqual(obj, flat_catalog_type_object)
TestCase().assertDictEqual(obj, service)


@responses.activate
def test_resource_action_with_payload(
cbc_endpoint,
cbc_client,
flat_catalog_type_object,
service,
):
responses.add(
method='POST',
url=f'{cbc_endpoint}/test-collection/identifier/upload',
json=flat_catalog_type_object,
json=service,
)

obj = cbc_client.test_collection['identifier'].action(
name='upload',
payload={},
)

TestCase().assertDictEqual(obj, flat_catalog_type_object)
TestCase().assertDictEqual(obj, service)


@responses.activate
def test_resource_action_not_json_response(
cbc_endpoint,
cbc_client,
flat_catalog_type_object,
service,
):
responses.add(
method='POST',
Expand All @@ -71,12 +71,12 @@ def test_resource_action_not_json_response(
def test_resource_action_with_extra_headers(
cbc_endpoint,
cbc_client,
flat_catalog_type_object,
service,
):
responses.add(
method='POST',
url=f'{cbc_endpoint}/test-collection/identifier/upload',
json=flat_catalog_type_object,
json=service,
)

obj = cbc_client.test_collection['identifier'].action(
Expand All @@ -85,39 +85,39 @@ def test_resource_action_with_extra_headers(
headers={'Content-Type': 'application/json'},
)

TestCase().assertDictEqual(obj, flat_catalog_type_object)
TestCase().assertDictEqual(obj, service)


@responses.activate
def test_resource_action_with_file(
cbc_endpoint,
cbc_client,
flat_catalog_type_object,
service,
):
responses.add(
method='POST',
url=f'{cbc_endpoint}/test-collection/identifier/upload',
json=flat_catalog_type_object,
json=service,
)

obj = cbc_client.test_collection['identifier'].action(
name='upload',
file=io.StringIO("some initial text data"),
)

TestCase().assertDictEqual(obj, flat_catalog_type_object)
TestCase().assertDictEqual(obj, service)


@responses.activate
def test_resource_action_with_headers_output(
cbc_endpoint,
cbc_client,
flat_catalog_type_object,
service,
):
responses.add(
method='POST',
url=f'{cbc_endpoint}/test-collection/identifier/upload',
json=flat_catalog_type_object,
json=service,
)

obj = cbc_client.test_collection['identifier'].action(
Expand Down
26 changes: 13 additions & 13 deletions tests/client/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ def test_service_discovery(
cbc_endpoint,
cbc_client,
flat_catalog_type,
flat_catalog_type_objects,
services,
):
responses.add(
method='GET',
url=f'{cbc_endpoint}/aps/2/resources/?implementing({flat_catalog_type})',
json=flat_catalog_type_objects,
json=services,
)

services = cbc_client(flat_catalog_type).get()
TestCase().assertListEqual(services, flat_catalog_type_objects)
TestCase().assertListEqual(services, services)


@responses.activate
Expand Down Expand Up @@ -76,13 +76,13 @@ def test_service_discovery_collection_with_underscore(
cbc_endpoint,
cbc_client,
flat_catalog_type,
flat_catalog_type_objects,
services,
):
service_id = flat_catalog_type_objects[0]['aps']['id']
service_id = services[0]['aps']['id']
responses.add(
method='GET',
url=f'{cbc_endpoint}/aps/2/resources/?implementing({flat_catalog_type})',
json=flat_catalog_type_objects,
json=services,
)

collection = cbc_client(flat_catalog_type).flat_catalog
Expand All @@ -95,13 +95,13 @@ def test_service_discovery_collection(
cbc_endpoint,
cbc_client,
flat_catalog_type,
flat_catalog_type_objects,
services,
):
service_id = flat_catalog_type_objects[0]['aps']['id']
service_id = services[0]['aps']['id']
responses.add(
method='GET',
url=f'{cbc_endpoint}/aps/2/resources/?implementing({flat_catalog_type})',
json=flat_catalog_type_objects,
json=services,
)

service = cbc_client(flat_catalog_type)
Expand All @@ -122,12 +122,12 @@ def test_service_discovery_collection_wrong_collection_value_type(
cbc_endpoint,
cbc_client,
flat_catalog_type,
flat_catalog_type_objects,
services,
):
responses.add(
method='GET',
url=f'{cbc_endpoint}/aps/2/resources/?implementing({flat_catalog_type})',
json=flat_catalog_type_objects,
json=services,
)

with pytest.raises(TypeError):
Expand All @@ -139,12 +139,12 @@ def test_service_discovery_collection_blank_collection_value(
cbc_endpoint,
cbc_client,
flat_catalog_type,
flat_catalog_type_objects,
services,
):
responses.add(
method='GET',
url=f'{cbc_endpoint}/aps/2/resources/?implementing({flat_catalog_type})',
json=flat_catalog_type_objects,
json=services,
)

with pytest.raises(ValueError):
Expand Down
Loading

0 comments on commit ecabb3e

Please sign in to comment.