Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/update tooling #84

Merged
merged 25 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a7947e7
Install ruff, apply fixes
jams2 Aug 11, 2023
af3b626
Add flake8-pytest-style ruff rule and apply fixes
jams2 Aug 11, 2023
e6fd487
Remove psycopg2
jams2 Aug 11, 2023
954636c
Drop Python 3.7
jams2 Aug 11, 2023
9b71a74
Rename README.rst -> README.md
jams2 Aug 11, 2023
9ec797f
Convert README to markdown
jams2 Aug 11, 2023
4a9249e
Bump ruff and update config
jams2 Feb 15, 2024
ba5d412
Apply ruff fixes and formatting
jams2 Feb 15, 2024
3cdc8d0
Use extend-select in ruff conf
jams2 Feb 18, 2024
681b7a6
Support Wagtail 5.1, drop Python 3.7
lparsons396 Oct 4, 2023
142ff33
Streamline testing matrix
lparsons396 Oct 4, 2023
233da41
Streamline testing matrix 2
lparsons396 Oct 4, 2023
f413260
Add Wagtail 5.2 to test matrix, Drop tests for Wagtail 4.2 and 5.0 as…
katdom13 Nov 16, 2023
df1f7d9
Update workflow to use tox-gh-actions
katdom13 Nov 16, 2023
9b6673a
Set STATIC_URL
katdom13 Nov 16, 2023
bef9aa9
Add a newline to tests/settings.py
katdom13 Nov 17, 2023
9ff068a
Drop wagtail<5.2,django<4.2, add wagtail6.0, django 5.0
jams2 Feb 18, 2024
3f84eb3
Add py3.12 to github actions, remove postgres service
jams2 Feb 18, 2024
2b99216
Update changelog
jams2 Feb 18, 2024
ab64809
Use better dummy secret key
jams2 Feb 18, 2024
68b0524
Reformat docs conf
jams2 Feb 18, 2024
3cc0114
Change tox basepython to 3.11
jams2 Feb 18, 2024
247a339
Change ruff entrypoint in tox conf
jams2 Feb 18, 2024
38893d3
Remove assertions from source modules
jams2 Feb 18, 2024
05c94cc
Only ignore "S101 - use of assert" in tests
jams2 Feb 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 6 additions & 43 deletions .github/workflows/python-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,20 @@ on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
services:
jams2 marked this conversation as resolved.
Show resolved Hide resolved
postgres:
image: postgres
env:
POSTGRES_PASSWORD: secret
POSTGRES_USER: wagtail_factories
POSTGRES_DB: wagtail_factories
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

strategy:
max-parallel: 4
matrix:
python-version:
- {version: 3.7, tox: 37}
- {version: 3.8, tox: 38}
- {version: 3.9, tox: 39}
- {version: '3.10', tox: 310}
- {version: '3.11', tox: 311}
django: [32, 40, 41]
wagtail: [41, 42, 50]
factoryboy: [32]
exclude:
- python-version: {version: 3.7, tox: 37}
django: 40
- python-version: {version: 3.7, tox: 37}
django: 41
- python-version: {version: '3.11', tox: 311}
django: 40
- python-version: {version: '3.11', tox: 311}
django: 32
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version.version }}
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip tox
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
env:
TEST_DB_NAME: wagtail_factories
TEST_DB_USER: wagtail_factories
TEST_DB_PASSWORD: secret
TOX_ENV: "py${{ matrix.python-version.tox }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}-factoryboy${{ matrix.factoryboy }}"
run: |
tox -e $TOX_ENV
run: tox
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Unreleased
==========
- Update for Wagtail >5.1
- Drop support for Django <4.2
jams2 marked this conversation as resolved.
Show resolved Hide resolved
- Drop support for Wagtail <5.2
- Add support for Django 5
- Add support for Wagtail 6
- Add support for Python 3.12

4.1.0
=====
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ recursive-exclude * *

graft src/wagtail_factories

include README.rst
include README.md
jams2 marked this conversation as resolved.
Show resolved Hide resolved
include CHANGES
include setup.py

Expand Down
180 changes: 180 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# wagtail-factories


Factory boy classes for Wagtail CMS

## Status

