-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from openedx/pwnage101/ENT-6836
feat: Add test factories
- Loading branch information
Showing
4 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
""" | ||
A library that records transactions against a ledger, denominated in units of value. | ||
""" | ||
__version__ = "0.1.3" | ||
__version__ = "0.1.4" | ||
|
||
default_app_config = "openedx_ledger.apps.EdxLedgerConfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Test factories for openedx-ledger models. | ||
""" | ||
from uuid import uuid4 | ||
|
||
import factory | ||
|
||
from openedx_ledger.models import Ledger, Transaction, UnitChoices | ||
|
||
|
||
class LedgerFactory(factory.django.DjangoModelFactory): | ||
""" | ||
Test factory for the `Ledger` model. | ||
By default, no transactions are created for this test Ledger. | ||
""" | ||
class Meta: | ||
model = Ledger | ||
|
||
uuid = factory.LazyFunction(uuid4) | ||
idempotency_key = factory.Faker("lexify", text="subsidy-????") | ||
unit = UnitChoices.USD_CENTS | ||
|
||
|
||
class TransactionFactory(factory.django.DjangoModelFactory): | ||
""" | ||
Test factory for the `Transaction` model. | ||
""" | ||
class Meta: | ||
model = Transaction | ||
|
||
uuid = factory.LazyFunction(uuid4) | ||
idempotency_key = factory.Faker( | ||
"lexify", | ||
text=factory.LazyAttribute(lambda tx: f"{tx.ledger.idempotency_key}-{tx.quantity}-????"), | ||
) | ||
quantity = factory.Faker("random_int", min=-100000, max=-100) | ||
ledger = factory.Iterator(Ledger.objects.all()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters