项目作者: kpn

项目描述 :
Pyrandall is a test framework with a focus on Event Streaming and Stream Processors.
高级语言: Python
项目地址: git://github.com/kpn/pyrandall.git
创建时间: 2019-09-23T13:14:36Z
项目社区:https://github.com/kpn/pyrandall

开源协议:Apache License 2.0

下载


Build Status

PYRANDALL

Data simulation and validation framework that supports Behaviour-Driven Development (BDD)1. \
Pyrandall’ focus is to drive the development of streaming architectures and Event Sourcing2.

Running examples

  1. # setup a venv and start mocks to
  2. docker-compose up -d
  3. pip install flask
  4. python stubserver.py
  1. # Simulate events from examples/scenarios/v2.yaml and files found in examples/events
  2. ./examples/pyrandall simulate v2.yaml
  1. # Validate results from examples/scenarios/v2.yaml and files found in examples/results
  2. ./examples/pyrandall validate v2.yaml

Example of scenario/v2 schema

The input yaml is validated with jsonschema, the schema can be found here pyrandall/schemas/scenario/v2.yaml.

  1. ---
  2. version: scenario/v2
  3. feature:
  4. description: V2 schema example
  5. scenarios:
  6. - description: HTTP to an ingest API and key-value API
  7. simulate:
  8. adapter: requests/http
  9. requests:
  10. - path: /v1/actions/produce-event
  11. events:
  12. - words1.json
  13. - words2.json
  14. validate:
  15. adapter: requests/http
  16. requests:
  17. - path: /foo/bar/123
  18. assert_that_responded:
  19. status_code: { equals_to: 200 }
  20. body: { equals_to_event: expected_result.json }
  21. - description: Produce and Consumer to kafka
  22. simulate:
  23. adapter: broker/kafka
  24. messages:
  25. - topic: emails
  26. events:
  27. - email1.json
  28. validate:
  29. adapter: broker/kafka
  30. messages:
  31. - topic: email_results
  32. assert_that_received:
  33. timeout_after: "5m"
  34. total_events: { equals_to: 4 } # I observed in total 4 events
  35. unordered:
  36. - { equals_to_event: word_count.json }
  37. - topic: email_results
  38. assert_that_received:
  39. last_event: { equals_to_event: word_count.json }
  40. timeout_after: 5m

Features and Ideas

  • Runnable pyrandall command to execute a BDD style scenario spec in YAML.
  • Focus on developers experience when creating dataflows. Where the emphasis lies in creating the events.
  • Simulated “events” are read from template files. By default json is supported.
  • Possibility to overwrite or extend pyrandall default behaviors with pluggy, a plugin system developed and used by pytest.
  • See a complete example of pluggy: https://pluggy.readthedocs.io/en/latest/#a-complete-example

Pyrandall is run from within docker. Connections are often only accessible through deployment and \
containers are de facto today. It also enables us to add complex dependencies like librdkafka to \
use confluent-kafka which supports all api versions offered by Kafka.

For adding plugins, self signed certificates etc, it is encouraged to create your own Dockerfile:

  1. FROM kpnnv/pyrandall:latest
  2. # Install your plugins
  3. # COPY certificates etc

Concepts

  • A spec can consist of multiple simulate and validate steps which are executed over HTTP or Apache Kafka.
  • This could be expanded to brokers in general or websockets support.
  • Validate should execute assertions against the state of your application.

Documentation

Pyrandall always could use more documentation, and help is welcome see our CONTRIBUTING.md.
At this moment code and tests are the best we have. See the examples/ and the test/functional.
Also see CHANGELOG.md on what is fixed, changed or added.

License

  1. Copyright 2019 KPN N.V.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.

Footnotes

  1. BDD is a software development process and automated tests are an outcome of that: https://cucumber.io/docs/bdd/.
  2. Read more about Event Sourcing here: https://martinfowler.com/eaaDev/EventSourcing.html