Page MenuHomePhabricator

Phester: bind variables to session context
Closed, InvalidPublic

Description

Session contexts should act as scopes for variables. This is also the mechanism by which fixtures can expose variables to tests.

Key ideas:

  • Every setup interaction (in a fixture or test suite) creates a session context (see T227885). Each fixture and each test suite is assumed to have a setup interaction and thus a session context, though the setup may be empty (and the setup stanza omitted).
  • When a fixture is declared to be used in a test suite, the fixture's context becomes available in that test suite, under the fixture's name (see T227885).
  • Variable references (in a variables stanza, or using yaml tags like p/grab or p/var or p/ix) are relative to the local context (that is, the context defined by the setup interaction in the same file - since there is one setup interaction per fixture or test suite, there is one per file).
  • Variables in an "imported" (fixture) context can be accessed by using the context's name (that is, the fixture's name) as a prefix, using "/" as the separator: Alice/user-id would reference the variable user-id in the context imported from the Alice context.
  • Special prefixes may be defined to provide access to additional variables, such as configuration. Special prefixes start with "/" to distinguish them from regular prefixes. Examples include /session/ (see below) and /config/
  • Only variables in the local context can be written (that is, set in a variables stanza or grabbed with p/grab). Variables from other contexts are immutable.
  • All tests in a suite may access the same variables, but if they modify these variables, that modification has to be local to the test, and invisible to other tests in the same suite. That is, variables defined in the suite's context act as parameters to the test.
  • When a test or an interaction step (request/response pair) uses a different session (via use-session, see T227885), variable references in that test or step are not automatically relative to that session. The special prefix /session/ can be used to force a variable to be looked up in the current session, instead of the local context. This is mostly useful in the context of prototypes (see T228776)

Example:

suite: CRUD
description: Test create/read/update/delete
type: RPC

use-fixtures:
  - Alice
  - Bob

variables:
  - title: p/ix: "CRUD_{{#random:16}}"   # stored in the local context
  - user-name: p/var: Bob/name           # access a variable from a fixture via a prefix

setup:
  - use-session: Alice                   # was made available by use-fixture above
    request:
      action: create
      page: p/var: title                 # from the local context, defined in the  variables stanza
      token: p/var: Alice/token          # from the Alice context, because of use-session Alice.

tests:
  - description: create and delete
     variables:
       - title: p/ix: "{{title}}/foo"    # Self-referential. New value is local to this test.
     interaction:
     -  request:                                           
           use-session: Alice            # Text context is cloned, so changes to cookies are local to this test.
           action: create
           page: p/var: title            # from the local context, defined in the  variables stanza
           token: p/var: /session/token  # from the Alice context, because of use-session Alice.
     - response:
         body:
           create:
             page-id: p/grab: page-id    # stored in this test's copy of the local context, invisible to other tests
     - request:
           use-session: Bob
           action: delete
           page-id: p/var: page-id       # in the test's clone of the local context, grabbed above
           token: p/var: /session/token  # from the Bob context, because of use-session Bob.

  - description: bad token
     interaction:
     -  request:
           use-session: Alice 
           action: update
           page: p/var: title            # from the local context, defined in the  variables stanza
           token: p/var: Bob/token       # from the Bob context. Doesn't match the session
        response:
           status: 403

Event Timeline

daniel renamed this task from Phester: bind variables to sessions to Phester: bind variables to session context.Jul 24 2019, 12:53 PM
daniel updated the task description. (Show Details)
daniel updated the task description. (Show Details)Jul 24 2019, 1:14 PM
Restricted Application added a subscriber: Liuxinyu970226. · View Herald TranscriptJul 24 2019, 1:15 PM
daniel updated the task description. (Show Details)Jul 24 2019, 1:16 PM
daniel updated the task description. (Show Details)Jul 24 2019, 1:27 PM
CCicalese_WMF closed this task as Invalid.Aug 12 2019, 6:39 PM
CCicalese_WMF added a subscriber: CCicalese_WMF.

We will not be building Phester.

Restricted Application removed a subscriber: Liuxinyu970226. · View Herald TranscriptAug 12 2019, 6:39 PM