Skip to main content

Factories that create fixtures

Project description

Overview

Facture is FAC-tories that generate partition-isolated fix-TURE data, ideal for elaborating scenarios.

Installation

pip install facturedata

How is this different from factories and fixtures?

Originally this tool was created to generate the test data for a database that had very high overhead per-insert. Using traditional data factories and individual transactions with rollback would not work; batching the inserts was necessary.

Fixtures alone could solve this problem, but it’s really hard to enumerate and manage the joins in a large number of scenarios in fixtures effectively. The primary advantage that factories have is their ease of use in testing individual scenarios without needing to understand other scenarios or manage a corpus of shared data. Carefully paritioning inserted data so the data is unambiguously owned by a scenario can provide the same benefit as factories, where it becomes easy to understand the data associated with individual scenarios.

How to Use

There is a fair amount of configuration that goes into setting facture up, but here is a quick inline example data group that shows how foreign keys work:

'group': 'facture_group_shawshank_redemption',
'offset': 100,
'data': [
    ['actors a_mf', {'attrs': {'first_name': 'Morgan', 'last_name': 'Freeman'}}],
    ['actors a_tr', {'attrs': {'first_name': 'Tim', 'last_name': 'Robbins'}}],
    ['films f', {'attrs': {'name': 'Shawshank Redemption', 'year': '1994'}}],
    ['roles r1', {'refs': {'actor_id': '.a_mf.id', 'film_id': '.f.id'}}],
    ['roles r1', {'refs': {'actor_id': '.a_tr.id', 'film_id': '.f.id'}}]
]

For a deeper dive I recommend that you look at this example: https://github.com/gmccreight/facture/tree/master/tests/examples/sql_inject_target

Copy the factureconf.py there to the directory you will be running facture in. Look at the facture_json target section in the original.sql file and copy it into a file of your own choosing. Update the conf_targets section of your newly created factureconf.py file to point to the file where you put the facture_json.

Run:

facture

Your target file should now be filled in with some generated data. You’re off to the races!

Additional benefits

  • “compile”-time factory configuration consistency checks. Checks for many typos, join issues, etc.

  • Materializes the output into your version-controlled files, unrolling the complexity. Because the fixtures that we generate are automatically created, we can put a lot of effort into making the generated data comprehensible (and lineage-providing). This means we annotate all generated data with the column names, and the scenario name. It’s also extremely easy to see what the effects of any change you make is, since it’s all laid out for you.

  • Code as configuration. The configuration files are written in Python, so you have the full power of the language.

  • Easy to reason about each scenario in complete isolation because of data partitioning

  • Plays well with others… can be introduced into existing fixtures. Integrates with how you do things, doesn’t try to take over completely. Can target files or sections within files.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

facturedata-0.2.02.tar.gz (9.2 kB view details)

Uploaded Source

File details

Details for the file facturedata-0.2.02.tar.gz.

File metadata

  • Download URL: facturedata-0.2.02.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0

File hashes

Hashes for facturedata-0.2.02.tar.gz
Algorithm Hash digest
SHA256 b11c2e6856d597bf83003606de17542b43a36b51909b912bfd728f6fef304840
MD5 50064029659793946d676ea5cf028f86
BLAKE2b-256 1bb638723eba2c01984364daa07d835b4a489db01033a2c6a22d14f574b70e38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page