예제 #1
0
    def test_all_group_methods(self):
        kidgdn = Sadik.objects.all()[0]
        test_requestion = test_utils.create_requestion(
            admission_date=datetime.date(datetime.date.today().year + 1, 1, 1),
            birth_date=datetime.date.today()-datetime.timedelta(days=510)
        )
        test_requestion.areas.add(kidgdn.area)
        test_requestion.save()
        test_utils.create_age_groups_for_sadik(kidgdn)

        groups = test_requestion.get_sadiks_groups()
        self.assertEqual(len(groups), 1)
        self.assertEqual(groups[0].sadik, kidgdn)
        self.assertEqual(groups[0].age_group.id, 2)

        groups_for_kidgdn = test_requestion.get_sadik_groups(kidgdn)
        self.assertEqual(len(groups_for_kidgdn), 1)
        self.assertEqual(groups_for_kidgdn[0], groups[0])

        age_groups = test_requestion.age_groups()
        self.assertEqual(len(age_groups), 1)
        self.assertEqual(age_groups[0].id, 2)
        self.assertEqual(groups[0].age_group, age_groups[0])

        # слишком маленький ребенок, никуда не распределяем
        small_requestion = test_utils.create_requestion(
            admission_date=datetime.date(datetime.date.today().year, 1, 1),
            birth_date=datetime.date.today()-datetime.timedelta(days=1)
        )
        small_requestion.areas.add(kidgdn.area)
        groups_small = small_requestion.get_sadiks_groups()
        self.assertEqual(len(groups_small), 0)
예제 #2
0
    def test_position_in_queue(self):
        # одна заявка, должна быть первой
        self.assertEqual(self.requestion.position_in_queue(), 1)

        # делаем заявку с более высоким приоритетом,
        # смещаем первую на второе место
        benefit_category_high = BenefitCategory.objects.get(priority=1)
        high_priority = test_utils.create_requestion(benefit_category=benefit_category_high)
        self.assertEqual(self.requestion.position_in_queue(), 2)

        # добавим еще одну заявку, без привелегий
        last_req = test_utils.create_requestion()
        self.assertEqual(last_req.position_in_queue(), 3)
        # убираем из очереди приоритетную
        high_priority.status = STATUS_REJECTED
        high_priority.save()
        self.assertEqual(last_req.position_in_queue(), 2)
예제 #3
0
    def test_all_group_methods(self):
        kidgdn = Sadik.objects.all()[0]
        # создаём заявку с ребёнком, попадающим в первую группу раннего возраста
        today = datetime.date.today()
        new_year_start_date = today.replace(month=9, day=1)
        if today <= new_year_start_date:
            birth_date = today.replace(year=today.year - 2, month=6, day=1)
        else:
            birth_date = today.replace(year=today.year - 1, month=6, day=1)
        test_requestion = test_utils.create_requestion(
            admission_date=today.replace(year=today.year + 1), birth_date=birth_date
        )
        test_requestion.areas.add(kidgdn.area)
        test_requestion.save()
        test_utils.create_age_groups_for_sadik(kidgdn)

        groups = test_requestion.get_sadiks_groups()
        self.assertEqual(len(groups), 1)
        self.assertEqual(groups[0].sadik, kidgdn)
        self.assertEqual(groups[0].age_group.id, 2)

        groups_for_kidgdn = test_requestion.get_sadik_groups(kidgdn)
        self.assertEqual(len(groups_for_kidgdn), 1)
        self.assertEqual(groups_for_kidgdn[0], groups[0])

        age_groups = test_requestion.age_groups()
        self.assertEqual(len(age_groups), 1)
        self.assertEqual(age_groups[0].id, 2)
        self.assertEqual(groups[0].age_group, age_groups[0])

        # слишком маленький ребенок, никуда не распределяем
        small_requestion = test_utils.create_requestion(
            admission_date=datetime.date(datetime.date.today().year, 1, 1),
            birth_date=datetime.date.today() - datetime.timedelta(days=1),
        )
        small_requestion.areas.add(kidgdn.area)
        groups_small = small_requestion.get_sadiks_groups()
        self.assertEqual(len(groups_small), 0)
