A library for generating fake data and populating database tables.

Overview

Knockoff Factory

codecov Test PyPi Release Docker Build License Python Versions Docker Image Size Python Wheel

A library for generating mock data and creating database fixtures that can be used for unit testing.

Table of content

Installation

pip install knockoff

Changelog

See the changelog for a history of notable changes to knockoff.

Documentation

We are working on adding more documentation and examples!

Unit Tests

Prerequisites

  • docker
  • poetry (curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python)

Some of the unit tests depend on a database instance. Knockoff will create ephemeral databases within that instance and clean them up when tests have completed. By default it will attempt to connect to an existing instance at postgresql://postgres@localhost:5432/postgres and will create and destroy databases per test. This postgres location can be overridden with the KNOCKOFF_TEST_DB_URI environment variable.

If no external postgres instance is available for testing, but postgresql is installed, the TEST_USE_EXTERNAL_DB environment variable can be set to 0. The fixtures will then rely on the testing.postgresql library to create ephemeral postgres instances per fixture.

If postgres is not available, dependent tests can be disabled with the following: export TEST_POSTGRES_ENABLED=0.

Create the database instance using docker:

docker run --rm  --name pg-docker -e POSTGRES_HOST_AUTH_METHOD=trust -d -p 5432:5432  postgres:11.9

Install poetry:

poetry install

Run unit test:

poetry run pytest