[![image](https://readthedocs.org/projects/wagtail-factories/badge/?version=latest)](https://readthedocs.org/projects/wagtail-factories/)
[![image](https://github.com/wagtail/wagtail-factories/workflows/Python%20Tests/badge.svg)](https://github.com/wagtail/wagtail-factories/actions?query=workflow%3A%22Python+Tests%22)
[![image](https://img.shields.io/pypi/v/wagtail-factories.svg)](https://pypi.python.org/pypi/wagtail-factories/)

## Installation

``` shell
pip install wagtail-factories
```

## Usage

Documentation is still in progress, but see the
[tests](https://github.com/wagtail/wagtail-factories/tree/main/tests)
for more examples.

``` python
import wagtail_factories
from . import models


class MyCarouselItemFactory(wagtail_factories.StructBlockFactory):
label = 'my-label'
image = factory.SubFactory(
wagtail_factories.ImageChooserBlockFactory)

class Meta:
model = models.MyBlockItem


class MyCarouselFactory(wagtail_factories.StructBlockFactory):
title = "Carousel title"
items = wagtail_factories.ListBlockFactory(
MyCarouselItemFactory)

class Meta:
model = models.MyCarousel


class MyNewsPageFactory(wagtail_factories.PageFactory):
class Meta:
model = models.MyNewsPage


class MyNewsPageChooserBlockFactory(wagtail_factories.PageChooserBlockFactory):
page = factory.SubFactory(MyNewsPageFactory)


class MyTestPageFactory(wagtail_factories.PageFactory):
body = wagtail_factories.StreamFieldFactory({
'carousel': factory.SubFactory(MyCarouselFactory),
'news_page': factory.SubFactory(MyNewsPageChooserBlockFactory),
})

class Meta:
model = models.MyTestPage


def test_my_page():
root_page = wagtail_factories.PageFactory(parent=None)
my_page = MyTestPageFactory(
parent=root_page,
body__0__carousel__items__0__label='Slide 1',
body__0__carousel__items__0__image__image__title='Image Slide 1',
body__0__carousel__items__1__label='Slide 2',
body__0__carousel__items__1__image__image__title='Image Slide 2',
body__0__carousel__items__2__label='Slide 3',
body__0__carousel__items__2__image__image__title='Image Slide 3',
body__1__news_page__page__title="News",
)
```

### Using StreamBlockFactory

`StreamBlockFactory` can be used in conjunction with the other block
factory types to create complex, nested `StreamValues`, much like how
`StreamBlock` can be used to declare the blocks for a complex
`StreamField`.

First, define your `StreamBlockFactory` subclass, using
`factory.SubFactory` to wrap child block declarations. Be sure to
include your `StreamBlock` subclass as the model attribute on the inner
`Meta` class.

``` python
class MyStreamBlockFactory(wagtail_factories.StreamBlockFactory):
my_struct_block = factory.SubFactory(MyStructBlockFactory)

class Meta:
model = MyStreamBlock
```

Then include your `StreamBlockFactory` subclass on a model factory as
the argument to a `StreamFieldFactory`.

``` python
class MyPageFactory(wagtail_factories.PageFactory):
body = wagtail_factories.StreamFieldFactory(MyStreamBlockFactory)

class Meta:
model = MyPage
```

You can then use a modified version of factory\_boy\'s deep object
declaration syntax to build up `StreamValues` on the fly.

``` python
MyPageFactory(
body__0__my_struct_block__some_field="some value",
body__0__my_struct_block__some_other_field="some other value",
)
```

To generate the default value for a block factory, terminate your
declaration at the index and provide the block name as the value.

``` python
MyPageFactory(body__0="my_struct_block")
```

### Alternative StreamFieldFactory declaration syntax

Prior to version 3.0, `StreamFieldFactory` could only be used by
providing a dict mapping block names to block factory classes as the
single argument, for example:

``` python
class MyTestPageWithStreamFieldFactory(wagtail_factories.PageFactory):
body = wagtail_factories.StreamFieldFactory(
{
"char_array": wagtail_factories.ListBlockFactory(
wagtail_factories.CharBlockFactory
),
"int_array": wagtail_factories.ListBlockFactory(
wagtail_factories.IntegerBlockFactory
),
"struct": MyBlockFactory,
"image": wagtail_factories.ImageChooserBlockFactory,
}
)

class Meta:
model = models.MyTestPage
```

This style of declaration is still supported, with the caveat that
nested stream blocks are not supported for this approach. From version
3.0, all `BlockFactory` values in a `StreamFieldFactory` definition of
this style *must* be wrapped in factory\_boy `SubFactories`. For
example, the above example must be updated to the following for 3.0
compatibility.

``` python
class MyTestPageWithStreamFieldFactory(wagtail_factories.PageFactory):
body = wagtail_factories.StreamFieldFactory(
{
"char_array": wagtail_factories.ListBlockFactory(
wagtail_factories.CharBlockFactory
),
"int_array": wagtail_factories.ListBlockFactory(
wagtail_factories.IntegerBlockFactory
),
"struct": factory.SubFactory(MyBlockFactory),
"image": factory.SubFactory(wagtail_factories.ImageChooserBlockFactory),
}
)

class Meta:
model = models.MyTestPage
```

This requirement does *not* apply to `ListBlockFactory`, which is a
subclass of `SubFactory`.
Loading
Loading