def test_distribution(self): management.call_command('generate_sadiks', 10) management.call_command('generate_requestions', 200, distribute_in_any_sadik=True) Requestion.objects.all().update(status=STATUS_REQUESTER) # Requestion.objects.all().update(cast=3) current_datetime = datetime.date.today() current_distribution_year = get_current_distribution_year() for age_group in AgeGroup.objects.all(): group_min_birth_date = age_group.min_birth_date() group_max_birth_date = age_group.max_birth_date() for sadik in Sadik.objects.all(): SadikGroup.objects.create( free_places=10, capacity=10, age_group=age_group, sadik=sadik, year=current_distribution_year, min_birth_date=group_min_birth_date, max_birth_date=group_max_birth_date) # группа заявок с датой распределения преывшающей текущую # они не должны быть распределены requestions_admission_date_ids = list(Requestion.objects.all( ).order_by('?')[:30].values_list('id', flat=True)) try: admission_date = current_datetime.replace( year=current_datetime.year + 1) except ValueError: admission_date = current_datetime.replace( year=current_datetime.year + 1, day=current_datetime.day - 1) Requestion.objects.filter( id__in=requestions_admission_date_ids ).update(admission_date=admission_date) # добавим новые ДОУ без мест и заявки желающие распределиться только # в эти ДОУ existing_sadiks_ids = list(Sadik.objects.all().values_list( 'id', flat=True)) management.call_command('generate_sadiks', 5) new_sadiks = list(Sadik.objects.exclude(id__in=existing_sadiks_ids)) # TODO: Исправить тест, с учетом distribute_in_any_sadik = True!!! requestions_pref_sadiks_ids = list(Requestion.objects.exclude( id__in=requestions_admission_date_ids ).order_by('?')[:30].values_list('id', flat=True)) for requestion in Requestion.objects.filter( id__in=requestions_pref_sadiks_ids): requestion.pref_sadiks = new_sadiks requestion.distribute_in_any_sadik = True requestion.save() requestions_area_distribution_ids = list(Requestion.objects.exclude( id__in=requestions_admission_date_ids + requestions_pref_sadiks_ids )[:30].values_list('id', flat=True)) Requestion.objects.filter(id__in=requestions_area_distribution_ids ).update(distribute_in_any_sadik=True) for requestion in Requestion.objects.filter( id__in=requestions_area_distribution_ids): requestion.areas = (random.choice(Area.objects.all()),) requestion.pref_sadiks = [] client = Client() client.login(username=self.operator.username, password="******") client.post(reverse('distribution_init'), data={'confirmation': 'yes'}, follow=True) decision_manager = DecisionManager() last_distributed_requestion = None queue_info = decision_manager.queue_info() total = 0 while queue_info['free_places'] and queue_info['queue']: requestion = queue_info['current_requestion'] if last_distributed_requestion: self.assertEqual(last_distributed_requestion, queue_info['last_distributed_requestion'], ) sadiks_for_requestion_dict = decision_manager.sadiks_for_requestion( requestion) sadiks_for_requestion = \ sadiks_for_requestion_dict['pref_sadiks'] or \ sadiks_for_requestion_dict['any_sadiks'] sadik = sadiks_for_requestion[0] if requestion.cast == 1: response = client.post( reverse('decision_manager'), data={ 'sadik': sadik.id, 'requestion_id': requestion.id, 'accept_location': True} ) else: response = client.post( reverse('decision_manager'), data={'sadik': sadik.id, 'requestion_id': requestion.id}) if response.status_code == 302: last_distributed_requestion = requestion total += 1 queue_info = decision_manager.queue_info() # проверяем,что заявки с ЖДП, превышающим текущую дату и желающие # зачислиться в ДОУ без мест не распределены # закомментировал с учетом distribute_in_any_sadik = True requestions_not_decision_ids = list(requestions_admission_date_ids) # + list(requestions_pref_sadiks_ids) self.assertEqual( Requestion.objects.filter( id__in=requestions_not_decision_ids).filter( status=STATUS_DECISION).count(), 0) # проверяем, что заявка была зачислена в свою возрастную группу for requestion in Requestion.objects.filter(status=STATUS_DECISION): self.assertIn( requestion.distributed_in_vacancy.sadik_group.age_group, requestion.age_groups()) # проверяем, что заявки, которые указали возможность зачисления в # любой ДОУ были зачислены в нужную территориальную область for requestion in Requestion.objects.filter( id__in=requestions_area_distribution_ids, distributed_in_vacancy__isnull=False): # проверяем, что заявка попадает в какую-нибудь возрастную группу и # может быть распределена if requestion.age_groups(): self.assertEqual( requestion.areas.all()[0], requestion.distributed_in_vacancy.sadik_group.sadik.area)
# -*- coding: utf-8 -*- from django.conf.urls.defaults import patterns, url from sadiki.distribution.views import DistributionInfo, DistributionInit, \ DistributionEnd, DecisionManager, DistributionResults, EndedDistributions, DistributionPlacesResults urlpatterns = patterns('', # Работа с комплектованием url(r'^$', DistributionInfo.as_view(), name='distribution_info'), url(r'^ended_distributions/$', EndedDistributions.as_view(), name='ended_distributions'), url(r'^results/(?P<distribution_id>\d{1,7})/$', DistributionResults.as_view(), name='distribution_results'), url(r'^places_results/(?P<distribution_id>\d{1,7})/$', DistributionPlacesResults.as_view(), name='distribution_places_results'), url(r'^new/$', DistributionInit.as_view(), name='distribution_init'), url(r'^decision_manager/$', DecisionManager.as_view(), name='decision_manager'), # url(r'^progress/$', # DistributionProgress.as_view(), name='distribution_progress'), # url(r'^autorun/$', # RunAutomaticDistribution.as_view(), name='distribution_autorun'), # url(r'^swap/(?:(?P<requestion_id>\d{1,7})/)?$', # DistributionEditmanually.as_view(), name='distribution_swap_requestions'), url(r'^finish/$', DistributionEnd.as_view(), name='distribution_end'), )