예제 #4
0
    def test_short_stay_requestion_operator(self):
        requestion = create_requestion(status=STATUS_REQUESTER)
        requestion.pref_sadiks.add(self.kg)
        requestion.set_ident_document_authentic()
        requestion.status = STATUS_SHORT_STAY
        requestion.save()
        self.assertEqual(requestion.status, STATUS_SHORT_STAY)

        # проверяем допустимые переводы для подтвержденной заявки
        transition_indexes = workflow.available_transitions(
            src=requestion.status)
        self.assertEqual(len(transition_indexes), 3)
        self.assertEqual(transition_indexes.sort(), [
            SHORT_STAY_DISTRIBUTION, SHORT_STAY_REQUESTER,
            SHORT_STAY_DECISION_BY_RESOLUTION
        ].sort())

        transitions = requestion.available_transitions()

        # отсутствуют транзакции, выполняемые оператором
        operator_allowed_transactions = [
            t for t in transitions if 'is_operator' in t.required_permissions]
        self.assertEqual(len(operator_allowed_transactions), 0)

        # одна транзакция, выполняемая администратором
        supervisor_allowed_transactions = [
            t for t in transitions if 'is_supervisor' in t.required_permissions]
        self.assertEqual(len(supervisor_allowed_transactions), 1)

        login = self.client.login(
            username=OPERATOR_USERNAME,
            password=OPERATOR_PASSWORD
        )
        self.assertTrue(login)
        op_response = self.client.get(
            reverse('operator_requestion_info', args=(requestion.id, )))
        self.assertEqual(op_response.status_code, 200)
        self.assertEqual(op_response.context['requestion'], requestion)

        for t in workflow.transitions:
            url = reverse(
                'operator_requestion_status_change',
                args=(requestion.id, t.dst)
            )
            t_response = self.client.get(url)
            self.assertEqual(t_response.status_code, 403)
            # проверяем, что кнопка выполнения транзакций отсутствует
            html_button = '<a class="btn" href="{}">'.format(url)
            self.assertNotIn(html_button, op_response.content)
예제 #5
0
    def test_distributed_requester_transitions(self):
        requestion = create_requestion(status=STATUS_REQUESTER)
        requestion.status = STATUS_ON_DISTRIBUTION
        requestion.save()
        requestion.status = STATUS_DECISION
        requestion.save()
        requestion.status = STATUS_DISTRIBUTED_FROM_ES
        requestion.save()
        self.assertEqual(requestion.status, STATUS_DISTRIBUTED_FROM_ES)

        req_url = reverse('supervisor_requestion_info', args=(requestion.id, ))
        req_action_url = reverse(
            'supervisor_requestion_status_change',
            args=(requestion.id, STATUS_REQUESTER))

        login = self.client.login(
            username=SUPERVISOR_USERNAME, password=SUPERVISOR_PASSWORD)
        self.assertTrue(login)
        response = self.client.get(req_url)
        self.assertEqual(response.status_code, 200)
        btn_code = u'<a class="btn" href="{}">Повторная постановка на учет</a>'
        self.assertNotIn(btn_code.format(
            req_action_url), response.content.decode('utf8'))
