Gino Factory
Project description
Install: pip install gino-factory
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
gino-factory-0.1.0.tar.gz
(7.7 kB
view hashes)
Built Distribution
Close
Hashes for gino_factory-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c85441eae215b5a1341557d69f97c05d58e43778aaec8070d406e70356d5166b |
|
MD5 | 4dcf35c54a8df39a292272ce62f3db73 |
|
BLAKE2b-256 | ef8dfc676fb3b2f05642cf28dbf89158ad6667fa55c5882880cb14cbc5fae717 |