Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LITE-29254 Product parameter deps are correctly sent to GDL #30

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
exclude = .idea,.vscode,.git,pg_data,venv,env,
exclude = .idea,.vscode,.git,pg_data,venv,env,node_modules
show-source = True
max-line-length = 100
application-import-names = connect_ext_datalake
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cloudblueconnect/connect-extension-runner:28.7
FROM cloudblueconnect/connect-extension-runner:29.4

COPY pyproject.toml /install_temp/.
COPY poetry.* /install_temp/.
Expand Down
48 changes: 35 additions & 13 deletions connect_ext_datalake/services/payloads.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2023, Ingram Micro - Rahul Mondal
# Copyright (c) 2023, Ingram Micro
# All rights reserved.
#
from collections import defaultdict
from datetime import datetime, timedelta, timezone

from connect.client import ConnectClient, R
Expand All @@ -28,24 +29,44 @@ def verify_property(obj: dict, properties: dict[str, str]):


def populate_dependents(parameters: list):
dependency_map = {}

"""
Approx. the following reversal logic is directly applied to the list of parameters for deps:
[
{'id': 'PRM-1', 'constraints': {'dependency': {'parameter': {'id': 'PRM-2'}}}},
{'id': 'PRM-2'},
]

->

[
{'id': 'PRM-1'},
{'id': 'PRM-2', 'constraints': {'dependents': [{'id': 'PRM-2'}]}},
]
"""

dependency_exists = False
dependency_map = defaultdict(list)
for param in parameters:
if 'constraints' in param.keys() and 'dependency' in param['constraints'].keys():
parent_param_id = param['constraints']['dependency']['id']
dep = ((param.get('constraints') or {}).get('dependency') or {}).pop('parameter', None)

if dep:
dependency_exists = True

dependent_object = param['constraints'].pop('dependency')
dependent_object['id'] = param['id']
dependent_object['name'] = param['name']
dependent_object['name'] = param.get('name')
dependent_object['value'] = dependent_object.pop('values', [])
dependency_map[dep['id']].append(dependent_object)

if parent_param_id not in dependency_map.keys():
dependency_map[parent_param_id] = []
if not dependency_exists:
return

dependency_map[parent_param_id].append(dependent_object)
for param in parameters:
dependents = dependency_map.get(param['id'])

if dependency_map:
for param in parameters:
if param['id'] in dependency_map.keys():
param['constraints']['dependents'] = dependency_map[param['id']]
if dependents:
param.setdefault('constraints', {})
param['constraints']['dependents'] = dependents


def sanitize_product(product: dict):
Expand Down Expand Up @@ -74,6 +95,7 @@ def sanitize_product(product: dict):


def sanitize_parameters(parameters: list):
populate_dependents(parameters)
for parameter in parameters:
remove_properties(
parameter,
Expand Down
872 changes: 392 additions & 480 deletions poetry.lock

Large diffs are not rendered by default.

64 changes: 41 additions & 23 deletions tests/fixtures/product_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@
"unique": false,
"readonly": false,
"dependency": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference",
"value": [
"parameter": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference"
},
"values": [
"new",
"existing"
],
"hidden": false
"hidden": false,
"required": true,
"readonly": false
},
"choices": [
{
Expand All @@ -73,9 +77,11 @@
"unique": false,
"readonly": false,
"dependency": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference",
"value": [
"parameter": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference"
},
"values": [
"new"
],
"hidden": false
Expand Down Expand Up @@ -107,9 +113,11 @@
"unique": false,
"readonly": false,
"dependency": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference",
"value": [
"parameter": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference"
},
"values": [
"new"
],
"hidden": false
Expand All @@ -131,9 +139,11 @@
"unique": false,
"readonly": false,
"dependency": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference",
"value": [
"parameter": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference"
},
"values": [
"new"
],
"hidden": false
Expand All @@ -156,9 +166,11 @@
"unique": false,
"readonly": false,
"dependency": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference",
"value": [
"parameter": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference"
},
"values": [
"new"
],
"hidden": false
Expand All @@ -180,13 +192,17 @@
"unique": false,
"readonly": false,
"dependency": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference",
"value": [
"parameter": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference"
},
"values": [
"new",
"existing"
],
"hidden": false
"hidden": true,
"required": false

},
"choices": [
{
Expand All @@ -212,9 +228,11 @@
"unique": false,
"readonly": false,
"dependency": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference",
"value": [
"parameter": {
"id": "PRM-814-505-018-0005",
"name": "tenant_preference"
},
"values": [
"new"
],
"hidden": false
Expand Down
7 changes: 5 additions & 2 deletions tests/fixtures/product_params_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"new",
"existing"
],
"hidden": false
"hidden": false,
"required": true,
"readonly": false
},
{
"id": "PRM-814-505-018-0012",
Expand Down Expand Up @@ -72,7 +74,8 @@
"new",
"existing"
],
"hidden": false
"hidden": true,
"required": false
},
{
"id": "PRM-814-505-018-0096",
Expand Down
112 changes: 111 additions & 1 deletion tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from google.cloud.pubsub_v1 import PublisherClient
import pytest

from connect_ext_datalake.services.payloads import populate_dependents
from connect_ext_datalake.services.payloads import populate_dependents, sanitize_parameters
from connect_ext_datalake.services.publish import get_pubsub_client


Expand Down Expand Up @@ -47,3 +47,113 @@ def test_populate_dependents_positional_change(
expected_param_list.append(first_param)

TestCase().assertListEqual(params, expected_param_list)


@pytest.mark.parametrize('inp,outp', [
[[], []],
[[{'id': 'PRM-1'}], [{'id': 'PRM-1'}]],
[
[
{
'id': 'PRM-1',
'name': '1',
'constraints': {
'hidden': True,
'dependency': {
'parameter': {
'id': 'PRM-2',
'name': '2',
},
'values': ['1'],
'required': True,
'xyz': False,
},
},
'events': {
'created': {},
},
},
{
'id': 'PRM-2',
'name': '2',
},
{
'id': 'PRM-3',
'name': '3',
'constraints': {
'dependency': {
'parameter': {
'id': 'PRM-2',
'name': '2',
},
'values': ['2', '1'],
},
},
},
{
'id': 'PRM-4',
'constraints': {
'something': True,
'dependency': {
'parameter': {
'id': 'PRM-1',
'name': '1',
},
'values': [''],
'required': False,
},
},
},
],
[
{
'id': 'PRM-1',
'name': '1',
'constraints': {
'hidden': True,
'dependents': [
{
'id': 'PRM-4',
'name': None,
'value': [''],
'required': False,
},
],
},
},
{
'id': 'PRM-2',
'name': '2',
'constraints': {
'dependents': [
{
'id': 'PRM-1',
'name': '1',
'value': ['1'],
'required': True,
'xyz': False,
},
{
'id': 'PRM-3',
'name': '3',
'value': ['2', '1'],
},
],
},
},
{
'id': 'PRM-3',
'name': '3',
'constraints': {},
},
{
'id': 'PRM-4',
'constraints': {
'something': True,
},
},
],
],
])
def test_sanitize_parameters(inp, outp):
assert outp == sanitize_parameters(inp)