Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 9, 2021 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/c1d50c3b5cabeef067d59bdf0b360e7e to your computer and use it in GitHub Desktop.
Save velotiotech/c1d50c3b5cabeef067d59bdf0b360e7e to your computer and use it in GitHub Desktop.
import pytest
from product.models import Category, Product, Retail
...
@pytest.fixture
def retailer_abc(db):
return Retail.objects.create(name="ABC")
@pytest.fixture
def retailers(db) -> list:
return []
@pytest.fixture(autouse=True)
def append_retailers(retailers, retailer_abc):
return retailers.append(retailer_abc)
@pytest.fixture
def product_one(db, category, retailers):
product = Product.objects.create(name="Book 1", category=category)
product.retails.set(retailers)
return product
def test_product_retailer(db, retailer_abc, product_one):
assert product_one.retails.filter(name=retailer_abc.name).exists()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment