本文整理汇总了Python中model_mommy.recipe.Recipe类的典型用法代码示例。如果您正苦于以下问题:Python Recipe类的具体用法?Python Recipe怎么用?Python Recipe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Recipe类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: AddressResponseTests
class AddressResponseTests(TestCase):
def setUp(self):
self.recipe = Recipe(
FormFieldResponse,
form_field__kind='address',
form_field__details={'required': True}
)
def test_should_pass_when_required_and_only_addr2_blank(self):
field_response = self.recipe.prepare(details={
'addressLine1': 'x', 'city': 'x', 'state': 'x', 'zip': 'x'
})
self.assertEqual(field_response.clean(), None)
def test_should_not_pass_when_required_and_any_field_but_addr2_blank(self):
field_response = self.recipe.prepare(details={
'addressLine1': '', 'city': 'x', 'state': 'x', 'zip': 'x'
})
self.assertRaises(ValidationError, field_response.clean)
def test_should_pass_when_not_required_and_all_fields_blank(self):
field_response = self.recipe.prepare()
field_response.form_field.details['required'] = False
self.assertEqual(field_response.clean(), None)
开发者ID:jsayres,项目名称:dynamic-forms-example,代码行数:25,代码来源:test_form_field_response.py
示例2: LongAnswerResponseTests
class LongAnswerResponseTests(TestCase):
def setUp(self):
self.recipe = Recipe(
FormFieldResponse,
form_field__kind='long-answer',
form_field__details={'required': True}
)
def test_should_pass_when_required_and_answer_not_blank(self):
field_response = self.recipe.prepare(details={'answer': 'ok'})
self.assertEqual(field_response.clean(), None)
def test_should_not_pass_when_required_and_answer_not_provided(self):
field_response = self.recipe.prepare(details={})
self.assertRaises(ValidationError, field_response.clean)
def test_should_not_pass_when_required_and_answer_blank(self):
field_response = self.recipe.prepare(details={'answer': ''})
self.assertRaises(ValidationError, field_response.clean)
def test_should_pass_when_not_required_and_answer_not_provided(self):
field_response = self.recipe.prepare(details={})
field_response.form_field.details['required'] = False
self.assertEqual(field_response.clean(), None)
def test_should_pass_when_not_required_and_answer_blank(self):
field_response = self.recipe.prepare(details={'answer': ''})
field_response.form_field.details['required'] = False
self.assertEqual(field_response.clean(), None)
开发者ID:jsayres,项目名称:dynamic-forms-example,代码行数:30,代码来源:test_form_field_response.py
示例3: test_always_calls_with_quantity
def test_always_calls_with_quantity(self):
with patch("test.generic.tests.test_recipes.choice") as choice_mock:
choice.return_value = "foo"
l = ["foo", "bar", "spam", "eggs"]
r = Recipe(DummyBlankFieldsModel, blank_char_field=lambda: choice(l))
r.make(_quantity=3)
self.assertEqual(choice_mock.call_count, 3)
开发者ID:berinhard,项目名称:model_mommy,代码行数:7,代码来源:test_recipes.py
示例4: test_always_calls_with_quantity
def test_always_calls_with_quantity(self):
with patch('test.generic.tests.test_recipes.choice') as choice_mock:
l = ['foo', 'bar', 'spam', 'eggs']
r = Recipe(DummyBlankFieldsModel,
blank_char_field = lambda: choice(l)
)
r.make(_quantity=3)
self.assertEqual(choice_mock.call_count, 3)
开发者ID:lucassimon,项目名称:model_mommy,代码行数:8,代码来源:test_recipes.py
示例5: test_defining_recipes_str
def test_defining_recipes_str(self):
from model_mommy.recipe import seq
p = Recipe("generic.Person", name=seq("foo"))
try:
p.make(_quantity=5)
except AttributeError as e:
self.fail("%s" % e)
开发者ID:berinhard,项目名称:model_mommy,代码行数:8,代码来源:test_recipes.py
示例6: leg_setup
def leg_setup(self):
self.survey_recipe = Recipe(models.Commutersurvey)
self.all_modes = models.Mode.objects.all()
self.leg_recipe = Recipe(
models.Leg,
checkin = self.survey_recipe.make(),
mode = cycle(self.all_modes)
)
开发者ID:greenstreetsinitiative,项目名称:checkin2015,代码行数:8,代码来源:tests.py
示例7: setUp
def setUp(self):
last_hour = datetime.now() - timedelta(hours=1)
# Next hour has 1 minute more because the delay between
# the creation of the event and the test execution
next_hour = datetime.now() + timedelta(minutes=61)
self.event_last_hour = Recipe(Event, ends=last_hour, published=True)
self.event_next_hour = Recipe(Event, ends=next_hour, published=True)
self.event_unpublished = Recipe(Event, ends=next_hour, published=False)
开发者ID:UFRB,项目名称:happening,代码行数:8,代码来源:test_views.py
示例8: test_defining_recipes_str
def test_defining_recipes_str(self):
from model_mommy.recipe import seq
p = Recipe('generic.Person',
name=seq('foo')
)
try:
p.make(_quantity=5)
except AttributeError, e:
self.fail('%s' %e)
开发者ID:kevinlondon,项目名称:model_mommy,代码行数:9,代码来源:test_recipes.py
示例9: test_prepare_recipe_with_foreign_key
def test_prepare_recipe_with_foreign_key(self):
person_recipe = Recipe(Person, name='John Doe')
dog_recipe = Recipe(Dog,
owner=foreign_key(person_recipe),
)
dog = dog_recipe.prepare()
self.assertIsNone(dog.id)
self.assertIsNone(dog.owner.id)
开发者ID:berinhard,项目名称:model_mommy,代码行数:9,代码来源:test_recipes.py
示例10: test_always_calls_when_creating
def test_always_calls_when_creating(self):
with patch('test.generic.tests.test_recipes.choice') as choice_mock:
choice.return_value = 'foo'
l = ['foo', 'bar', 'spam', 'eggs']
r = Recipe(DummyBlankFieldsModel,
blank_char_field = lambda: choice(l)
)
r.make().blank_char_field
r.make().blank_char_field
self.assertEqual(choice_mock.call_count, 2)
开发者ID:AspireFintech,项目名称:model_mommy,代码行数:10,代码来源:test_recipes.py
示例11: test_only_iterators_not_iteratables_are_iterated
def test_only_iterators_not_iteratables_are_iterated(self):
"""Ensure we only iterate explicit iterators.
Consider "iterable" vs "iterator":
Something like a string is "iterable", but not an "iterator". We don't
want to iterate "iterables", only explicit "iterators".
"""
r = Recipe(DummyBlankFieldsModel, blank_text_field="not an iterator, so don't iterate!")
self.assertEqual(r.make().blank_text_field, "not an iterator, so don't iterate!")
开发者ID:berinhard,项目名称:model_mommy,代码行数:11,代码来源:test_recipes.py
示例12: test_make_recipe_without_all_model_needed_data
def test_make_recipe_without_all_model_needed_data(self):
person_recipe = Recipe(Person, name="John Doe")
person = person_recipe.make()
self.assertEqual("John Doe", person.name)
self.assertTrue(person.nickname)
self.assertTrue(person.age)
self.assertTrue(person.bio)
self.assertTrue(person.birthday)
self.assertTrue(person.appointment)
self.assertTrue(person.blog)
self.assertTrue(person.wanted_games_qtd)
self.assertTrue(person.id)
开发者ID:berinhard,项目名称:model_mommy,代码行数:12,代码来源:test_recipes.py
示例13: test_prepare_recipe_without_all_model_needed_data
def test_prepare_recipe_without_all_model_needed_data(self):
person_recipe = Recipe(Person, name='John Doe')
person = person_recipe.prepare()
self.assertEqual('John Doe', person.name)
self.assertTrue(person.nickname)
self.assertTrue(person.age)
self.assertTrue(person.bio)
self.assertTrue(person.birthday)
self.assertTrue(person.appointment)
self.assertTrue(person.blog)
self.assertTrue(person.wanted_games_qtd)
self.assertFalse(person.id)
开发者ID:lucassimon,项目名称:model_mommy,代码行数:12,代码来源:test_recipes.py
示例14: test_do_query_lookup_empty_recipes
def test_do_query_lookup_empty_recipes(self):
"""
It should not attempt to create other object when
using query lookup syntax
"""
dog_recipe = Recipe(Dog)
dog = dog_recipe.make(owner__name='James')
self.assertEqual(Person.objects.count(), 1)
self.assertEqual(dog.owner.name, 'James')
dog = dog_recipe.prepare(owner__name='Zezin')
self.assertEqual(Person.objects.count(), 1)
self.assertEqual(dog.owner.name, 'Zezin')
开发者ID:lucassimon,项目名称:model_mommy,代码行数:13,代码来源:test_recipes.py
示例15: setUp
def setUp(self):
self.endereco_base = 'Rua Baronesa, 175'
self.cidade_base = 'Rio de Janeiro'
self.lat_base = -22.8950148
self.lng_base = -43.3542673
self.imovel = mommy.make(Imovel)
self.basic_imovel_recipe = Recipe(Imovel, latitude=None, longitude=None)
imoveis_recipe = Recipe(Imovel,
endereco=self.endereco_base,
cidade=self.cidade_base,
latitude=self.lat_base,
longitude=self.lng_base,
disponivel=cycle([False, True])
)
# Cria 9 imóveis alterando disponíveis e indisponíveis
imoveis_recipe.make(_quantity=9)
开发者ID:diegorocha,项目名称:desafio-finxi,代码行数:16,代码来源:test_models.py
示例16: setUp
def setUp(self):
self.recipe = Recipe(
FormFieldResponse,
form_field__kind='multiple-choice',
form_field__details={
'choices': [{'label': 'A'}, {'label': 'B'}, {'label': 'C'}],
'required': True
}
)
开发者ID:jsayres,项目名称:dynamic-forms-example,代码行数:9,代码来源:test_form_field_response.py
示例17: InfoResponseTests
class InfoResponseTests(TestCase):
def setUp(self):
self.recipe = Recipe(FormFieldResponse, form_field__kind='info')
def test_should_never_pass(self):
for details in [{}, {'answer': 'no good'}]:
field_response = self.recipe.prepare(details=details)
self.assertRaises(ValidationError, field_response.clean)
开发者ID:jsayres,项目名称:dynamic-forms-example,代码行数:9,代码来源:test_form_field_response.py
示例18: create_employer
class Fixtures:
def create_employer(self):
emp = models.Employer.objects.create(name="ACME", id=1, nochallenge=True, active2015=True, active2016=True)
emp.save()
def leg_setup(self):
self.survey_recipe = Recipe(models.Commutersurvey)
self.all_modes = models.Mode.objects.all()
self.leg_recipe = Recipe(
models.Leg,
checkin = self.survey_recipe.make(),
mode = cycle(self.all_modes)
)
def generate_leg_set(self, checkin):
# generates a set of legs to associate with a given checkin
# set is complete in the sense of having 1+ leg per direction/day pair
self.leg_recipe.make(day='w', direction='fw', checkin=checkin, _quantity=randint(1,3))
self.leg_recipe.make(day='w', direction='tw', checkin=checkin, _quantity=randint(1,3))
self.leg_recipe.make(day='n', direction='fw', checkin=checkin, _quantity=randint(1,3))
self.leg_recipe.make(day='n', direction='tw', checkin=checkin, _quantity=randint(1,3))
def create_legs(self):
self.leg_setup()
checkin = self.survey_recipe.make()
self.generate_leg_set(checkin)
checkin.save()
return (self.leg_recipe, checkin)
开发者ID:greenstreetsinitiative,项目名称:checkin2015,代码行数:28,代码来源:tests.py
示例19: TestPostModel
class TestPostModel(TestCase):
def setUp(self):
self.recipe = Recipe(Post, slug=None)
def test_str(self):
post = self.recipe.make(title='foobar')
self.assertEqual(post.__str__(), 'foobar')
def test_get_absolute_url(self):
post = self.recipe.make(title='foobar')
self.assertEqual(post.get_absolute_url(), '/foobar/')
def test_queryset(self):
# cria 2 posts
self.recipe.make(status=cycle([Post.FINISHED, Post.DRAFT]), _quantity=2)
# Aprova os finalizados
Post.objects.filter(status=Post.FINISHED).update(approved=True)
# cria mais 2 posts para termos finalizados não aprovados
self.recipe.make(status=cycle([Post.FINISHED, Post.DRAFT]), _quantity=2)
self.assertEqual(Post.objects.finished().count(), 2)
self.assertEqual(Post.objects.draft().count(), 2)
self.assertEqual(Post.objects.approved().count(), 1)
self.assertEqual(Post.objects.live().count(), 1)
开发者ID:dvl,项目名称:pyclub,代码行数:26,代码来源:tests.py
示例20: setUp
def setUp(self):
self.recipe_attrs = {
"name": "John Doe",
"nickname": "joe",
"age": 18,
"bio": "Someone in the crowd",
"birthday": now().date(),
"appointment": now(),
"blog": "http://joe.blogspot.com",
"wanted_games_qtd": 4,
"birth_time": now(),
}
self.person_recipe = Recipe(Person, **self.recipe_attrs)
开发者ID:berinhard,项目名称:model_mommy,代码行数:13,代码来源:test_recipes.py
注:本文中的model_mommy.recipe.Recipe类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论