本文整理汇总了Python中mixer.backend.django.mixer.blend函数的典型用法代码示例。如果您正苦于以下问题:Python blend函数的具体用法?Python blend怎么用?Python blend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了blend函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_grados_profesor
def test_add_grados_profesor(self):
"""
Comprueba la vista add_grados_profesor
Comprueba que si no se le pasan datos muestra el formulario.
Comprueba que se muestra al añadir un profesor.
Comprueba que si no se le pasan los datos correctamente no te dirige a añadir los grados.
"""
profesor = User.objects.get(username="profesor")
mixer.blend(Grado, profesores=profesor, id=10)
self.client = Client()
self.client.login(username="admin", password="admin")
session = self.client.session
session['profesor'] = profesor.id
session.save()
response = self.client.post("/miPanel/addGradosProfesor/", {})
boolean = True if not response.context['grados'] else False
self.assertEquals(boolean, False)
response = self.client.post("/miPanel/addGradosProfesor/", {'choices': 'error'})
boolean = True if not response.context['grados'] else False
self.assertEquals(boolean, False)
response = self.client.post("/miPanel/addGradosProfesor/", {'choices': '10'})
boolean = True if not response.context else False
self.assertEquals(boolean, True)
示例2: test_with_invalid_product_id
def test_with_invalid_product_id(self):
"""test the behavior of the import function if a product was not found in the database"""
global CURRENT_PRODUCT_MIGRATION_TEST_DATA
CURRENT_PRODUCT_MIGRATION_TEST_DATA = pd.DataFrame(
[
[
"Product that is not in the Database",
"Existing Migration Source",
"Replacement Product ID",
"comment of the migration",
"Invalid URL"
]
], columns=PRODUCT_MIGRATION_TEST_DATA_COLUMNS
)
mixer.blend("productdb.Product", product_id="Product A", vendor=Vendor.objects.get(id=1))
mixer.blend("productdb.ProductMigrationSource", name="Existing Migration Source")
product_migrations_file = ProductMigrationsExcelImporter("virtual_file.xlsx")
assert product_migrations_file.is_valid_file() is False
product_migrations_file.verify_file()
assert product_migrations_file.is_valid_file() is True
product_migrations_file.import_to_database()
assert ProductMigrationOption.objects.count() == 0
assert "Product Product that is not in the Database not found in database, skip " \
"entry" in product_migrations_file.import_result_messages
Product.objects.all().delete()
ProductMigrationOption.objects.all().delete()
ProductMigrationSource.objects.all().delete()
示例3: test_security
def test_security(self):
user = mixer.blend('auth.User', first_name='Martin')
post = mixer.blend('birdie.Post')
req = RequestFactory().post('/', data={})
req.user = user
with pytest.raises(Http404):
views.PostUpdateView.as_view()(req, pk=post.pk)
示例4: test_form
def test_form(self):
data = {'text': 'Foo'}
form = forms.MessageForm(user=self.user, conversation=None, data=data,
initial_user=self.other_user)
self.assertFalse(form.errors)
self.assertTrue(form.is_valid())
conversation = form.save()
self.assertEqual(Conversation.objects.count(), 1, msg=(
'A new conversation should\'ve been started with the message.'))
form = forms.MessageForm(user=self.user, data=data, initial_user=None,
conversation=conversation)
form.save()
self.assertEqual(Conversation.objects.count(), 1, msg=(
'The existing conversation should\'ve been re-used.'))
blocked_user = mixer.blend('conversation.BlockedUser',
blocked_by=self.user, user=self.other_user)
form = forms.MessageForm(user=self.user, data=data, initial_user=None,
conversation=conversation)
self.assertTrue(form.errors, msg=(
'Conversation should have been blocked'))
blocked_user.delete()
mixer.blend('conversation.BlockedUser',
user=self.user, blocked_by=self.other_user)
form = forms.MessageForm(user=self.user, data=data, initial_user=None,
conversation=conversation)
self.assertTrue(form.errors, msg=(
'Conversation should have been blocked'))
示例5: test_import_with_missing_product_value
def test_import_with_missing_product_value(self):
"""test import with missing product (ignore it)"""
global CURRENT_PRODUCT_MIGRATION_TEST_DATA
CURRENT_PRODUCT_MIGRATION_TEST_DATA = pd.DataFrame(
[
[
None,
"Existing Migration Source",
"Replacement Product ID",
"comment of the migration",
"Invalid URL"
]
], columns=PRODUCT_MIGRATION_TEST_DATA_COLUMNS
)
mixer.blend("productdb.Product", product_id="Product A", vendor=Vendor.objects.get(id=1))
mixer.blend("productdb.ProductMigrationSource", name="Existing Migration Source")
product_migrations_file = ProductMigrationsExcelImporter("no file.xlsx")
assert product_migrations_file.is_valid_file() is False
product_migrations_file.verify_file()
assert product_migrations_file.is_valid_file() is True
product_migrations_file.import_to_database()
assert ProductMigrationOption.objects.count() == 0
assert len(product_migrations_file.import_result_messages) == 0
Product.objects.all().delete()
ProductMigrationOption.objects.all().delete()
ProductMigrationSource.objects.all().delete()
示例6: test_invalid_scheme
def test_invalid_scheme():
from mixer.backend.django import mixer
try:
mixer.blend('django_app.Unknown')
except ValueError:
return False
raise Exception('test.failed')
示例7: test_form
def test_form(self):
account = mixer.blend('account_keeping.Account')
data = {
'transaction_type': 'd',
'transaction_date': now().strftime('%Y-%m-%d'),
'account': account.pk,
'payee': mixer.blend('account_keeping.Payee').pk,
'category': mixer.blend('account_keeping.Category').pk,
'currency': mixer.blend('currency_history.Currency').pk,
'amount_net': 0,
'amount_gross': 0,
'vat': 0,
'value_net': 0,
'value_gross': 0,
'mark_invoice': True,
}
form = forms.TransactionForm(data=data, branch=account.branch)
self.assertFalse(form.errors)
transaction = form.save()
transaction.invoice = mixer.blend('account_keeping.Invoice',
payment_date=None)
transaction.invoice.save()
self.assertFalse(transaction.invoice.payment_date)
data.update({'invoice': transaction.invoice.pk})
form = forms.TransactionForm(data=data, branch=account.branch)
self.assertFalse(form.errors)
transaction = form.save()
self.assertTrue(transaction.invoice.payment_date)
示例8: test_form_suppress_notification_only_for_superusers
def test_form_suppress_notification_only_for_superusers(self):
# anonymous users are not allowed to add a notification
files = {"excel_file": SimpleUploadedFile("myfile.xlsx", b"yxz")}
data = {"suppress_notification": False}
form = ImportProductsFileUploadForm(user=AnonymousUser(), data=data, files=files)
assert form.is_valid() is True
assert form.fields["suppress_notification"].disabled is True
assert form.cleaned_data["suppress_notification"] is True
# authenticated users are not allowed to add a notification
authuser = mixer.blend("auth.User")
files = {"excel_file": SimpleUploadedFile("myfile.xlsx", b"yxz")}
data = {"suppress_notification": False}
form = ImportProductsFileUploadForm(user=authuser, data=data, files=files)
assert form.is_valid() is True
assert form.fields["suppress_notification"].disabled is True
assert form.cleaned_data["suppress_notification"] is True
# superusers are allowed to change the parameter
superuser = mixer.blend("auth.User", is_superuser=True)
files = {"excel_file": SimpleUploadedFile("myfile.xlsx", b"yxz")}
data = {"suppress_notification": False}
form = ImportProductsFileUploadForm(user=superuser, data=data, files=files)
assert form.is_valid() is True
assert form.fields["suppress_notification"].disabled is False
assert form.cleaned_data["suppress_notification"] is False
示例9: test_relate_existing_object_to_task
def test_relate_existing_object_to_task(self):
"""Test POST to relate existing note/record to a task
"""
# First, ensure that a task, record and note all exist.
task = mixer.blend(Task, referral=self.ref)
note = mixer.blend(Note, referral=self.ref)
record = mixer.blend(Record, referral=self.ref)
init_records = task.records.count()
init_notes = task.notes.count()
url = reverse('referral_create_child_related', kwargs={
'pk': self.ref.pk,
'model': 'task',
'id': task.pk,
'type': 'addrecord'})
resp = self.client.post(url, {'records': [record.pk]})
self.assertEqual(resp.status_code, 302)
self.assertTrue(task.records.count() > init_records)
url = reverse('referral_create_child_related', kwargs={
'pk': self.ref.pk,
'model': 'task',
'id': task.pk,
'type': 'addnote'})
resp = self.client.post(url, {'notes': [note.pk]})
self.assertEqual(resp.status_code, 302)
self.assertTrue(task.notes.count() > init_notes)
示例10: test_tag
def test_tag(self):
self.assertFalse(conversation_tags.is_blocked('foo', 'bar'))
user1 = mixer.blend('auth.User')
user2 = mixer.blend('auth.User')
self.assertFalse(conversation_tags.is_blocked(user1, user2))
mixer.blend('conversation.BlockedUser', blocked_by=user1, user=user2)
self.assertTrue(conversation_tags.is_blocked(user1, user2))
示例11: setUp
def setUp(self):
self.user = mixer.blend('auth.User')
self.doc = mixer.blend('document_library.Document')
self.doc_en = self.doc.translate('en')
self.doc_en.save()
self.doc_de = self.doc.translate('de')
self.doc_de.save()
示例12: test_get_average_rating_with_custom_choices
def test_get_average_rating_with_custom_choices(self):
self.assertFalse(self.review.get_average_rating(), msg=(
'If there are no ratings, it should return False.'))
rating1 = mixer.blend('review.Rating', review=self.review, value='4')
# we create choices to simulate, that the previous value was the max
for i in range(0, 5):
mixer.blend('review.RatingCategoryChoiceTranslation',
language_code='en-us',
ratingcategory=rating1.category, value=i)
rating2 = mixer.blend('review.Rating', review=self.review, value='6')
# we create choices to simulate, that the previous value was the max
for i in range(0, 7):
mixer.blend('review.RatingCategoryChoiceTranslation',
language_code='en-us',
ratingcategory=rating2.category, value=i)
mixer.blend('review.Rating', category=rating2.category,
review=self.review, value='6')
mixer.blend('review.Rating', category=rating2.category,
review=self.review, value=None)
# testing the absolute max voting
self.assertEqual(self.review.get_average_rating(6), 6, msg=(
'Should return the average rating value.'))
self.assertEqual(self.review.get_average_rating(4), 4, msg=(
'Should return the average rating value.'))
self.assertEqual(self.review.get_average_rating(100), 100, msg=(
'Should return the average rating value.'))
# testing the category averages
"""
示例13: setUp
def setUp(self):
self.extra_info = mixer.blend(
'review.ReviewExtraInfo',
review=mixer.blend('review.Review',
content_type=ContentType.objects.get_for_model(
WeatherCondition)),
content_type=ContentType.objects.get_for_model(WeatherCondition))
示例14: test_product_migration_source_names_set
def test_product_migration_source_names_set(self):
site = AdminSite()
product_admin = admin.ProductAdmin(models.Product, site)
obj = mixer.blend(
"productdb.Product",
name="Product",
eox_update_time_stamp=None
)
result = product_admin.product_migration_source_names(obj)
expected = ""
assert result == expected
mixer.blend(
"productdb.ProductMigrationOption",
product=obj,
migration_source=ProductMigrationSource.objects.create(name="test"),
replacement_product_id="MyProductId"
)
result = product_admin.product_migration_source_names(obj)
expected = "test"
assert result == expected
mixer.blend(
"productdb.ProductMigrationOption",
product=obj,
migration_source=ProductMigrationSource.objects.create(name="test2"),
replacement_product_id="MyProductId"
)
result = product_admin.product_migration_source_names(obj)
expected = "test\ntest2"
assert result == expected
示例15: test_form
def test_form(self):
form = ProductListForm(data={})
assert form.is_valid() is False
assert "name" in form.errors
assert "description" not in form.errors, "Null/Blank values are allowed"
assert "string_product_list" in form.errors
data = {
"name": "Test Product List",
"description": "",
"string_product_list": ""
}
form = ProductListForm(data=data)
assert form.is_valid() is False
assert "name" not in form.errors, "Should be allowed (can be any string)"
assert "description" not in form.errors, "Null/Blank values are allowed"
assert "string_product_list" in form.errors, "At least one Product is required"
data = {
"name": "Test Product List",
"description": "",
"string_product_list": "Product"
}
mixer.blend("productdb.Product", product_id="Product")
form = ProductListForm(data=data)
assert form.is_valid() is True, form.errors