-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split oscar.test.newfactories in multiple modules
Create a factory module per app and move them under the new oscar.test.factories module.
- Loading branch information
1 parent
8c32aaf
commit 0c02ff5
Showing
22 changed files
with
567 additions
and
478 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
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,33 @@ | ||
import factory | ||
|
||
from oscar.core.phonenumber import PhoneNumber | ||
from oscar.core.loading import get_model | ||
|
||
__all__ = [ | ||
'CountryFactory', 'UserAddressFactory', | ||
] | ||
|
||
|
||
class CountryFactory(factory.DjangoModelFactory): | ||
iso_3166_1_a2 = 'GB' | ||
name = "UNITED KINGDOM" | ||
|
||
class Meta: | ||
model = get_model('address', 'Country') | ||
django_get_or_create = ('iso_3166_1_a2',) | ||
|
||
|
||
class UserAddressFactory(factory.DjangoModelFactory): | ||
title = "Dr" | ||
first_name = "Barry" | ||
last_name = 'Barrington' | ||
line1 = "1 King Road" | ||
line4 = "London" | ||
postcode = "SW1 9RE" | ||
phone_number = PhoneNumber.from_string('+49 351 3296645') | ||
country = factory.SubFactory(CountryFactory) | ||
user = factory.SubFactory( | ||
'oscar.test.factories.UserFactory') | ||
|
||
class Meta: | ||
model = get_model('address', 'UserAddress') |
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,28 @@ | ||
import factory | ||
|
||
from oscar.core.loading import get_model, get_class | ||
|
||
Selector = get_class('partner.strategy', 'Selector') | ||
|
||
|
||
__all__ = [ | ||
'BasketFactory', 'BasketLineAttributeFactory' | ||
] | ||
|
||
|
||
class BasketFactory(factory.DjangoModelFactory): | ||
|
||
@factory.post_generation | ||
def set_strategy(self, create, extracted, **kwargs): | ||
# Load default strategy (without a user/request) | ||
self.strategy = Selector().strategy() | ||
|
||
class Meta: | ||
model = get_model('basket', 'Basket') | ||
|
||
|
||
class BasketLineAttributeFactory(factory.DjangoModelFactory): | ||
option = factory.SubFactory('oscar.test.factories.OptionFactory') | ||
|
||
class Meta: | ||
model = get_model('basket', 'LineAttribute') |
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,106 @@ | ||
# coding=utf-8 | ||
import factory | ||
|
||
from oscar.core.loading import get_model | ||
|
||
__all__ = [ | ||
'ProductClassFactory', 'ProductFactory', | ||
'CategoryFactory', 'ProductCategoryFactory', | ||
'ProductAttributeFactory', 'AttributeOptionGroupFactory', | ||
'OptionFactory', 'AttributeOptionFactory', | ||
'ProductAttributeValueFactory', 'ProductReviewFactory', | ||
] | ||
|
||
|
||
class ProductClassFactory(factory.DjangoModelFactory): | ||
name = "Books" | ||
requires_shipping = True | ||
track_stock = True | ||
|
||
class Meta: | ||
model = get_model('catalogue', 'ProductClass') | ||
|
||
|
||
class ProductFactory(factory.DjangoModelFactory): | ||
class Meta: | ||
model = get_model('catalogue', 'Product') | ||
|
||
structure = Meta.model.STANDALONE | ||
upc = factory.Sequence(lambda n: '978080213020%d' % n) | ||
title = "A confederacy of dunces" | ||
product_class = factory.SubFactory(ProductClassFactory) | ||
|
||
stockrecords = factory.RelatedFactory( | ||
'oscar.test.factories.StockRecordFactory', 'product') | ||
categories = factory.RelatedFactory( | ||
'oscar.test.factories.ProductCategoryFactory', 'product') | ||
|
||
|
||
class CategoryFactory(factory.DjangoModelFactory): | ||
name = factory.Sequence(lambda n: 'Category %d' % n) | ||
|
||
# Very naive handling of treebeard node fields. Works though! | ||
depth = 1 | ||
path = factory.Sequence(lambda n: '%04d' % n) | ||
|
||
class Meta: | ||
model = get_model('catalogue', 'Category') | ||
|
||
|
||
class ProductCategoryFactory(factory.DjangoModelFactory): | ||
category = factory.SubFactory(CategoryFactory) | ||
|
||
class Meta: | ||
model = get_model('catalogue', 'ProductCategory') | ||
|
||
|
||
class ProductAttributeFactory(factory.DjangoModelFactory): | ||
code = name = 'weight' | ||
product_class = factory.SubFactory(ProductClassFactory) | ||
type = "float" | ||
|
||
class Meta: | ||
model = get_model('catalogue', 'ProductAttribute') | ||
|
||
|
||
class OptionFactory(factory.DjangoModelFactory): | ||
class Meta: | ||
model = get_model('catalogue', 'Option') | ||
|
||
name = 'example option' | ||
code = 'example' | ||
type = Meta.model.OPTIONAL | ||
|
||
|
||
class AttributeOptionFactory(factory.DjangoModelFactory): | ||
# Ideally we'd get_or_create a AttributeOptionGroup here, but I'm not | ||
# aware of how to not create a unique option group for each call of the | ||
# factory | ||
|
||
option = factory.Sequence(lambda n: 'Option %d' % n) | ||
|
||
class Meta: | ||
model = get_model('catalogue', 'AttributeOption') | ||
|
||
|
||
class AttributeOptionGroupFactory(factory.DjangoModelFactory): | ||
name = u'Grüppchen' | ||
|
||
class Meta: | ||
model = get_model('catalogue', 'AttributeOptionGroup') | ||
|
||
|
||
class ProductAttributeValueFactory(factory.DjangoModelFactory): | ||
attribute = factory.SubFactory(ProductAttributeFactory) | ||
product = factory.SubFactory(ProductFactory) | ||
|
||
class Meta: | ||
model = get_model('catalogue', 'ProductAttributeValue') | ||
|
||
|
||
class ProductReviewFactory(factory.DjangoModelFactory): | ||
score = 5 | ||
product = factory.SubFactory(ProductFactory, stockrecords=[]) | ||
|
||
class Meta: | ||
model = get_model('reviews', 'ProductReview') |
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,14 @@ | ||
import factory | ||
|
||
from django.contrib.auth import models as auth_models | ||
|
||
__all__ = ['PermissionFactory'] | ||
|
||
|
||
class PermissionFactory(factory.DjangoModelFactory): | ||
name = 'Dummy permission' | ||
codename = 'dummy' | ||
|
||
class Meta: | ||
model = auth_models.Permission | ||
django_get_or_create = ('content_type', 'codename') |
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,19 @@ | ||
import factory | ||
|
||
from oscar.core.compat import get_user_model | ||
|
||
__all__ = ['UserFactory'] | ||
|
||
|
||
class UserFactory(factory.DjangoModelFactory): | ||
username = factory.Sequence(lambda n: 'the_j_meister nummer %d' % n) | ||
email = factory.Sequence(lambda n: 'example_%s@example.com' % n) | ||
first_name = 'joseph' | ||
last_name = 'winterbottom' | ||
password = factory.PostGenerationMethodCall('set_password', 'skelebrain') | ||
is_active = True | ||
is_superuser = False | ||
is_staff = False | ||
|
||
class Meta: | ||
model = get_user_model() |
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,54 @@ | ||
import factory | ||
|
||
from oscar.core.loading import get_model | ||
|
||
|
||
__all__ = [ | ||
'RangeFactory', 'ConditionFactory', 'BenefitFactory', | ||
'ConditionalOfferFactory', | ||
] | ||
|
||
|
||
class RangeFactory(factory.DjangoModelFactory): | ||
name = factory.Sequence(lambda n: 'Range %d' % n) | ||
slug = factory.Sequence(lambda n: 'range-%d' % n) | ||
|
||
class Meta: | ||
model = get_model('offer', 'Range') | ||
|
||
@factory.post_generation | ||
def products(self, create, extracted, **kwargs): | ||
if not create or not extracted: | ||
return | ||
|
||
RangeProduct = get_model('offer', 'RangeProduct') | ||
|
||
for product in extracted: | ||
RangeProduct.objects.create(product=product, range=self) | ||
|
||
|
||
class BenefitFactory(factory.DjangoModelFactory): | ||
type = get_model('offer', 'Benefit').PERCENTAGE | ||
value = 10 | ||
max_affected_items = None | ||
range = factory.SubFactory(RangeFactory) | ||
|
||
class Meta: | ||
model = get_model('offer', 'Benefit') | ||
|
||
|
||
class ConditionFactory(factory.DjangoModelFactory): | ||
type = get_model('offer', 'Condition').COUNT | ||
value = 10 | ||
|
||
class Meta: | ||
model = get_model('offer', 'Condition') | ||
|
||
|
||
class ConditionalOfferFactory(factory.DjangoModelFactory): | ||
name = 'Test offer' | ||
benefit = factory.SubFactory(BenefitFactory) | ||
condition = factory.SubFactory(ConditionFactory) | ||
|
||
class Meta: | ||
model = get_model('offer', 'ConditionalOffer') |
Oops, something went wrong.