Example #1
0
    def test_parse_contract(self):
        raw_contract = get_fixture("contract")
        parsed_contract = parse_contract(raw_contract=raw_contract)

        expectation = Contract(
            id="cAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP",
            account_id="aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP",
            name="Product Name",
            product_id="product-id",
            entitlements=[
                Entitlement(
                    type="entitlement-type-2",
                    support_level=None,
                    enabled_by_default=False,
                ),
                Entitlement(
                    type="support",
                    support_level="advanced",
                    enabled_by_default=False,
                ),
            ],
            items=[
                ContractItem(
                    contract_id="cAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP",
                    created_at="2017-01-02T10:00:00Z",
                    start_date="2017-01-02T10:00:00Z",
                    end_date="2018-01-02T10:00:00Z",
                    reason="trial_started",
                    value=1,
                    product_listing_id="lAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP",
                    purchase_id=None,
                    trial_id="tAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP",
                ),
                ContractItem(
                    contract_id="cAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP",
                    created_at="2017-02-02T10:00:00Z",
                    start_date="2017-02-02T10:00:00Z",
                    end_date="2018-02-02T10:00:00Z",
                    reason="purchase_made",
                    value=1,
                    product_listing_id="lAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP",
                    purchase_id="pAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP",
                    trial_id=None,
                ),
            ],
        )

        self.assertIsInstance(parsed_contract, Contract)
        self.assertEqual(to_dict(expectation), to_dict(parsed_contract))
Example #2
0
    def test_parse_legacy_contract_items(self):
        raw_contract_items = [get_fixture("contract-item-legacy")]

        parsed_contract_items = parse_contract_items(
            raw_items=raw_contract_items)

        expectation = [
            ContractItem(
                contract_id="cAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP2",
                created_at="2014-01-01T10:00:00Z",
                start_date="2014-01-01T10:00:00Z",
                end_date="2015-01-01T00:00:00Z",
                reason="contract_created",
                value=5,
                product_listing_id=None,
                purchase_id=None,
                trial_id=None,
                renewal=Renewal(
                    id="rAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP2",
                    contract_id="cAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP2",
                    actionable=True,
                    start_date="2014-11-01T00:00:00Z",
                    end_date="2015-01-01T00:00:00Z",
                    status="pending",
                    new_contract_start="2015-01-01T00:00:00Z",
                    price=5000,
                    currency="USD",
                ),
            ),
        ]

        self.assertIsInstance(parsed_contract_items, List)
        self.assertEqual(to_dict(expectation), to_dict(parsed_contract_items))
Example #3
0
def make_legacy_contract_item(
    contract_id: str = None,
    created_at: str = None,
    start_date: str = None,
    end_date: str = None,
    reason: str = None,
    value: int = None,
    renewal: Renewal = None,
) -> ContractItem:
    default_renewal = Renewal(
        id="rAaBbCcDdEeFfGg",
        contract_id="cAaBbCcDdEeFfGg",
        actionable=True,
        status="pending",
        start_date="2020-01-01T10:00:00Z",
        end_date="2021-01-01T10:00:00Z",
        new_contract_start="2020-01-01T10:00:00Z",
        price=10000,
        currency="USD",
    )

    return ContractItem(
        contract_id=contract_id or "cAaBbCcDdEeFfGg",
        created_at=created_at or "2020-01-01T00:00:00Z",
        start_date=start_date or "2020-01-01T00:00:00Z",
        end_date=end_date or "2020-03-01T00:00:00Z",
        reason=reason or "contract_created",
        value=value or 5,
        renewal=renewal or default_renewal,
    )
Example #4
0
def make_contract_item(
    contract_id: str = None,
    created_at: str = None,
    start_date: str = None,
    end_date: str = None,
    reason: str = None,
    value: int = None,
    product_listing_id: str = None,
    purchase_id: str = None,
    trial_id: str = None,
    renewal: Renewal = None,
) -> ContractItem:

    return ContractItem(
        contract_id=contract_id or "cAaBbCcDdEeFfGg",
        created_at=created_at or "2020-01-01T00:00:00Z",
        start_date=start_date or "2020-01-01T00:00:00Z",
        end_date=end_date or "2020-03-01T00:00:00Z",
        reason=reason or "purchase_made",
        value=value or 5,
        product_listing_id=product_listing_id or "lAaBbCcDdEeFfGg",
        purchase_id=purchase_id or "pAaBbCcDdEeFfGg",
        trial_id=trial_id or None,
        renewal=renewal or None,
    )
Example #5
0
def make_free_trial_contract_item(
    contract_id: str = None,
    created_at: str = None,
    start_date: str = None,
    end_date: str = None,
    product_listing_id: str = None,
    purchase_id: str = None,
    trial_id: str = None,
) -> ContractItem:
    return ContractItem(
        contract_id=contract_id or "cAaBbCcDdEeFfGg",
        created_at=created_at or "2020-01-01T00:00:00Z",
        start_date=start_date or "2020-01-01T00:00:00Z",
        end_date=end_date or "2020-03-01T00:00:00Z",
        reason="trial_started",
        value=1,
        product_listing_id=product_listing_id or "lAaBbCcDdEeFfGg",
        purchase_id=purchase_id or "pAaBbCcDdEeFfGg",
        trial_id=trial_id or "tAaBbcCdDeEFfGg",
    )
Example #6
0
    def test_parse_purchase_contract_items(self):
        raw_contract_items = [get_fixture("contract-item-shop")]

        parsed_contract_items = parse_contract_items(
            raw_items=raw_contract_items)

        expectation = [
            ContractItem(
                contract_id="cAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP2",
                created_at="2014-02-01T10:00:00Z",
                start_date="2014-03-01T10:00:00Z",
                end_date="2015-03-01T00:00:00Z",
                reason="purchase_made",
                value=1,
                product_listing_id="lAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP2",
                purchase_id="pAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpP2",
                trial_id=None,
            ),
        ]

        self.assertIsInstance(parsed_contract_items, List)
        self.assertEqual(to_dict(expectation), to_dict(parsed_contract_items))
Example #7
0
def parse_contract_items(raw_items: List[Dict] = None) -> List[ContractItem]:
    items = []
    raw_items = raw_items or []
    for raw_item in raw_items:
        raw_renewal = raw_item.get("renewal")

        item = ContractItem(
            contract_id=raw_item.get("contractID"),
            created_at=raw_item.get("created"),
            start_date=raw_item.get("effectiveFrom"),
            end_date=raw_item.get("effectiveTo"),
            reason=raw_item.get("reason"),
            value=raw_item.get("value"),
            product_listing_id=raw_item.get("productListingID"),
            purchase_id=raw_item.get("purchaseID"),
            trial_id=raw_item.get("trialID"),
            renewal=parse_renewal(raw_renewal) if raw_renewal else None,
        )

        items.append(item)

    return items