tortoise-factory


Nametortoise-factory JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryPopulate Tortoise Model with faker output in a factory for tests
upload_time2024-09-09 16:15:21
maintainerNone
docs_urlNone
authorSebastien Nicolet
requires_python<4.0,>=3.11
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Usage
```python
from tortoise import Model, fields
from tortoise_factory import model_factory


class User(Model):
    id = fields.IntField(primary_key=True)
    first_name = fields.CharField(max_length=100)
    last_name = fields.CharField(max_length=100)
    email = fields.CharField(max_length=200)


class Product(Model):
    id = fields.IntField(primary_key=True)
    name = fields.CharField(max_length=200)
    description = fields.TextField(null=True, default=None)
    price = fields.FloatField()
    created_by = fields.ForeignKeyField(
        "models.User",
        on_delete=fields.CASCADE,
        related_name="products",
    )

    def __str__(self) -> str:
        return self.name
```
## Generalities
All returned models are saved in db, meaning they will all have a `.id` value, the same is true for any ForeignKeyField


## Random values
To get a simple random product:
```python
product = await model_factory(Product)
```
the `created_by` will be created automaticaly since it cannot be None, when possible, the factory will put None into optional fields.


## Specify some fields
```python
product = await model_factory(Product, name="something", created_by__name="Bob")
```
we use `__` to go throught relations


## Fill optional values
```python
product = await model_factory(Product, _optionals=["description"])
```

now you will have a `product.description` wich won't be `None`


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tortoise-factory",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": "Sebastien Nicolet",
    "author_email": "snicolet95@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8b/ee/dba834b5fc25c2fb7f94c9674a9594673b029bc8dbdf1b85ffc95f3a71d8/tortoise_factory-0.1.0.tar.gz",
    "platform": null,
    "description": "# Usage\n```python\nfrom tortoise import Model, fields\nfrom tortoise_factory import model_factory\n\n\nclass User(Model):\n    id = fields.IntField(primary_key=True)\n    first_name = fields.CharField(max_length=100)\n    last_name = fields.CharField(max_length=100)\n    email = fields.CharField(max_length=200)\n\n\nclass Product(Model):\n    id = fields.IntField(primary_key=True)\n    name = fields.CharField(max_length=200)\n    description = fields.TextField(null=True, default=None)\n    price = fields.FloatField()\n    created_by = fields.ForeignKeyField(\n        \"models.User\",\n        on_delete=fields.CASCADE,\n        related_name=\"products\",\n    )\n\n    def __str__(self) -> str:\n        return self.name\n```\n## Generalities\nAll returned models are saved in db, meaning they will all have a `.id` value, the same is true for any ForeignKeyField\n\n\n## Random values\nTo get a simple random product:\n```python\nproduct = await model_factory(Product)\n```\nthe `created_by` will be created automaticaly since it cannot be None, when possible, the factory will put None into optional fields.\n\n\n## Specify some fields\n```python\nproduct = await model_factory(Product, name=\"something\", created_by__name=\"Bob\")\n```\nwe use `__` to go throught relations\n\n\n## Fill optional values\n```python\nproduct = await model_factory(Product, _optionals=[\"description\"])\n```\n\nnow you will have a `product.description` wich won't be `None`\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Populate Tortoise Model with faker output in a factory for tests",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6edfbdb5145086944dffc6e400926832474eed0b559c2fa8e2ba3efcd6f567bb",
                "md5": "0668328e4cf25027cef02476bdaef84e",
                "sha256": "21c9727b2ba83e905a9453f40dd9b20d79041cefadcfca7b0d234583c5f6eb94"
            },
            "downloads": -1,
            "filename": "tortoise_factory-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0668328e4cf25027cef02476bdaef84e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 4233,
            "upload_time": "2024-09-09T16:15:19",
            "upload_time_iso_8601": "2024-09-09T16:15:19.605723Z",
            "url": "https://files.pythonhosted.org/packages/6e/df/bdb5145086944dffc6e400926832474eed0b559c2fa8e2ba3efcd6f567bb/tortoise_factory-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8beedba834b5fc25c2fb7f94c9674a9594673b029bc8dbdf1b85ffc95f3a71d8",
                "md5": "a1aa387978c0db3eb1c325e6eb5e9179",
                "sha256": "b351f8b8d9d3e4727e91e26af697b1b963cf64b660d51d9838fa6bda9580c428"
            },
            "downloads": -1,
            "filename": "tortoise_factory-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a1aa387978c0db3eb1c325e6eb5e9179",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 3627,
            "upload_time": "2024-09-09T16:15:21",
            "upload_time_iso_8601": "2024-09-09T16:15:21.073061Z",
            "url": "https://files.pythonhosted.org/packages/8b/ee/dba834b5fc25c2fb7f94c9674a9594673b029bc8dbdf1b85ffc95f3a71d8/tortoise_factory-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-09 16:15:21",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "tortoise-factory"
}
        
Elapsed time: 0.31557s