本文整理汇总了Python中mixer.backend.django.mixer.cycle函数的典型用法代码示例。如果您正苦于以下问题:Python cycle函数的具体用法?Python cycle怎么用?Python cycle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cycle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_paginator
def test_paginator(self):
from adrest.mixin import EmitterMixin
from django.views.generic import View
from django.test import RequestFactory
from tests.core.models import Pirate
from adrest.utils.paginator import Paginator
mixer.cycle(3).blend('core.pirate')
class SomeResource(EmitterMixin, View):
class Meta:
model = 'core.pirate'
dyn_prefix = 'adr-'
limit_per_page = 2
def dispatch(self, request, **resources):
p = Paginator(request, self, Pirate.objects.all())
return self.emit(p, request=request)
rf = RequestFactory()
resource = SomeResource()
response = resource.dispatch(rf.get('/'))
self.assertContains(response, '"page": 1')
self.assertContains(response, '"num_pages": 2')
示例2: test_handler
def test_handler(self):
mixer.cycle(3).blend(Reimbursement, search_vector=None)
command = Command()
command.handle(batch_size=2, silent=True)
queryset = Reimbursement.objects.exclude(search_vector=None)
self.assertEqual(3, queryset.count())
示例3: setUp
def setUp(self):
#Create/log in a normal user.
self.a_user = mixer.blend(User, username='adminuser', is_superuser=True, is_staff=True)
self.a_user.set_password('pass')
self.a_user.save()
self.client.login(username='adminuser', password='pass')
mixer.blend(ChangeRequest)
mixer.cycle(2).blend(ChangeLog)
self.rfc = ChangeRequest.objects.first()
示例4: test_get_filter_queryset_custom_filter
def test_get_filter_queryset_custom_filter(self):
mixer.cycle(3).blend("testapp.comment")
response = self.client.get(
'/api/comment?filter=is_outdated=1',
content_type='application/vnd.api+json',
HTTP_ACCEPT='application/vnd.api+json'
)
data = json.loads(response.content.decode("utf-8"))
self.assertEqual(len(data['data']), 1)
示例5: test_get_include_many_many_db_queries
def test_get_include_many_many_db_queries(self):
mixer.cycle(10).blend("testapp.comment")
# prefetch related join is done in python twice.
with self.assertNumQueries(3):
self.client.get(
'/api/author?include=posts,posts.comments',
content_type='application/vnd.api+json',
HTTP_ACCEPT='application/vnd.api+json'
)
示例6: test_get_sort
def test_get_sort(self):
mixer.cycle(2).blend("testapp.comment")
response = self.client.get(
'/api/comment?sort=-id',
content_type='application/vnd.api+json',
HTTP_ACCEPT='application/vnd.api+json'
)
data = json.loads(response.content.decode("utf-8"))
self.assertEqual([o['id'] for o in data['data']], [2, 1])
示例7: test_get_include_db_query
def test_get_include_db_query(self):
mixer.cycle(10).blend("testapp.comment")
# prefetch related join is done in python twice.
# TODO: add 'comments.author' relationship (->to-many->to-one).
with self.assertNumQueries(3):
self.client.get(
'/api/post?include=author,comments,author.comments',
content_type='application/vnd.api+json',
HTTP_ACCEPT='application/vnd.api+json'
)
示例8: setUp
def setUp(self):
super(ReferralCreateChildTest, self).setUp()
self.ref = Referral.objects.first()
# Ensure that conditions with 'approved' text exist on the referral.
mixer.cycle(3).blend(
Condition, referral=self.ref, category=mixer.SELECT,
condition=mixer.RANDOM, model_condition=mixer.SELECT,
proposed_condition=mixer.RANDOM)
for i in Condition.objects.filter(referral=self.ref):
i.proposed_condition_html = '<p>Proposed condition</p>'
i.condition_html = '<p>Actual condition</p>'
i.save()
示例9: setUp
def setUp(self):
super(AssetsAdminTestCase, self).setUp()
# Create/log in an admin user.
self.admin_user = mixer.blend(User, username='admin', is_superuser=True, is_staff=True)
self.admin_user.set_password('pass')
self.admin_user.save()
self.client.login(username='admin', password='pass')
mixer.cycle(5).blend(
HardwareAsset, purchased_value=randint(100, 1000), date_purchased=random_datetime)
mixer.cycle(5).blend(
SoftwareAsset, support_expiry=random_datetime)
示例10: handle
def handle(self, *args, **options):
self.stdout.write('Deleting data.......' )
BlogCategory.objects.all().delete()
BlogTopic.objects.all().delete()
BlogPost.objects.all().delete()
self.stdout.write('Start loading.......' )
categories = mixer.cycle(10).blend(BlogCategory)
for c in categories:
topics = mixer.cycle(10).blend(BlogTopic,category=c, title=u'Заголовок блога категории '+c.name)
for t in topics:
posts = mixer.cycle(10).blend(BlogPost,topic=t,content=mixer.fake, author='Fedot')
self.stdout.write('Well done' )
示例11: test_manager_methods
def test_manager_methods(self):
"""Test the inherited ReferralLookup manager methods.
"""
mixer.cycle(2).blend(DopTrigger) # Some extras.
obj_del = mixer.blend(DopTrigger) # One to delete.
obj_del.delete()
all_pks = [i.pk for i in DopTrigger.objects.all()]
current_pks = [i.pk for i in DopTrigger.objects.current()]
del_pks = [i.pk for i in DopTrigger.objects.deleted()]
self.assertTrue(obj_del.pk in all_pks)
self.assertFalse(obj_del.pk in current_pks)
self.assertTrue(obj_del.pk in del_pks)
self.assertFalse(self.obj.pk in del_pks)
示例12: setUp
def setUp(self):
# We need a defined Group, because of the user_post_save signal in
# the tracking app.
Group.objects.create(name='Edit Resource Tracking Device')
# Create User object.
self.user1 = User.objects.create_user(
username='testuser', email='[email protected]')
self.user1.set_password('pass')
self.user1.save()
# Log in user1 by default.
self.client.login(username=self.user1.username, password='pass')
# Create a WeatherStation object.
self.ws = mixer.blend(WeatherStation)
mixer.cycle(5).blend(WeatherObservation, station=self.ws)
示例13: test_select
def test_select(self):
from mixer.backend.django import mixer
mixer.cycle(3).blend(Rabbit)
hole = mixer.blend(Hole, rabbit=mixer.select)
self.assertFalse(hole.rabbit)
rabbits = Rabbit.objects.all()
hole = mixer.blend(Hole, owner=mixer.select)
self.assertTrue(hole.owner in rabbits)
rabbit = rabbits[0]
hole = mixer.blend(Hole, owner=mixer.select(email=rabbit.email))
self.assertEqual(hole.owner, rabbit)
示例14: test_get_include_many_to_many
def test_get_include_many_to_many(self):
group = mixer.blend('testapp.group')
authors = mixer.cycle(2).blend('testapp.author')
memberships = mixer.cycle(2).blend('testapp.membership', group=group,
author=(a for a in authors))
# prefetch related join is done in python
with self.assertNumQueries(2):
response = self.client.get(
'/api/author?include=memberships',
content_type='application/vnd.api+json',
HTTP_ACCEPT='application/vnd.api+json'
)
data = json.loads(response.content.decode("utf-8"))
expected_data = {
"data": [{
"id": author.id,
"name": author.name,
"links": {
"memberships": author.membership_set.values_list(
"id", flat=True)
}
} for author in authors],
"links": {
},
"linked": [{
"type": "memberships",
"id": membership.id,
"links": {
"group": membership.group_id,
"author": membership.author_id,
}
} for membership in memberships]
}
compare(data, expected_data)
response = self.client.get(
'/api/author?include=memberships,memberships.group',
content_type='application/vnd.api+json',
HTTP_ACCEPT='application/vnd.api+json'
)
data = json.loads(response.content.decode("utf-8"))
expected_data["linked"].append({
"type": "group",
"id": group.id,
"name": group.name,
})
compare(data, expected_data)
示例15: setUp
def setUp(self):
"""Generate from FreshdeskTicket objects.
"""
super(FreshdeskTicketResourceTestCase, self).setUp()
mixer.cycle(5).blend(
FreshdeskContact, email=random_dpaw_email)
mixer.cycle(5).blend(
FreshdeskTicket,
subject=mixer.RANDOM, description_text=mixer.RANDOM, type='Test',
freshdesk_requester=mixer.SELECT,
it_system=mixer.SELECT,
custom_fields={
'support_category': None, 'support_subcategory': None},
)
self.ticket = FreshdeskTicket.objects.first()