예제 #6
0
    def test_operator_requestion_not_confirmed(self):
        requestion = create_requestion()
        requestion.pref_sadiks.add(self.kg)
        requestion.save()
        self.assertEqual(requestion.status, STATUS_REQUESTER_NOT_CONFIRMED)

        # проверяем допустимые переводы для неподтвержденной заявки
        transition_indexes = workflow.available_transitions(
            src=requestion.status)
        self.assertEqual(len(transition_indexes), 3)
        self.assertEqual(transition_indexes.sort(), [
            CONFIRM_REQUESTION,
            NOT_CONFIRMED_REMOVE_REGISTRATION,
            REQUESTION_REJECT
        ].sort())
        transitions = requestion.available_transitions()
        self.assertEqual(transition_indexes.sort(),
                         [t.index for t in transitions].sort())
        self.assertTrue(requestion.is_available_for_actions)

        # банальные проверки работы веб-интерфейса
        login = self.client.login(
            username=OPERATOR_USERNAME,
            password=OPERATOR_PASSWORD
        )
        self.assertTrue(login)
        op_response = self.client.get(
            reverse('operator_requestion_info', args=(requestion.id, )))
        self.assertEqual(op_response.status_code, 200)
        self.assertEqual(op_response.context['requestion'], requestion)

        # проверяем доступность разрешенных оператору транзакций
        user_allowed_transactions = [
            t for t in transitions if 'is_operator' in t.required_permissions]
        for t in user_allowed_transactions:
            url = reverse(
                'operator_requestion_status_change',
                args=(requestion.id, t.dst)
            )
            t_response = self.client.get(url)
            self.assertEqual(t_response.status_code, 200)
            # проверяем, что кнопка выполнения транзакций пристутствует
            html_button = '<a class="btn" href="{}">'.format(url)
            self.assertIn(html_button, op_response.content)

        # проверяем запрет для пользователя остальных транзакций
        # формируем список из запрещенных транзаций
        user_forbidden_transactions = [
            t for t in transitions if t not in user_allowed_transactions]
        allowed_dst = [t.dst for t in transitions]
        wrong_transitions = [
            t for t in workflow.transitions if (
                t.src != requestion.status and t.dst not in allowed_dst)
        ]
        for t in wrong_transitions + user_forbidden_transactions:
            url = reverse(
                'operator_requestion_status_change',
                args=(requestion.id, t.dst)
            )
            t_response = self.client.get(url)
            self.assertEqual(t_response.status_code, 403)
            # проверяем, что кнопка выполнения транзакций отсутствует
            html_button = '<a class="btn" href="{}">'.format(url)
            self.assertNotIn(html_button, op_response.content)
예제 #7
0
 def setUp(self):
     self.requestion = test_utils.create_requestion(name="Ann")
예제 #8
0
    def test_requestion_search(self):
        today = datetime.date.today()
        date1 = today - datetime.timedelta(days=500)
        date2 = today - datetime.timedelta(days=1000)
        date3 = today - datetime.timedelta(days=800)
        date4 = today - datetime.timedelta(days=1200)
        permission = Permission.objects.get(codename=u'is_requester')
        user = User.objects.create(username='******')
        user.user_permissions.add(permission)
        profile = Profile.objects.create(user=user)
        profile.first_name = u'Иван'
        profile.last_name = u'Иванов'
        profile.save()
        document = PersonalDocument.objects.create(
            profile=profile, series='1234', number='135790')
        requestion1 = test_utils.create_requestion(
            profile=profile, name=u'Серёжа', child_last_name=u'Иванов',
            birth_date=date2)
        requestion1.update_registration_datetime(date1)
        requestion2 = test_utils.create_requestion(
            profile=profile, name=u'Василий', child_last_name=u'Иванов',
            birth_date=date3)
        user = User.objects.create(username='******')
        user.user_permissions.add(permission)
        profile = Profile.objects.create(user=user)
        profile.first_name = u'Андрей'
        profile.last_name = u'Смирнов'
        profile.save()
        requestion3 = test_utils.create_requestion(
            profile=profile, name=u'Саша', child_last_name=u'Смирнова',
            birth_date=date4)
        number1 = requestion1.requestion_number
        number2 = requestion2.requestion_number
        number3 = requestion3.requestion_number

        self.assertTrue(self.client.login(username=self.operator.username,
                                          password='******'))
        post_url = reverse('anonym_requestion_search')
        # поиск по номеру заявки
        post_data = {'requestion_number': requestion2.requestion_number}
        response = self.client.post(post_url, post_data)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, number1)
        self.assertContains(response, number2)
        self.assertNotContains(response, number3)
        # поиск по дате регистрации
        post_data = {'registration_date': today.strftime('%d.%m.%Y')}
        response = self.client.post(post_url, post_data)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, number1)
        self.assertContains(response, number2)
        self.assertContains(response, number3)
        # поиск по данным ребёнка
        post_data = {'child_name': u'Серёжа'}
        response = self.client.post(post_url, post_data)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, number1)
        self.assertNotContains(response, number2)
        self.assertNotContains(response, number3)
        post_data = {'child_name': u'Саша', 'child_last_name': u'Смирнова'}
        response = self.client.post(post_url, post_data)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, number1)
        self.assertNotContains(response, number2)
        self.assertContains(response, number3)
        # поиск по данным заявителя
        post_data = {'requester_first_name': u'Иван',
                     'requester_last_name': u'Иванов'}
        response = self.client.post(post_url, post_data)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, number1)
        self.assertContains(response, number2)
        self.assertNotContains(response, number3)
        # комбинированный поиск: перс. данные заявителя + дата рождения ребёнка
        post_data = {'requester_document_series': '1234',
                     'requester_document_number': '135790',
                     'birth_date': date3.strftime('%d.%m.%Y')}
        response = self.client.post(post_url, post_data)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, number1)
        self.assertContains(response, number2)
        self.assertNotContains(response, number3)
