import unittest

from ucuenca.ucuenca import Ucuenca
from ucuenca.ucuenca import UcuencaException


class TestUcuenca(unittest.TestCase):
    def setUp(self):
        self.ucuenca = Ucuenca()

    def test_academic_record(self):
        """Check 0706455136's academic_record."""
        student_id = '0706455136'
        expected_result = self._get_academic_record(student_id)
        actual_result = self.ucuenca.academic_record(student_id)
        self.assertEqual(expected_result, actual_result)

    def test_academic_record_invalid_student(self):
        """Check invalid student's academic record."""
        student_id = '1234567890'
        with self.assertRaises(UcuencaException) as e:
            self.ucuenca.academic_record(student_id)
        self.assertEqual(404, e.exception.status_code)

    def test_academic_record_lower_case_keys(self):
        """Check 0706455136's academic_record with lower case keys."""
        student_id = '0706455136'
        expected_result = self._get_academic_record(student_id)
        expected_result = {k.lower(): v  for k, v in expected_result.items()}
        self.ucuenca.lowercase_keys = True
        actual_result = self.ucuenca.academic_record(student_id)
        self.assertEqual(expected_result, actual_result)


    def _get_academic_record(self, student_id):
        academic_records = {
            '0706455136': {"PERSONA_ID":"0706455136","NOMBRE":"GALLEGOS CEVILLA SANTOS EDUARDO","MALLA":"MALLA MODERNA SISTEMAS 2013","PLACAR_ID":1,"FECHA_MATRICULA":"2016-08-30 12:59:18.0","SECCION":"GENERAL","ESTADO_MATRICULA":"MATRICULADO","ESTA_ANULADA":"N","CARRERA_ID":37,"PERIODO_LECTIVO":"SEPTIEMBRE 2016-FEBRERO 2017","CARRERA":"INGENIERIA DE SISTEMAS","NIVEL_NUMERO":2,"PERLEC_ID":115,"NRO_MATRICULA":13074,"FACULTAD":"FACULTAD DE INGENIER&Iacute;A","SECCIONID":4,"ESGRATUITA":"SI","MALLA_ID":7,"PLAN_CARRERA":"PLAN DE CARRERA DE SISTEMAS CREDITOS 2008"}
        }
        return academic_records[student_id]

@@ -236,33 +236,33 @@
   %22%22%22Check 0
-706455136
+104926787
 's academic_
@@ -291,33 +291,33 @@
 dent_id = '0
-706455136
+104926787
 '%0A        ex
@@ -868,25 +868,25 @@
 %22Check 0
-706455136
+104926787
 's acade
@@ -944,25 +944,25 @@
 _id = '0
-706455136
+104926787
 '%0A      
@@ -1355,25 +1355,25 @@
       '0
-706455136
+104926787
 ': %7B%22PER
@@ -1387,17 +1387,17 @@
 %22:%220
-706455136
+104926787
 %22,%22N
@@ -1408,77 +1408,84 @@
 E%22:%22
-G
 AL
-LEGOS CEVILLA SANTOS EDUARDO%22,%22MALLA%22:%22MALLA MODERNA SISTEMAS 2013
+VAREZ BARROS PAOLA KATHERINE%22,%22MALLA%22:%22MALLA CONTABILIDAD Y AUDITORIA 2008
 %22,%22P
@@ -1494,17 +1494,17 @@
 CAR_ID%22:
-1
+4
 ,%22FECHA_
@@ -1522,23 +1522,23 @@
 %22201
-6-08-30 12:59:1
+3-03-03 09:37:0
 8.0%22
@@ -1623,18 +1623,18 @@
 ERA_ID%22:
-37
+44
 ,%22PERIOD
@@ -1649,36 +1649,28 @@
 O%22:%22
-SEPTIEMBRE 2016-FEBRERO 2017
+MARZO2013-AGOSTO2013
 %22,%22C
@@ -1682,30 +1682,32 @@
 A%22:%22
-INGENIERIA DE SISTEMAS
+CONTABILIDAD Y AUDITORIA
 %22,%22N
@@ -1719,17 +1719,17 @@
 NUMERO%22:
-2
+6
 ,%22PERLEC
@@ -1738,10 +1738,10 @@
 D%22:1
-15
+08
 ,%22NR
@@ -1757,13 +1757,12 @@
 LA%22:
-13074
+8151
 ,%22FA
@@ -1786,25 +1786,52 @@
  DE 
-INGENIER&Iacute;A
+CIENCIAS ECON&Oacute;MICAS Y ADMINISTRATIVAS
 %22,%22S
@@ -1856,18 +1856,18 @@
 TUITA%22:%22
-SI
+NO
 %22,%22MALLA
@@ -1871,17 +1871,17 @@
 LLA_ID%22:
-7
+1
 ,%22PLAN_C
@@ -1898,39 +1898,32 @@
 LAN 
-DE CARRERA DE SISTEMAS CRE
+CONTABILIDAD Y AU
 DITO
-S
+RIA
  200

Update tests