OpenActive Developers
Data ValidatorDataset DashboardW3C Community Group
  • Welcome to our community
  • Publishing Data
    • Data Feeds
      • How an RPDE data feed works
      • Types of RDPE feed
      • Implementing RPDE
      • Testing RPDE feeds
      • Scaling RPDE feeds
    • Activity list references
    • Including geo coordinates
    • Schedules
    • Dataset Sites
    • Virtual Events
    • On-Demand Events
    • Opening Hours
    • Data Quality
  • Using data
    • Harvesting opportunity data
      • Large Integers in JavaScript
    • Tutorial: Consuming an RPDE feed
    • Attribution
  • Open Booking API
    • Key Decisions
    • Implementing booking
    • Testing booking
      • Configuring Test Suite
      • Implementing the Test Interface
        • Test Interface Actions
        • Create Opportunity Endpoint
      • Random Mode: Generating Test Opportunity Data
      • Running Test Suite
      • Generating the Conformance Certificate
  • Data Model
    • Data Model Overview
    • @context and JSON-LD
    • Types Reference
      • Action
      • AudioObject
      • BabyChanging
      • Barcode
      • BookingService
      • BooleanFormFieldSpecification
      • Brand
      • ChangingFacilities
      • ConceptScheme
      • Concept
      • CourseInstance
      • Course
      • Creche
      • CustomerAccount
      • DataCatalog
      • DataDownload
      • Dataset
      • DropdownFormFieldSpecification
      • DynamicPayment
      • Entitlement
      • EventSeries
      • Event
      • FacilityUse
      • FileUploadFormFieldSpecification
      • GeoCoordinates
      • HeadlineEvent
      • ImageObject
      • IndividualFacilityUse
      • InternalApplicationError
      • InternalLibraryConfigurationError
      • InternalLibraryError
      • Lease
      • LocationFeatureSpecification
      • Lockers
      • MediaObject
      • OfferOverride
      • Offer
      • OnDemandEvent
      • OpenBookingError
      • OpeningHoursSpecification
      • OrderItem
      • OrderProposal
      • OrderQuote
      • Order
      • Organization
      • ParagraphFormFieldSpecification
      • Parking
      • PartialSchedule
      • Payment
      • Person
      • Place
      • PostalAddress
      • PriceSpecification
      • PrivacyPolicy
      • PropertyValueSpecification
      • PropertyValue
      • QuantitativeValue
      • Schedule
      • ScheduledSession
      • SessionSeries
      • ShortAnswerFormFieldSpecification
      • Showers
      • Slot
      • SportsActivityLocation
      • TaxChargeSpecification
      • TermsOfUse
      • Terms
      • Toilets
      • Towels
      • VideoObject
      • VirtualLocation
      • WebAPI
  • Specifications
    • Specifications Overview
  • Useful links
    • Data Visualiser
    • Data Validator
    • Dataset Dashboard
    • Non-technical Guidance
  • OpenActive on GitHub
    • Overview
    • Activity List
    • Community
    • Controlled Vocabularies
    • Dataset Publication
    • Documentation
    • Implementation Support
    • Programmes
    • RPDE
    • SKOS
    • Specifications
    • Validators
Powered by GitBook
On this page
  • Test Data Generator
  • Example
Edit on GitHub
  1. Open Booking API
  2. Testing booking

Random Mode: Generating Test Opportunity Data

PreviousCreate Opportunity EndpointNextRunning Test Suite

Last updated 1 year ago

This page is only for those who are using to test their booking systems. If instead using , you don't need to worry about manually generating data, as Test Suite will automatically do this by calling your booking system's .

In , Test Suite requires test opportunity data to already exist, which it will use to run tests.

Running Test Suite will cause test opportunities to be booked, and therefore to eventually not be available to subsequent Test Suite runs. And so, this test opportunity data will, at least sometimes, need to be re-generated between Test Suite runs.

You may already have some process for generating random test opportunity data in your booking system (for example, copying data from a live environment snapshot, with personally identifiable information removed) and this may suffice for simple cases. However, the recommended approach is to create a script that populates your dataset with the exact required test opportunity data based on your . This ensures that you never waste debugging time on test runs that fail due to insufficient data. And it means that your testing solution will be sufficiently stable to run automatically in CI.

Test Data Generator

Use to find out exactly how much test opportunity data needs to be in your booking system in order to run a given set of tests. The README in that project details how you can use this script to generate a test-opportunity-data.json file.

You can then create a custom script to populate your dataset using, as input, the test-opportunity-data.json file.

Example

This example should give you an idea as to how to write a custom script to populate your dataset. In this example, one of the .itemListElement items in your test-opportunity-data.json file looks like this:

{
  "@type": "ListItem",
  "item": {
    "@type": "Slot",
    "facilityUse": {
      "@type": "IndividualFacilityUse",
      "provider": {
        "@type": "Organization",
        "@id": "https://id.booking-system.example.com/organizer/3"
      }
    },
    "test:testOpportunityCriteria": "https://openactive.io/test-interface#TestOpportunityBookable",
    "test:testOpenBookingFlow": "https://openactive.io/test-interface#OpenBookingSimpleFlow",
  },
  "test:numberOfInstancesInDistribution": 32
}

When your script comes to process this item, it should consider the following:

  • How many to generate: Find this in .['test:numberOfInstancesInDistribution']. For this item, the value is 32, so the script should generate (at least) 32 opportunities that fit these constraints.

It is strongly recommended to incorporate an element of diversity into your test opportunity data, to provide a greater testing surface area. For example, this could be done by using random data for some of your fields and randomly deciding whether to include certain fields e.g. image if images are optional in your dataset.

What type of opportunity to generate: for this item, s that belong to s should be generated (note that the IndividualFacilityUses — and the s that they belong to — can either be generated new or can already exist if they satisfy the other constraints).

Seller: Which should the generated opportunities be created within. This will either be specified in .item.facilityUse.provider (for a Slot) or .item.superEvent.organizer (for a ). For this item, the Slots (and their parent IndividualFacilityUses and FacilityUses) should be created within the Seller with ID https://id.booking-system.example.com/organizer/3.

Test Data Generator will only use .

Booking Flow: Which the generated opportunities should support. Find this in item['test:testOpenBookingFlow']. For this item, the value is https://openactive.io/test-interface#OpenBookingSimpleFlow, which means that the generated opportunities need to support the .

Opportunity Criteria: The criteria constrains the properties of the generated opportunities. Find this in item['test:testOpportunityCriteria']. For this item, the value is https://openactive.io/test-interface#TestOpportunityBookable, whose description can be found in the Test Interface docs .

Slot
IndividualFacilityUse
FacilityUse
seller
ScheduledSession
booking flow
Simple Booking Flow
here
Create Opportunity Endpoint
Test Data Generator
Random Mode
Controlled Mode
Random Mode
implemented features
Sellers that you have already described in your Test Suite configuration