Skip to content

Commit

Permalink
[HF] MPT-6549 Account revival is failing if the account to be transfe… (
Browse files Browse the repository at this point in the history
#323)

…rred has one-time items
  • Loading branch information
d3rky authored and Robert Segal committed Feb 4, 2025
2 parents e0fd807 + f07b7aa commit 9dbe8e4
Show file tree
Hide file tree
Showing 15 changed files with 700 additions and 19 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/pr-build-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ jobs:
run: |
sed -i 's/\/extension\/adobe_vipm/\/home\/runner\/work\/swo-adobe-vipm-extension\/swo-adobe-vipm-extension\/adobe_vipm/g' coverage.xml
- name: 'Run SonarCloud Scan'
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: 'Run SonarQube Quality Gate check'
uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# - name: 'Run SonarCloud Scan'
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

# - name: 'Run SonarQube Quality Gate check'
# uses: sonarsource/sonarqube-quality-gate-action@master
# timeout-minutes: 5
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: 'Stop containers'
if: always()
Expand Down
16 changes: 12 additions & 4 deletions adobe_vipm/flows/fulfillment/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
switch_order_to_query,
)
from adobe_vipm.flows.helpers import SetupContext
from adobe_vipm.flows.mpt import update_order
from adobe_vipm.flows.mpt import get_product_items_by_skus, update_order
from adobe_vipm.flows.pipeline import Pipeline, Step
from adobe_vipm.flows.sync import sync_agreements_by_agreement_ids
from adobe_vipm.flows.utils import (
Expand Down Expand Up @@ -470,10 +470,18 @@ def _transfer_migrated(
customer_deployments,
):
return

adobe_transfer = exclude_items_with_deployment_id(adobe_transfer)

one_time_skus = get_one_time_skus(mpt_client, order)
returned_skus = [
get_partial_sku(item["offerId"]) for item in adobe_subscriptions["items"]
]
items = get_product_items_by_skus(
mpt_client, order["agreement"]["product"]["id"], returned_skus
)
one_time_skus = [
item["externalIds"]["vendor"]
for item in items
if item["terms"]["period"] == "one-time"
]
adobe_items_without_one_time_offers = [
item
for item in adobe_subscriptions["items"]
Expand Down
178 changes: 178 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import copy
import signal
from collections import defaultdict
from datetime import UTC, date, datetime, timedelta

import jwt
import pytest
import responses
from swo.mpt.extensions.core.events.dataclasses import Event
from swo.mpt.extensions.runtime.djapp.conf import get_for_product
from swo.mpt.extensions.runtime.master import Master

from adobe_vipm.adobe.client import AdobeClient
from adobe_vipm.adobe.config import Config
Expand Down Expand Up @@ -1511,3 +1514,178 @@ def _mocked_cache(cache=None):
@pytest.fixture()
def mocked_pricelist_cache(mock_pricelist_cache_factory):
return mock_pricelist_cache_factory()


@pytest.fixture()
def mocked_setup_master_signal_handler():
signal_handler = signal.getsignal(signal.SIGINT)

def handler(signum, frame):
print("Signal handler called with signal", signum)
signal.signal(signal.SIGINT, signal_handler)

signal.signal(signal.SIGINT, handler)


@pytest.fixture()
def mock_gradient_result():
return [
"#00C9CD",
"#07B7D2",
"#0FA5D8",
"#1794DD",
"#1F82E3",
"#2770E8",
"#2F5FEE",
"#374DF3",
"#3F3BF9",
"#472AFF",
]


@pytest.fixture()
def mock_runtime_master():
color = True
debug = False
reload = True
component = "all"
return Master(
{"color:": color, "debug": debug, "reload": reload, "component": component}
)


@pytest.fixture()
def mock_swoext_commands():
return (
"swo.mpt.extensions.runtime.commands.run.run",
"swo.mpt.extensions.runtime.commands.django.django",
)


@pytest.fixture()
def mock_dispatcher_event():
return {
"type": "event",
"id": "event-id",
}


@pytest.fixture()
def mock_workers_options():
return {
"color": False,
"debug": False,
"reload": False,
"component": "all",
}


@pytest.fixture()
def mock_gunicorn_logging_config():
return {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "{asctime} {name} {levelname} (pid: {process}) {message}",
"style": "{",
},
"rich": {
"format": "%(message)s",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "verbose",
},
"rich": {
"class": "swo.mpt.extensions.runtime.logging.RichHandler",
"formatter": "rich",
"log_time_format": lambda x: x.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3],
"rich_tracebacks": True,
},
},
"root": {
"handlers": ["rich"],
"level": "WARNING",
},
"loggers": {
"django": {
"handlers": ["rich"],
"level": "INFO",
"propagate": False,
},
"swo.mpt": {
"handlers": ["rich"],
"level": "DEBUG",
"propagate": False,
},
"azure": {
"handlers": ["rich"],
"level": "WARNING",
"propagate": False,
},
},
}


@pytest.fixture()
def mock_wrap_event():
return Event("evt-id", "orders", {"id": "ORD-1111-1111-1111"})


@pytest.fixture()
def mock_meta_with_pagination_has_more_pages():
return {
"$meta": {
"pagination": {
"offset": 0,
"limit": 10,
"total": 12,
},
},
}


@pytest.fixture()
def mock_meta_with_pagination_has_no_more_pages():
return {
"$meta": {
"pagination": {
"offset": 0,
"limit": 10,
"total": 4,
},
},
}

@pytest.fixture()
def mock_logging_account_prefixes():
return ("ACC", "BUY", "LCE", "MOD", "SEL", "USR", "AUSR", "UGR")

@pytest.fixture()
def mock_logging_catalog_prefixes():
return (
"PRD",
"ITM",
"IGR",
"PGR",
"MED",
"DOC",
"TCS",
"TPL",
"WHO",
"PRC",
"LST",
"AUT",
"UNT",
)

@pytest.fixture()
def mock_logging_commerce_prefixes():
return ("AGR", "ORD", "SUB", "REQ")

@pytest.fixture()
def mock_logging_aux_prefixes():
return ("FIL", "MSG")
20 changes: 20 additions & 0 deletions tests/core/test_core_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from swo.mpt.extensions.core.events.registry import EventsRegistry
from swo.mpt.extensions.runtime.utils import get_events_registry


def test_get_events_registry():
registry = get_events_registry()
assert isinstance(registry, EventsRegistry)


def test_registry_listener():
registry = EventsRegistry()

@registry.listener("orders")
def test_listener(client, event):
pass

assert registry.get_listener("orders") == test_listener
assert registry.get_registered_types() == ["orders"]
assert registry.is_event_supported("orders")
assert not registry.is_event_supported("unknown")
10 changes: 10 additions & 0 deletions tests/core/test_core_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.conf import settings
from swo.mpt.client import MPTClient
from swo.mpt.extensions.core.utils import setup_client


def test_setup_client():
client = setup_client()
assert isinstance(client, MPTClient)
assert client.base_url == f"{settings.MPT_API_BASE_URL}/v1/"
assert client.api_token == settings.MPT_API_TOKEN
Loading

0 comments on commit 9dbe8e4

Please sign in to comment.