예제 #9
0
    def test_profile_search(self):
        permission = Permission.objects.get(codename=u'is_requester')
        user = User.objects.create(username='******')
        user.user_permissions.add(permission)
        profile = Profile.objects.create(user=user)
        profile.first_name = u'Иван'
        profile.save()
        user = User.objects.create(username='******')
        user.user_permissions.add(permission)
        profile = Profile.objects.create(user=user)
        profile.first_name = u'Иван'
        profile.save()
        new_requestion = test_utils.create_requestion(profile=profile)
        user = User.objects.create(username='******')
        user.user_permissions.add(permission)
        profile = Profile.objects.create(user=user)
        profile.first_name = u'Андрей'
        profile.save()

        self.assertTrue(self.client.login(username=self.operator.username,
                                          password='******'))
        old_requestion = test_utils.create_requestion(
            profile=self.requester.profile)
        profile_search_url = reverse('find_profile_for_requestion',
                                     args=(old_requestion.id,))
        # ищем по имени заявителя, которое должно найтись
        search_form_data = {'parent_first_name': u'Иван'}
        response = self.client.post(profile_search_url, search_form_data)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'requester_1')
        self.assertContains(response, 'requester_2')
        self.assertNotContains(response, 'requester_3')
        # ищем по несуществующему имени заявителя
        search_form_data = {'parent_first_name': u'Вася'}
        response = self.client.post(profile_search_url, search_form_data)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, 'requester_1')
        self.assertNotContains(response, 'requester_2')
        self.assertNotContains(response, 'requester_3')
        # ищем только по имени User
        search_form_data = {'username': '******'}
        response = self.client.post(profile_search_url, search_form_data)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, 'requester_1')
        self.assertContains(response, 'requester_2')
        self.assertNotContains(response, 'requester_3')
        # ищем по имени заявителя и имени User одновременно
        search_form_data = {'username': '******',
                            'parent_first_name': u'Андрей'}
        response = self.client.post(profile_search_url, search_form_data)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, 'requester_1')
        self.assertNotContains(response, 'requester_2')
        self.assertContains(response, 'requester_3')
        # ищем по номеру заявки
        search_form_data = {
            'requestion_number': new_requestion.requestion_number}
        response = self.client.post(profile_search_url, search_form_data)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, 'requester_1')
        self.assertContains(response, 'requester_2')
        self.assertNotContains(response, 'requester_3')