Skip to content

Commit

Permalink
LITE-28139 Add capability to validate PPR file using CBC PLM API
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulmondal committed Jul 20, 2023
1 parent 602c192 commit 14190a5
Show file tree
Hide file tree
Showing 8 changed files with 877 additions and 7 deletions.
1 change: 0 additions & 1 deletion connect_ext_ppr/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def execute_request(
if response is not None:
raise ClientError(
message=f'{type(e).__name__} : {str(e)}',
status_code=response.status_code,
response=response,
cause=e,
)
Expand Down
9 changes: 7 additions & 2 deletions connect_ext_ppr/client/exception.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from json import JSONDecodeError

from requests import Response


class ClientError(RuntimeError):
def __init__(
self,
message: str,
status_code: int = None,
response: Response = None,
cause: Exception = None,
):
self.message = message
self.response = response
self.status_code = status_code
self.status_code = response.status_code if response else None
self.cause = cause
try:
self.json = response.json() if response else None
except JSONDecodeError:
self.json = None
28 changes: 24 additions & 4 deletions connect_ext_ppr/client/ns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from functools import cached_property
from io import FileIO
from typing import Dict

from connect_ext_ppr.client.mixin import (
ActionMixin,
Expand Down Expand Up @@ -63,10 +65,7 @@ def collection(self, name: str):
)


class Service(
NSBase,
ActionMixin,
):
class Service(NSBase):
def __init__(self, client, aps_type: str, path: str):
super().__init__(
client=client,
Expand Down Expand Up @@ -113,3 +112,24 @@ def get(self, **kwargs):
path=f'{self.path}/aps/2/resources/?implementing({self.aps_type})',
params=kwargs,
)

def action(
self,
name: str,
method: str = 'POST',
payload: dict = None,
file: FileIO = None,
headers: Dict[str, str] = None,
output: str = 'body',
):
if payload and file:
raise ValueError('Either payload or file can be specified.')

return self.client.execute_request(
method=method,
path=f'{self.service_path}/{name}',
payload=payload,
file=file,
headers=headers,
output=output,
)
12 changes: 12 additions & 0 deletions connect_ext_ppr/services/cbc_hub.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import base64
from functools import cached_property
from io import FileIO

from connect_ext_ppr.client import CBCClient
from connect_ext_ppr.client.exception import ClientError
Expand Down Expand Up @@ -81,3 +83,13 @@ def update_product(self, product_id: str):
'fulfillmentSystem': 'connect',
},
)

def parse_ppr(self, file: FileIO):
base64_content = base64.b64encode(file.read()).decode('ascii')

return self.plm_service.action(
name='parseConfig',
payload={
'excelConfig': base64_content,
},
)
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,13 @@ def plm_service():
@pytest.fixture
def plm_services(plm_service):
return [plm_service]


@pytest.fixture
def sample_ppr_file():
return open('./tests/fixtures/Sweet_Pies_v2.xlsx', 'rb')


@pytest.fixture
def parse_ppr_success_response():
return json.load(open('./tests/fixtures/parse_ppr_success_response.json'))
Binary file added tests/fixtures/Sweet_Pies_v2.xlsx
Binary file not shown.
Loading

0 comments on commit 14190a5

Please sign in to comment.