def test_studies_deleted_appears_for_admin(self): """ Test for url 'administracion:main_estudios' with the 'eliminado_admin' parameter. Visit the url of name 'administracion:main_estudios' and check it loads the content of the socio-economic studies deleted in the dashboard panel. """ # Get the capturist and creates families user = User.objects.get(username='******') user_id = user.id capturist = Capturista.objects.get(user=user_id) solvencia = 'No tienen dinero' estado = Familia.OPCION_ESTADO_SOLTERO estado2 = Familia.OPCION_ESTADO_CASADO_CIVIL localidad = Familia.OPCION_LOCALIDAD_JURICA localidad2 = Familia.OPCION_LOCALIDAD_CAMPANA f1 = Familia(numero_hijos_diferentes_papas=1, explicacion_solvencia=solvencia, estado_civil=estado, localidad=localidad) f1.save() f2 = Familia(numero_hijos_diferentes_papas=2, explicacion_solvencia=solvencia, estado_civil=estado2, localidad=localidad2) f2.save() e1 = Estudio(capturista_id=capturist.id, familia_id=f1.id, status=Estudio.ELIMINADO_ADMIN) e1.save() e2 = Estudio(capturista_id=capturist.id, familia_id=f2.id, status=Estudio.ELIMINADO_ADMIN) e2.save() test_url_name = 'administracion:main_estudios' self.browser.visit( self.live_server_url + reverse(test_url_name, args=['eliminado_administrador'])) self.assertEqual(Estudio.objects.count(), 2) self.assertFalse( self.browser.is_text_present( 'No existen registros de este tipo de estudios para mostrar')) # Check that the following texts are present in the dashboard self.assertTrue(self.browser.is_text_present('Número')) self.assertTrue(self.browser.is_text_present('Familia')) self.assertTrue(self.browser.is_text_present('Nombre del Capturista')) self.assertTrue(self.browser.is_text_present('Acciones')) self.assertTrue(self.browser.is_text_present('Eliminado'))
def list_studies(request, status_study): """ View to list the studies with a specific status according to the button pushed """ total_estudios = Estudio.objects.count() estudios = Estudio.objects.filter(status=status_study) contexto = { 'estudios': estudios, 'estado': status_study, 'status_options': Estudio.get_options_status(), 'total_estudios': total_estudios } return render(request, 'estudios_socioeconomicos/listado_estudios.html', contexto)
def capturista_dashboard(request): """View to render the capturista control dashboard. This view shows the list of socio-economic studies that are under review and the button to add a new socio-economic study. Also shows the edit and see feedback buttons to each socio-economic study shown in the list if this exists for the current user (capturist). """ context = {} estudios = Estudio.objects.filter( status__in=[Estudio.RECHAZADO, Estudio.REVISION, Estudio.BORRADOR], capturista=Capturista.objects.get( user=request.user)).order_by('status') context['estudios'] = estudios context['status_options'] = Estudio.get_options_status() return render(request, 'captura/dashboard_capturista.html', context)
def test_invalid_status(self): """ Test we can't assign a scholarship to a family who's status is not approved yet. """ for status in filter(lambda x: x != Estudio.APROBADO, Estudio.get_options_status().values()): familia = Familia.objects.create(numero_hijos_diferentes_papas=3, explicacion_solvencia='narco', estado_civil='secreto', localidad='otro') estudio = Estudio.objects.create(capturista=self.capturista, familia=familia, status=status) data = {'tabulador': '17', 'porcentaje': '20'} response = self.client.post(reverse( 'becas:asignar_beca', kwargs={'id_estudio': estudio.id}), data=data) self.assertEqual(404, response.status_code)
def save_upload_study(request, id_estudio): """ Final view of where a capturista decides whether to upload a study for revision. This view allows a capturista user to upload a study for revision. After uploading, the capturista is not allowed to modify the study. @TODO: Check study is actually ready for upload? """ context = {} estudio = get_object_or_404(Estudio, pk=id_estudio) if is_capturista(request.user): get_object_or_404(Estudio, pk=id_estudio, capturista=request.user.capturista) if not user_can_modify_study(request.user, estudio): raise Http404() if request.method == 'POST': if is_capturista( request.user): # Capturista can only save in revision mode estudio.status = Estudio.REVISION estudio.save() return redirect('captura:estudios') if estudio.status == Estudio.RECHAZADO: context['retroalimentacion'] = Retroalimentacion.objects.filter( estudio=estudio) context['comentarios'] = Comentario.objects.filter(familia=estudio.familia) context['form'] = ComentarioForm(initial={'familia': estudio.familia}) context['estudio'] = estudio context['status_options'] = Estudio.get_options_status() return render(request, 'captura/save_upload_study.html', context)