def test_discount_code_get_by_id(client):
    discount_code = client.discount_codes.create(
        types.DiscountCodeDraft(
            name=types.LocalizedString({"en": "test discount"}),
            code="1337",
        ))

    assert discount_code.id
    assert discount_code.code == "1337"

    discount_code = client.discount_codes.get_by_id(discount_code.id)
    assert discount_code.id
    assert discount_code.code == "1337"

    with pytest.raises(HTTPError):
        client.discount_codes.get_by_id("invalid")
def test_discount_code_update(client):
    discount_code = client.discount_codes.create(
        types.DiscountCodeDraft(
            name=types.LocalizedString(en="en-discount_code"),
            code="1337",
            is_active=True,
        ))
    assert discount_code.code == "1337"

    discount_code = client.discount_codes.update_by_id(
        id=discount_code.id,
        version=discount_code.version,
        actions=[types.DiscountCodeChangeIsActiveAction(is_active=False)],
    )

    assert discount_code.is_active is False
 def post_load(self, data):
     return types.DiscountCodeDraft(**data)