本文整理汇总了Python中mixer.backend.django.mixer.blend方法的典型用法代码示例。如果您正苦于以下问题:Python mixer.blend方法的具体用法?Python mixer.blend怎么用?Python mixer.blend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mixer.backend.django.mixer
的用法示例。
在下文中一共展示了mixer.blend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send_get_request_via_user_viewset
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_send_get_request_via_user_viewset(self):
# list GET : POST
# retrive / patch / des / GET:PUT:DELETE
admin_user = mixer.blend(
'auth.User',
is_staff=True,
is_superuser=True)
app = self.set_oauth2_app_by_admin(admin_user)
access_token = self.get_token(admin_user, app)
url = reverse('user-list')
self.client.credentials(
HTTP_AUTHORIZATION=f'Bearer {access_token}'
)
response = self.client.get(url, format='json')
assert response.status_code == status.HTTP_200_OK
示例2: test_create_oauth2_token
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_create_oauth2_token(self):
admin_user = mixer.blend('auth.User', is_staff=True, is_superuser=True)
app = Application.objects.create(
name='SuperAPI OAUTH2 APP',
user=admin_user,
client_type=Application.CLIENT_PUBLIC,
authorization_grant_type=Application.GRANT_PASSWORD,
)
assert Application.objects.count() == 1, "Should be equal"
random = get_random_string(length=16)
admin_token = AccessToken.objects.create(
user=admin_user,
scope='read write',
# ?? ????? . . .
expires=timezone.now() + timedelta(minutes=5),
token=f'{random}---{admin_user.username}',
application=app
)
assert admin_token is not None, "??? ???"
示例3: setUp
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def setUp(self):
self.semester = mixer.blend(Semester)
self.user = mixer.blend(User)
self.admin_user = User.objects.create_superuser('admin', '[email protected]', 'password')
self.client.force_login(self.admin_user)
self.call = mixer.blend(
Call, semester=self.semester,
deadline=timezone.now() + timedelta(days=7),
opens=timezone.now(),
proposal_type=Call.SCI_PROPOSAL
)
mixer.blend(Instrument, call=self.call)
self.apps = mixer.cycle(3).blend(
ScienceApplication,
status=ScienceApplication.SUBMITTED,
submitter=self.user,
call=self.call,
tac_rank=(x for x in range(3))
)
示例4: test_request_state_pond_state_initial_state_pending
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_request_state_pond_state_initial_state_pending(self):
request = dmixer.blend(Request, state='PENDING')
fail_count = request.fail_count
now = timezone.now()
molecules = mixer.cycle(4).blend(PondMolecule, completed=False, failed=False, event=[])
pond_blocks = [mixer.blend(PondBlock, molecules=molecules, canceled=False, start=now - timedelta(minutes=30),
end=now + timedelta(minutes=30))._to_dict(),
mixer.blend(PondBlock, molecules=molecules)._to_dict()]
state_changed = update_request_state(request, pond_blocks, False)
request.refresh_from_db()
self.assertFalse(state_changed)
self.assertEqual(request.state, 'PENDING')
self.assertEqual(fail_count, request.fail_count)
示例5: test_request_state_pond_state_failed_but_threshold_complete_2
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_request_state_pond_state_failed_but_threshold_complete_2(self):
request = dmixer.blend(Request, state='PENDING', acceptability_threshold=70.0)
now = timezone.now()
molecules = mixer.cycle(4).blend(PondMolecule, completed=False, failed=True, event=[{'completedExposures': 0},],
exp_time=100, exp_cnt=1)
molecules.append(mixer.blend(PondMolecule, completed=True, failed=False, event=[{'completedExposures': 10,}],
exp_time=100, exp_cnt=10))
pond_blocks = [mixer.blend(PondBlock, molecules=molecules, start=now - timedelta(minutes=30), end=now + timedelta(minutes=30))._to_dict(),
mixer.blend(PondBlock, molecules=molecules)._to_dict()]
state_changed = update_request_state(request, pond_blocks, False)
request.refresh_from_db()
self.assertTrue(state_changed)
self.assertEqual(request.state, 'COMPLETED')
示例6: test_request_state_pond_state_failed_and_threshold_failed
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_request_state_pond_state_failed_and_threshold_failed(self):
request = dmixer.blend(Request, state='PENDING', acceptability_threshold=95.0)
fail_count = request.fail_count
now = timezone.now()
molecules = mixer.cycle(4).blend(PondMolecule, completed=False, failed=True, event=[{'completedExposures': 9},],
exp_time=100, exp_cnt=10)
pond_blocks = [mixer.blend(PondBlock, molecules=molecules, start=now - timedelta(minutes=30), end=now + timedelta(minutes=30))._to_dict(),
mixer.blend(PondBlock, molecules=molecules)._to_dict()]
state_changed = update_request_state(request, pond_blocks, False)
request.refresh_from_db()
self.assertTrue(state_changed)
self.assertEqual(request.state, 'PENDING')
self.assertEqual(fail_count + 1, request.fail_count)
示例7: test_many_requests_complete_and_expired
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_many_requests_complete_and_expired(self, modify_mock):
now = timezone.now()
dmixer.cycle(3).blend(Window, request=(r for r in self.requests), start=now-timedelta(days=2), end=now-timedelta(days=1))
molecules1 = mixer.cycle(3).blend(PondMolecule, completed=True, failed=False, request_num=self.requests[0].id, tracking_num=self.ur.id, event=[])
molecules2 = mixer.cycle(3).blend(PondMolecule, completed=False, failed=False, request_num=self.requests[1].id, tracking_num=self.ur.id, event=[])
molecules3 = mixer.cycle(3).blend(PondMolecule, completed=False, failed=False, request_num=self.requests[2].id, tracking_num=self.ur.id, event=[])
pond_blocks = mixer.cycle(3).blend(PondBlock, molecules=(m for m in [molecules1, molecules2, molecules3]), start=now - timedelta(minutes=30), end=now - timedelta(minutes=20))
pond_blocks = [pb._to_dict() for pb in pond_blocks]
update_request_states_from_pond_blocks(pond_blocks)
request_states = ['COMPLETED', 'WINDOW_EXPIRED', 'WINDOW_EXPIRED']
for i, req in enumerate(self.requests):
req.refresh_from_db()
self.assertEqual(req.state, request_states[i])
self.ur.refresh_from_db()
self.assertEqual(self.ur.state, 'COMPLETED')
示例8: test_many_requests_complete_and_failed
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_many_requests_complete_and_failed(self, modify_mock):
now = timezone.now()
dmixer.cycle(3).blend(Window, request=(r for r in self.requests), start=now-timedelta(days=2), end=now+timedelta(days=1))
molecules1 = mixer.cycle(3).blend(PondMolecule, completed=True, failed=False, request_num=self.requests[0].id, tracking_num=self.ur.id, event=[])
molecules2 = mixer.cycle(3).blend(PondMolecule, completed=True, failed=False, request_num=self.requests[1].id, tracking_num=self.ur.id, event=[])
molecules3 = mixer.cycle(3).blend(PondMolecule, completed=False, failed=True, request_num=self.requests[2].id, tracking_num=self.ur.id, event=[])
pond_blocks = mixer.cycle(3).blend(PondBlock, molecules=(m for m in [molecules1, molecules2, molecules3]), start=now - timedelta(minutes=30), end=now - timedelta(minutes=20))
pond_blocks = [pb._to_dict() for pb in pond_blocks]
update_request_states_from_pond_blocks(pond_blocks)
request_states = ['COMPLETED', 'COMPLETED', 'PENDING']
for i, req in enumerate(self.requests):
req.refresh_from_db()
self.assertEqual(req.state, request_states[i])
self.ur.refresh_from_db()
self.assertEqual(self.ur.state, 'PENDING')
示例9: test_many_requests_window_expired_and_failed
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_many_requests_window_expired_and_failed(self, modify_mock):
now = timezone.now()
self.requests[0].state = 'WINDOW_EXPIRED'
self.requests[0].save()
dmixer.cycle(3).blend(Window, request=(r for r in self.requests), start=now-timedelta(days=2), end=now+timedelta(days=1))
molecules1 = mixer.cycle(3).blend(PondMolecule, completed=False, failed=False, request_num=self.requests[0].id, tracking_num=self.ur.id, event=[])
molecules2 = mixer.cycle(3).blend(PondMolecule, completed=False, failed=True, request_num=self.requests[1].id, tracking_num=self.ur.id, event=[])
molecules3 = mixer.cycle(3).blend(PondMolecule, completed=False, failed=True, request_num=self.requests[2].id, tracking_num=self.ur.id, event=[])
pond_blocks = mixer.cycle(3).blend(PondBlock, molecules=(m for m in [molecules1, molecules2, molecules3]), start=now - timedelta(minutes=30), end=now - timedelta(minutes=20))
pond_blocks = [pb._to_dict() for pb in pond_blocks]
update_request_states_from_pond_blocks(pond_blocks)
request_states = ['WINDOW_EXPIRED', 'PENDING', 'PENDING']
for i, req in enumerate(self.requests):
req.refresh_from_db()
self.assertEqual(req.state, request_states[i])
self.ur.refresh_from_db()
self.assertEqual(self.ur.state, 'PENDING')
示例10: test_many_requests_complete_and_complete
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_many_requests_complete_and_complete(self, modify_mock):
now = timezone.now()
self.requests[0].state = 'COMPLETED'
self.requests[0].save()
self.requests[1].state = 'COMPLETED'
self.requests[1].save()
dmixer.cycle(3).blend(Window, request=(r for r in self.requests), start=now-timedelta(days=2), end=now+timedelta(days=1))
molecules3 = mixer.cycle(3).blend(PondMolecule, completed=True, failed=False, request_num=self.requests[2].id, tracking_num=self.ur.id)
pond_blocks = [mixer.blend(PondBlock, molecules=molecules3, start=now - timedelta(minutes=30), end=now - timedelta(minutes=20))._to_dict()]
update_request_states_from_pond_blocks(pond_blocks)
request_states = ['COMPLETED', 'COMPLETED', 'COMPLETED']
for i, req in enumerate(self.requests):
req.refresh_from_db()
self.assertEqual(req.state, request_states[i])
self.ur.refresh_from_db()
self.assertEqual(self.ur.state, 'COMPLETED')
示例11: test_many_requests_complete_and_window_expired
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_many_requests_complete_and_window_expired(self, modify_mock):
now = timezone.now()
self.requests[0].state = 'COMPLETED'
self.requests[0].save()
self.requests[1].state = 'COMPLETED'
self.requests[1].save()
dmixer.cycle(3).blend(Window, request=(r for r in self.requests), start=now-timedelta(days=2), end=now-timedelta(days=1))
molecules3 = mixer.cycle(3).blend(PondMolecule, completed=False, failed=True, request_num=self.requests[2].id, tracking_num=self.ur.id, event=[])
pond_blocks = [mixer.blend(PondBlock, molecules=molecules3, start=now - timedelta(minutes=30), end=now - timedelta(minutes=20))._to_dict()]
update_request_states_from_pond_blocks(pond_blocks)
request_states = ['COMPLETED', 'COMPLETED', 'WINDOW_EXPIRED']
for i, req in enumerate(self.requests):
req.refresh_from_db()
self.assertEqual(req.state, request_states[i])
self.ur.refresh_from_db()
self.assertEqual(self.ur.state, 'COMPLETED')
示例12: test_many_requests_canceled_to_completed
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_many_requests_canceled_to_completed(self, modify_mock):
now = timezone.now()
for req in self.requests:
req.state = 'CANCELED'
req.save()
self.ur.state = 'CANCELED'
self.ur.save()
dmixer.cycle(3).blend(Window, request=(r for r in self.requests), start=now-timedelta(days=2), end=now-timedelta(days=1))
molecules3 = mixer.cycle(3).blend(PondMolecule, completed=True, failed=False, request_num=self.requests[2].id, tracking_num=self.ur.id)
pond_blocks = [mixer.blend(PondBlock, molecules=molecules3, start=now - timedelta(minutes=30), end=now - timedelta(minutes=20))._to_dict()]
update_request_states_from_pond_blocks(pond_blocks)
request_states = ['CANCELED', 'CANCELED', 'COMPLETED']
for i, req in enumerate(self.requests):
req.refresh_from_db()
self.assertEqual(req.state, request_states[i])
self.ur.refresh_from_db()
self.assertEqual(self.ur.state, 'COMPLETED')
示例13: test_oneof_requests_window_expired_to_completed
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_oneof_requests_window_expired_to_completed(self, modify_mock):
now = timezone.now()
self.ur.operator = 'ONEOF'
self.ur.save()
for req in self.requests:
req.state = 'WINDOW_EXPIRED'
req.save()
self.ur.state = 'WINDOW_EXPIRED'
self.ur.save()
dmixer.cycle(3).blend(Window, request=(r for r in self.requests), start=now - timedelta(days=2),
end=(e for e in [now - timedelta(days=1), now - timedelta(days=1), now + timedelta(days=1)]))
molecules3 = mixer.cycle(3).blend(PondMolecule, completed=True, failed=False, request_num=self.requests[2].id, tracking_num=self.ur.id)
pond_blocks = [mixer.blend(PondBlock, molecules=molecules3, start=now - timedelta(minutes=30), end=now - timedelta(minutes=20))._to_dict()]
update_request_states_from_pond_blocks(pond_blocks)
request_states = ['WINDOW_EXPIRED', 'WINDOW_EXPIRED', 'COMPLETED']
for i, req in enumerate(self.requests):
req.refresh_from_db()
self.assertEqual(req.state, request_states[i])
self.ur.refresh_from_db()
self.assertEqual(self.ur.state, 'COMPLETED')
示例14: test_oneof_requests_canceled_to_completed
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def test_oneof_requests_canceled_to_completed(self, modify_mock):
now = timezone.now()
self.ur.operator = 'ONEOF'
self.ur.save()
for req in self.requests:
req.state = 'CANCELED'
req.save()
self.ur.state = 'CANCELED'
self.ur.save()
dmixer.cycle(3).blend(Window, request=(r for r in self.requests), start=now - timedelta(days=2),
end=(e for e in [now - timedelta(days=1), now - timedelta(days=1), now + timedelta(days=1)]))
molecules3 = mixer.cycle(3).blend(PondMolecule, completed=True, failed=False, request_num=self.requests[2].id, tracking_num=self.ur.id)
pond_blocks = [mixer.blend(PondBlock, molecules=molecules3, start=now - timedelta(minutes=30), end=now - timedelta(minutes=20))._to_dict()]
update_request_states_from_pond_blocks(pond_blocks)
request_states = ['CANCELED', 'CANCELED', 'COMPLETED']
for i, req in enumerate(self.requests):
req.refresh_from_db()
self.assertEqual(req.state, request_states[i])
self.ur.refresh_from_db()
self.assertEqual(self.ur.state, 'COMPLETED')
示例15: setUp
# 需要导入模块: from mixer.backend.django import mixer [as 别名]
# 或者: from mixer.backend.django.mixer import blend [as 别名]
def setUp(self):
super().setUp()
self.proposal = mixer.blend(Proposal)
self.user = mixer.blend(User)
mixer.blend(Profile, user=self.user)
self.client.force_login(self.user)
self.semester = mixer.blend(
Semester, id='2016B', start=datetime(2016, 9, 1, tzinfo=timezone.utc),
end=datetime(2016, 12, 31, tzinfo=timezone.utc)
)
self.time_allocation_1m0_sbig = mixer.blend(
TimeAllocation, proposal=self.proposal, semester=self.semester,
telescope_class='1m0', instrument_name='1M0-SCICAM-SBIG', std_allocation=100.0, std_time_used=0.0,
too_allocation=10, too_time_used=0.0, ipp_limit=10.0, ipp_time_available=5.0
)
self.time_allocation_2m0_floyds = mixer.blend(
TimeAllocation, proposal=self.proposal, semester=self.semester,
telescope_class='2m0', instrument_name='2M0-FLOYDS-SCICAM', std_allocation=100.0, std_time_used=0.0,
too_allocation=10, too_time_used=0.0, ipp_limit=10.0, ipp_time_available=5.0
)
self.membership = mixer.blend(Membership, user=self.user, proposal=self.proposal)
self.generic_payload = copy.deepcopy(generic_payload)
self.generic_payload['proposal'] = self.proposal.id