class ProviderTest(unittest.TestCase):

    def setUp(self):
        self.provider = DataProvider()
        self.mock_app = mock_app
        self.url = "localhost"
        self.port = 8008

    def test_get_alumnos_de_carrera(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            alumnos = self.provider.get_alumnos_de_carrera(token, 'TEST')
            self.assertEqual(len(alumnos), 10)

    def test_get_cantidad_materias_necesarias(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            materias_necesarias = self.provider.get_cantidad_materias_necesarias(token, 'TEST', 2019)
            self.assertEqual(materias_necesarias['cantidad'], 40)

    def test_get_plan(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            materias = self.provider.get_plan(token, 'TEST', 2019)
            self.assertEqual(len(materias), 59)

    def test_get_inscriptos(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            inscriptos = self.provider.get_inscriptos(token, 'TEST')
            self.assertEqual(len(inscriptos), 10)

    def test_get_graduados(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            graduados = self.provider.get_graduados(token, 'TEST')
            self.assertEqual(len(graduados), 10)

    def test_get_graduados_anio(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            graduados = self.provider.get_graduados(token, 'TEST', 2019)
            self.assertEqual(graduados['cantidad'], 1)

    def test_get_ingresantes(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            ingresantes = self.provider.get_ingresantes(token, 'TEST')
            self.assertEqual(len(ingresantes), 10)

    def test_get_ingresantes_anio(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            ingresantes = self.provider.get_ingresantes(token, 'TEST', 2019)
            self.assertEqual(ingresantes['cantidad'], 2)

    def test_get_cursantes(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            cursantes = self.provider.get_cursantes(token, 'TEST')
            self.assertEqual(len(cursantes), 10)

    def test_get_cursantes_anio(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            cursantes = self.provider.get_cursantes(token, 'TEST', 2019)
            self.assertEqual(cursantes['cantidad'], 10)

    def test_get_postulantes(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            postulantes = self.provider.get_postulantes(token, 'TEST')
            self.assertEqual(len(postulantes), 10)

    def test_get_postulantes_anio(self):
        with self.mock_app.run(self.url, self.port):
            token = self.provider.retrieve_token()
            postulantes = self.provider.get_postulantes(token, 'TEST', 2019)
            self.assertEqual(postulantes['cantidad'], 3)
Beispiel #2
0
class AppTest(unittest.TestCase):
    def setUp(self):
        self.provider = DataProvider()
        self.mock_app = mock_app
        self.mock_url = "0.0.0.0"
        self.mock_port = 8008

    def test_recursantes_unauthorized(self):
        """
			Hago un request sin el token, y deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                response = client.get(
                    '/materias/90028/recursantes?carrera=TEST')
                self.assertEqual(response.status_code, 401)

    def test_recursantes(self):
        """
			Hago un request con token, deberia darme los recursantes
			Chequeo que el alumno con legajo 1 haya recursado 2 veces
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/materias/90028/recursantes?carrera=TEST',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data[0]["Legajo"], '1')
                self.assertEqual(data[0]["Cantidad"], 2)

    def test_detalle_aprobados_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/materias/90028/detalle-aprobados?carrera=TEST')
                self.assertEqual(response.status_code, 401)

    def test_detalle_aprobados(self):
        """
			Hago un request con token
			Deberia darme un solo resultado, el alumno con legajo 10
			Que promociono en otra carrera
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/materias/90028/detalle-aprobados?carrera=TEST',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data[0]['Promocion en otra carrera'], 1)

    def test_basicos_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get('/materias/90028/basicos?carrera=TEST')
                self.assertEqual(response.status_code, 401)

    def test_basicos_aprobados(self):
        """
			Hago un request con token
			Segun los datos, hay un solo aprobado
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/materias/90028/basicos?carrera=TEST',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data[0]['Aprobados'], 1)

    def test_basicos_ausentes(self):
        """
			Hago un request con token
			Segun los datos, no hay ausentes
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/materias/90028/basicos?carrera=TEST',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data[0]['Ausentes'], 0)

    def test_basicos_desaprobados(self):
        """
			Hago un request con token
			Segun los datos, hay 4 desaprobados
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/materias/90028/basicos?carrera=TEST',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data[0]['Desaprobados'], 4)

    def test_basicos_faltantes(self):
        """
			Hago un request con token
			Segun los datos, hay 9 faltantes
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/materias/90028/basicos?carrera=TEST',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data[0]['Faltantes'], 9)

    def test_dispersion_notas_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/materias/90028/dispersion-notas?carrera=TEST')
                self.assertEqual(response.status_code, 401)

    def test_dispersion_notas(self):
        """
			Hago un request con token
			Devuelvo la primer nota, que deberia ser 2
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/materias/90028/dispersion-notas?carrera=TEST',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data[0]['Nota'], '2')

    def test_porcentajes_areas_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumnos/1/porcentajes-areas?carrera=TEST&plan=2019')
                self.assertEqual(response.status_code, 401)

    def test_porcentajes_areas(self):
        """
			Hago un request con token
			Deberia tener un 50 de ingles
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumnos/1/porcentajes-areas?carrera=TEST&plan=2019',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                for materia in data:
                    if materia['nombre'] == 'Inglés':
                        self.assertEqual("%.2f" % materia['valor'], '50.00')

    def test_porcentajes_nucleos_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumnos/1/porcentajes-nucleos?carrera=TEST&plan=2019')
                self.assertEqual(response.status_code, 401)

    def test_porcentajes_nucleos(self):
        """
			Hago un request con token
			Deberia tener un 33.33 del ingreso
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumnos/1/porcentajes-nucleos?carrera=TEST&plan=2019',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                for nucleo in data:
                    if nucleo['nombre'] == 'I':
                        self.assertEqual("%.2f" % nucleo['valor'], '33.33')

    def test_alumnos_carrera_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get('/carreras/TEST/alumnos?plan=2019')
                self.assertEqual(response.status_code, 401)

    def test_alumnos_carrera(self):
        """
			Hago un request con token
			Deberia darme 10 alumnos
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/alumnos?plan=2019',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data[0]['cantidad'], 10)

    def test_cantidades_alumnos_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/cantidades-alumnos?plan=2019')
                self.assertEqual(response.status_code, 401)

    def test_cantidades_alumnos_graduados(self):
        """
			Hago un request con token
			Deberia recibir [..., {'Cohorte': 2019, 'Graduados': 1, 'Cursantes': 10, 'Ingresantes': 2}]
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/cantidades-alumnos?plan=2019',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                for cohorte in data:
                    if cohorte['Cohorte'] == 2019:
                        self.assertEqual(cohorte['Graduados'], 1)

    def test_cantidades_alumnos_ingresantes(self):
        """
			Hago un request con token
			Deberia recibir [..., {'Cohorte': 2019, 'Graduados': 1, 'Cursantes': 10, 'Ingresantes': 2}]
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/cantidades-alumnos',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                for cohorte in data:
                    if cohorte['Cohorte'] == 2019:
                        self.assertEqual(cohorte['Ingresantes'], 2)

    def test_cantidades_alumnos_cursantes(self):
        """
			Hago un request con token
			Deberia recibir [..., {'Cohorte': 2019, 'Graduados': 1, 'Cursantes': 10, 'Ingresantes': 2}]
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/cantidades-alumnos',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                for cohorte in data:
                    if cohorte['Cohorte'] == 2019:
                        self.assertEqual(cohorte['Cursantes'], 10)

    def test_cantidades_ingresantes_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get('/carreras/TEST/cantidades-ingresantes')
                self.assertEqual(response.status_code, 401)

    def test_cantidades_ingresantes(self):
        """
			Hago un request con token
			Deberia recibir [..., {'Cohorte': 2019, 'Ingresantes': 2}]
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/cantidades-ingresantes',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                for cohorte in data:
                    if cohorte['Cohorte'] == 2019:
                        self.assertEqual(cohorte['Ingresantes'], 2)

    def test_cursantes_actual_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get('/carreras/TEST/cursantes-actual')
                self.assertEqual(response.status_code, 401)

    def test_cursantes_actual(self):
        """
			Hago un request con token
			Deberia recibir {'nombre': 'Cursantes del año actual', 'valor': 10}
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/cursantes-actual',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data['valor'], 10)

    def test_ingresantes_actual_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get('/carreras/TEST/ingresantes-actual')
                self.assertEqual(response.status_code, 401)

    def test_ingresantes_actual(self):
        """
			Hago un request con token
			Deberia recibir {'nombre': 'Ingresantes del año actual', 'valor': 2}
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/ingresantes-actual',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data['valor'], 2)

    def test_graduados_total_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get('/carreras/TEST/graduados-total')
                self.assertEqual(response.status_code, 401)

    def test_graduados_total(self):
        """
			Hago un request con token
			Deberia recibir {'nombre': 'Graduados', 'valor': 1}
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/graduados-total',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data['valor'], 1)

    def test_notas_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumnos/1/notas?carrera=TEST&plan=2019')
                self.assertEqual(response.status_code, 401)

    '''
	def test_notas(self):
		"""
			Hago un request con token
			Deberia recibir [... {'Fecha': '2018-02-07', 'Materia': 'Inglés II', 'Plan': 2019, 'Nota': '3'}]
		"""
		with self.mock_app.run(self.mock_url, self.mock_port):
			with test_app.test_client() as client:
				token = self.provider.retrieve_token()
				response = client.get('/alumnos/1/notas?carrera=TEST&plan=2019', headers={"Authorization": f"Bearer {token}"})
				data = json.loads(response.data)
				for materia in data:
					if materia['Materia'] == 'Inglés II' and materia['Fecha'] == '2018-02-07':
						self.assertEqual(materia['Nota'], '3')
	'''

    def test_scores_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumnos/1/scores?carrera=TEST&plan=2019')
                self.assertEqual(response.status_code, 401)

    def test_scores(self):
        """
			Hago un request con token
			Deberia recibir [{'nombre': '2017-S2', 'valor': 3.0}, {'nombre': '2018-S2', 'valor': 5.666666666666667}]
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumnos/1/scores?carrera=TEST&plan=2019',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                print(data)
                for score in data:
                    if score['nombre'] == '2017-S2':
                        self.assertEqual(score['valor'], 3)

    def test_porcentaje_carrera_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumnos/1/porcentaje-carrera?carrera=TEST&plan=2019')
                self.assertEqual(response.status_code, 401)

    def test_porcentaje_carrera(self):
        """
			Hago un request con token
			Deberia recibir {"nombre": "Porcentaje de avance", "valor": 5.0} porque tiene aprobadas 2 de 40
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumnos/1/porcentaje-carrera?carrera=TEST&plan=2019',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data['valor'], '5.0')

    def test_dispersion_score_unauthorized(self):
        """
			Hago un request sin token, deberia darme 401
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/dispersion-score-promedio?dias=18250')
                self.assertEqual(response.status_code, 401)

    def test_dispersion_score_carrera(self):
        """
			Hago un request con token
			Si hay datos de los ultimos 365 dias, deberia recibir [... {'Promedio': '7', 'Alumno': '9', 'Score': 2.0}]
			Como los datos son fijos, este test dejaria de andar en el año 2070
		"""
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/carreras/TEST/dispersion-score-promedio?dias=18250',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                for alumno in data:
                    if alumno['Alumno'] == '9':
                        self.assertEqual(alumno['Score'], 2)

    def test_getStudent(self):
        with self.mock_app.run(self.mock_url, self.mock_port):
            with test_app.test_client() as client:
                token = self.provider.retrieve_token()
                response = client.get(
                    '/alumno/16921',
                    headers={"Authorization": f"Bearer {token}"})
                data = json.loads(response.data)
                self.assertEqual(data.get('nombre'), 'Estudiante')
                self.assertEqual(data.get('valor'), 'Nestor Munoz')