Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
ProductFactoryを複数回実行に対応させた
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Jun 4, 2014
1 parent 2d24c80 commit cab92e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/kawaz/apps/products/tests/factories.py
Expand Up @@ -27,10 +27,10 @@ class CategoryFactory(factory.DjangoModelFactory):

class ProductFactory(factory.DjangoModelFactory):
FACTORY_FOR = Product
FACTORY_DJANGO_GET_OR_CREATE = ('slug',)
FACTORY_DJANGO_GET_OR_CREATE = ('title', 'slug',)

title = 'かわずたんアドベンチャー'
slug = 'kawaz-tan-adventure'
title = factory.sequence(lambda n: 'かわずたんアドベンチャー{}'.format(n))
slug = factory.sequence(lambda n: 'kawaz-tan-adventure-{}'.format(n))
advertisement_image = ('products/kawaz-tan-adventure/'
'advertisement_images/kawaztan.png')
thumbnail = 'products/kawaz-tan-adventure/thumbnails/kawaztan.png'
Expand Down Expand Up @@ -87,4 +87,3 @@ class ScreenshotFactory(factory.DjangoModelFactory):

image = 'products/kawaz-tan-adventure/screenshots/cute_kawaz_tan.png'
product = factory.SubFactory(ProductFactory)

10 changes: 9 additions & 1 deletion src/kawaz/apps/products/tests/test_models.py
Expand Up @@ -8,7 +8,6 @@
from .factories import ProductFactory
from .factories import URLReleaseFactory
from .factories import PackageReleaseFactory
from .factories import Screenshot


class PlatformModelTestCase(TestCase):
Expand All @@ -30,6 +29,15 @@ def test_str_returns_category_label(self):


class ProductModelTestCase(TestCase):
def test_product_factory_create_unique_product(self):
"""
ProductFactory が一意なプロダクトを返すか否か(Ref: issue#68)
"""
from ..models import Product
for i in range(5):
ProductFactory()
self.assertEqual(Product.objects.count(), 5)

def test_str_returns_product_title(self):
"""
str()関数はプロダクトのタイトルを返す
Expand Down

0 comments on commit cab92e8

Please sign in to comment.