Future work

  • Further documentation and examples for SDK
  • Add yaml based configuration for SDK
  • Make extensible generic output for KnockffDB.insert (csv, parquet, etc)
  • Enable append option for KnockoffDB.insert
  • Autodiscover and populate all tables by using reflection and building dependency graph with foreign key relationships
  • Parallelize execution of dag. (e.g. https://ipython.org/ipython-doc/stable/parallel/dag_dependencies.html)
You might also like...
A Python Selenium library inspired by the Testing Library

Selenium Testing Library Slenium Testing Library (STL) is a Python library for Selenium inspired by Testing-Library. Dependencies Python 3.6, 3.7, 3.8

A command-line tool and Python library and Pytest plugin for automated testing of RESTful APIs, with a simple, concise and flexible YAML-based syntax

1.0 Release See here for details about breaking changes with the upcoming 1.0 release: https://github.com/taverntesting/tavern/issues/495 Easier API t

Test django schema and data migrations, including migrations' order and best practices.

django-test-migrations Features Allows to test django schema and data migrations Allows to test both forward and rollback migrations Allows to test th

Hypothesis is a powerful, flexible, and easy to use library for property-based testing.

Hypothesis Hypothesis is a family of testing libraries which let you write tests parametrized by a source of examples. A Hypothesis implementation the

Python version of the Playwright testing and automation library.

🎭 Playwright for Python Docs | API Playwright is a Python library to automate Chromium, Firefox and WebKit browsers with a single API. Playwright del

A library to make concurrent selenium tests that automatically download and setup webdrivers

AutoParaSelenium A library to make parallel selenium tests that automatically download and setup webdrivers Usage Installation pip install autoparasel

pytest plugin for manipulating test data directories and files

pytest-datadir pytest plugin for manipulating test data directories and files. Usage pytest-datadir will look up for a directory with the name of your

A mocking library for requests

httmock A mocking library for requests for Python 2.7 and 3.4+. Installation pip install httmock Or, if you are a Gentoo user: emerge dev-python/httm

A utility for mocking out the Python Requests library.

Responses A utility library for mocking out the requests Python library. Note Responses requires Python 2.7 or newer, and requests = 2.0 Installing p

Releases(v4.3.2)
  • v4.3.2(Aug 3, 2022)

    • Removed dependency on six which was required for py23 compatibility.
    • Updated dependency-injector version to resolve poetry lock issue with six <=1.15.0.

    Additional information about the changes can be found here.

    Source code(tar.gz)
    Source code(zip)
  • v4.3.1(Aug 3, 2022)

    Fixed backwards compatibility issue in KnockoffContainer with sqlalchemy breaking change for create_engine's positional arg changing into a kwarg, url. Fix KnockoffDB class so that it actually skips inserts where insert=False for a node Fix KnockoffTableFactory so that if you pass next_strategy_factory it won't complain about also providing next_strategy_callable

    Additional information about the changes can be found here.

    Source code(tar.gz)
    Source code(zip)
  • v4.3.0(Jul 27, 2021)

    • Added io utilities for parallelizing writes to sql with joblib
    • Added rename and drop parameters for KnockoffTable
    • Added support for MySQL to TempDatabaseService (knockoff.tempdb.setup_teardown:mysql_setup_teardown)
    • Added reflect_schema method to KnockoffDatabaseService
    • Moved knockoff.testing_postgresql modules to knockoff.utilities.testing.postgresql
    • Parallelized DefaultDatabaseService inserts
    • Renamed KnockoffTable.build_record method to KnockoffTable._build_record declaring it as private by convention
    • Fixed DefaultDatabaseService's reflect_table method for MySql

    Additional information about changes can be found here.

    Source code(tar.gz)
    Source code(zip)
  • v4.2.1(Jul 27, 2021)

    • Added default configurations for knockoff run CLI with environment variable override options
    • Moved clear_env_vars from knockoff.orm to knockoff.utilities.environ
    • Fixed issue where knockoff run CLI was not using the temp db created with the --ephemeral flag
    Source code(tar.gz)
    Source code(zip)
  • v4.2.0(Jul 19, 2021)

    • Add --ephemeral flag for knockoff run CLI to create temp database for loading knockoff configuration from sdk
    • Add unit tests for KnockoffDB.build and knockoff run CLI
    • Add Documentation and jupyter notebook for TempDatabaseService
    • Add Documentation and jupyter notebook for KnockoffDB
    • Moved legacy YAML based knockoff cli from README.md to legacy.MD
    Source code(tar.gz)
    Source code(zip)
  • v4.1.0(Jul 19, 2021)

  • v4.0.0(Jul 15, 2021)

    • Added ColumnFactory for providing factory functions instead of requiring as a tuple (column, factory)
    • Added build method for KnockoffDB to enable building dataframes without inserting into DB
    • Added run CLI command for loading data into database from sdk configuration
    • Added Blueprint class to sdk for more composable configuration
    • Added tempdb module and TempDatabaseService class
    • Made CLI extensible with injectable subcommands
    • Moved previous CLI to legacy subcommand for loading data into database using yaml configuration
    • Renamed knockoff.utilities.mixin:FactoryMixin to knockoff.utilities.mixin:ResourceLocatorMixin
    • Updated internal knockoff fixtures to use TempDatabaseService

    Additional changes can be found here.

    Source code(tar.gz)
    Source code(zip)
Owner
Nike Inc.
Nike Inc.
create custom test databases that are populated with fake data

About Generate fake but valid data filled databases for test purposes using most popular patterns(AFAIK). Current support is sqlite, mysql, postgresql

Emir Ozer 2.2k Jan 4, 2023
Faker is a Python package that generates fake data for you.

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in yo

Daniele Faraglia 15.2k Jan 1, 2023
FakeDataGen is a Full Valid Fake Data Generator.

FakeDataGen is a Full Valid Fake Data Generator. This tool helps you to create fake accounts (in Spanish format) with fully valid data. Within this in

Joel GM 64 Dec 12, 2022
Kent - Fake Sentry server for local development, debugging, and integration testing

Kent is a service for debugging and integration testing Sentry.

Will Kahn-Greene 100 Dec 15, 2022
Aioresponses is a helper for mock/fake web requests in python aiohttp package.

aioresponses Aioresponses is a helper to mock/fake web requests in python aiohttp package. For requests module there are a lot of packages that help u

null 402 Jan 6, 2023
Plugin for generating HTML reports for pytest results

pytest-html pytest-html is a plugin for pytest that generates a HTML report for test results. Resources Documentation Release Notes Issue Tracker Code

pytest-dev 548 Dec 28, 2022
Test for generating stylized circuit traces from images

I test of an image processing idea to take an image and make neat circuit board art automatically. Inspired by this twitter post by @JackRhysider

Miller Hooks 3 Dec 12, 2022
Automatic SQL injection and database takeover tool

sqlmap sqlmap is an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of

sqlmapproject 25.7k Jan 4, 2023
A pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database

This is a pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database. It allows you to specify fixtures for PostgreSQL process and client.

Clearcode 252 Dec 21, 2022
This is a pytest plugin, that enables you to test your code that relies on a running MongoDB database

This is a pytest plugin, that enables you to test your code that relies on a running MongoDB database. It allows you to specify fixtures for MongoDB process and client.

Clearcode 19 Oct 21, 2022