Gino Factory
Project description
Github: https://github.com/Basalex/gino_factory
Usage:
Let’s create two gino models
class Team(db.Model):
__tablename__ = 'teams'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255))
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
parent_id = db.Column(sa.Integer, sa.ForeignKey(f'users.id', name='parent_id_fkey'))
username = db.Column(db.String(255), nullable=False, unique=True)
custom_field = db.Column(db.String(255), nullable=False, unique=True)
custom_factory = db.Column(db.String(255), nullable=False, unique=True)
Next you need to register this model
from gino_factory import GinoFactory
class Factory(GinoFactory):
pass
Factory.register(Team)
Factory.register(User, custom_field='value', custom_factory=function)
Single objects
async def test():
user = await Factory.user()
assert user.team_id is not None
team = await Factory.test()
user = await Factory.user(team_id=team)
assert team.id == user.team_id
Iterator objects
from itertools import cycle
async def test():
teams = await Factory.cycle(10).team()
users = await Factory.cycle(10).user(team_id=iter(teams))
assert users[-1].team_id == teams[-1].id
teams = await Factory.cycle(3).team() # id: 1,2,3
users = await Factory.cycle(10).user(team_id=cycle(teams))
assert [u.team_id for u in users] == [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
Trees
- Tree attributes:
amount: int = 50 - maximum amount of total members
max_depth: int = 5 - maximum tree depth
top_parents_amount: int = 3 - Amount of “top” parents (parent_id=None)
top_parents: CRUDModel = None - Pre-generated top-parents
parent_field_name: str = ‘parent_id’ - Name of parent field
Following code generates single head tree with max depth of 3
async def test():
users = await Factory.tree(amount=100, max_depth=3, top_parents_amount=1).user()
or you may fill your database with random data using __random__ method
await Factory.__random__()
This method inserts random data to all registered tables
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gino-factory-0.1.0.tar.gz
.
File metadata
- Download URL: gino-factory-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7b388893826bdb15ba85f07372e6247dfecb3935a4d2cd5fceaad594c527af8 |
|
MD5 | b856645bddd8d636d7cf2670b5e0017d |
|
BLAKE2b-256 | 962f04f80fe94712adb15ab80c62074bc36ec1bff7567dbe39634f0773b11432 |
File details
Details for the file gino_factory-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: gino_factory-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c85441eae215b5a1341557d69f97c05d58e43778aaec8070d406e70356d5166b |
|
MD5 | 4dcf35c54a8df39a292272ce62f3db73 |
|
BLAKE2b-256 | ef8dfc676fb3b2f05642cf28dbf89158ad6667fa55c5882880cb14cbc5fae717 |