Skip to content

test: add guarded live API draft create/delete tier for sandbox-limited coverage #56

Description

@axisrow

Problem

Several write integration scenarios are blocked by Yandex Direct sandbox behavior tracked in #28. Some of those flows can be tested safely against the live API if the test creates disposable draft objects and deletes them immediately.

Yandex Direct campaigns can be created as drafts. A draft campaign can be created and deleted without serving ads, as long as the test never submits anything to moderation, never resumes an existing object, and never touches user-owned existing IDs.

Goal

Add a separate guarded live-write test tier that validates the safest production API mutation path:

  1. create a disposable draft campaign;
  2. verify it is not serving (Status=DRAFT and/or State=OFF);
  3. delete it;
  4. prove cleanup happened.

This becomes the foundation for testing sandbox-limited write flows that need real API persistence.

Safety contract

The live-write tier must be opt-in only.

Required guardrails:

  • use a dedicated pytest marker, for example integration_live_write;
  • skip unless YANDEX_DIRECT_LIVE_WRITE=1 is set;
  • require YANDEX_DIRECT_TOKEN;
  • optionally require YANDEX_DIRECT_LOGIN for agency/client isolation;
  • generated campaign names must use a unique prefix: direct-cli-live-test-<timestamp>-<uuid>;
  • tests may mutate only IDs created inside the same test run;
  • cleanup must run in finally;
  • no test may call moderate;
  • no test may call resume on production objects;
  • no test may update/delete/archive/suspend existing user objects;
  • failed cleanup must print the created IDs and fail loudly.

Initial scope

Implement only the minimal draft lifecycle first:

direct campaigns add --name direct-cli-live-test-<suffix> --start-date <tomorrow>
direct campaigns get --ids <created-id> --fields Id,Name,Status,State
direct campaigns delete --id <created-id>
direct campaigns get --ids <created-id> --fields Id,Name,Status,State

Expected result:

  • campaigns add returns a campaign ID;
  • campaigns get confirms the campaign is draft/inactive before deletion;
  • campaigns delete succeeds;
  • final campaigns get confirms the object is gone or no longer returned.

Follow-up scope after the root fixture is proven

Use the disposable draft campaign as the safe root for selected sandbox-limited checks:

Candidate Live-write safety Notes
adimages add/delete low standalone asset, should be tested next
sitelinks add/delete low-medium standalone sitelink set, do not attach to active ads
adgroups add/update/delete medium only inside disposable draft campaign
ads add/update/delete medium only inside disposable draft campaign/adgroup; never call moderate
keywords add/update/delete medium only inside disposable draft adgroup
bids set, keywordbids set medium-high only on disposable keyword created in the same run
audiencetargets add/delete medium-high only with disposable adgroup/list fixtures
dynamicads / smartadtargets high manual-only until draft fixture safety is proven

Implementation notes

  • Add marker registration in pytest config: integration_live_write: opt-in live production write tests.
  • Add fixtures for:
    • live-write opt-in guard;
    • unique test suffix;
    • live draft campaign create/delete.
  • Keep existing integration_write sandbox/VCR suite unchanged.
  • Do not run integration_live_write in normal CI.
  • If VCR is used later, cassettes must be reviewed for token/login leaks before commit.

Acceptance criteria

  • Running normal tests does not hit the live API.
  • Running without YANDEX_DIRECT_LIVE_WRITE=1 skips the live-write test.
  • Running with explicit opt-in creates exactly one disposable draft campaign and deletes it.
  • Test output includes the created campaign ID.
  • No existing campaign/ad/adgroup/keyword IDs can be passed into the test path.
  • test: roadmap for write integration beyond current Yandex sandbox limits #28 is updated with the result and next recommended candidate commands.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-status:supportedAPI surface is supported by official docs/WSDLenhancementFeature addition

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions