def test_get_pdf_ull_filter_by_date(self): user = UserFactory.create() user.profile.rrhh_code = 'example_code' user.profile.documento = 'example_codeL' pdf = CVN.get_user_pdf_ull(user=user) cvn = CVN(user=user, pdf=pdf) cvn.xml_file.open() self.assertEqual(len(etree.parse(cvn.xml_file).findall('CvnItem')), 3) pdf = CVN.get_user_pdf_ull(user=user) cvn = CVN(user=user, pdf=pdf) cvn.xml_file.open() self.assertEqual(len(etree.parse(cvn.xml_file).findall('CvnItem')), 3) pdf = CVN.get_user_pdf_ull( user=user, start_date=datetime.date(2012, 1, 1)) cvn = CVN(user=user, pdf=pdf) cvn.xml_file.open() self.assertEqual(len(etree.parse(cvn.xml_file).findall('CvnItem')), 1) pdf = CVN.get_user_pdf_ull( user=user, end_date=datetime.date(2010, 1, 1)) cvn = CVN(user=user, pdf=pdf) cvn.xml_file.open() self.assertEqual(len(etree.parse(cvn.xml_file).findall('CvnItem')), 2) pdf = CVN.get_user_pdf_ull( user=user, start_date=datetime.date(2006, 1, 1), end_date=datetime.date(2011, 1, 1)) cvn = CVN(user=user, pdf=pdf) cvn.xml_file.open() self.assertEqual(len(etree.parse(cvn.xml_file).findall('CvnItem')), 2)
def test_update_from_xml(self): us = UserFactory.create() cvn = CVN(user=us) xml_file = file(os.path.join(st_cvn.FILE_TEST_ROOT, 'xml/CVN-Test.xml')) cvn.update_from_xml(xml_file.read()) self.assertTrue(cvn.xml_file and cvn.cvn_file)
def test_get_pdf_ull_learning(self): user = UserFactory.create() user.profile.rrhh_code = 'example_code' user.profile.documento = 'example_codeL' pdf = CVN.get_user_pdf_ull(user=user) cvn = CVN(user=user, pdf=pdf) cvn.xml_file.open() cvn_items = etree.parse(cvn.xml_file).findall('CvnItem') ws_content = CachedWS.get(st.WS_ULL_LEARNING % 'example_code') for w in ws_content: CVN._clean_data_learning(w) if u'des1_grado_titulacion' in w: w[u'des1_grado_titulacion'] = w[u'des1_grado_titulacion'].upper() if w[u'des1_grado_titulacion'] == u'DOCTOR': del w[u'des1_grado_titulacion'] pdf_content = [] for item in cvn_items: pdf_content.append(parse_cvnitem(item)) self.assertEqual(len(ws_content), len(pdf_content)) allequal = True for wi in ws_content: equal = False for pi in pdf_content: if cmp(wi, pi) == 0: equal = True if not equal: allequal = False self.assertTrue(allequal)
def test_get_pdf_ull_cargos(self): user = UserFactory.create() user.profile.rrhh_code = 'example_code' user.profile.documento = 'example_codeL' pdf = CVN.get_user_pdf_ull(user=user) cvn = CVN(user=user, pdf=pdf) cvn.xml_file.open() cvn_items = etree.parse(cvn.xml_file).findall('CvnItem') ws_content = CachedWS.get(st.WS_ULL_CARGOS % 'example_code') for w in ws_content: CVN._clean_data_profession(w) if not u'employer' in w: w[u'employer'] = u'Universidad de La Laguna' pdf_content = [] for item in cvn_items: pdf_content.append(parse_cvnitem(item)) self.assertEqual(len(ws_content), len(pdf_content)) allequal = True for wi in ws_content: equal = False for pi in pdf_content: if cmp(wi, pi) == 0: equal = True if not equal: allequal = False self.assertTrue(allequal)
def test_insert_xml_ull(self): """ Insert the data of XML in the database """ user = UserFactory.create() cvn = CVN(user=user, pdf_path=get_cvn_path('CVN-ULL')) cvn.insert_xml() self.assertEqual(user.profile.articulo_set.count(), 1214) self.assertEqual(user.profile.libro_set.count(), 6) self.assertEqual(user.profile.capitulo_set.count(), 32) self.assertEqual(user.profile.congreso_set.count(), 55) self.assertEqual(user.profile.convenio_set.count(), 38) self.assertEqual(user.profile.proyecto_set.count(), 11) self.assertEqual(user.profile.tesisdoctoral_set.count(), 0)
def test_on_insert_cvn_old_pdf_is_moved(self): user = UserFactory.create() cvn = CVN(user=user, pdf_path=get_cvn_path('CVN-Test')) cvn.save() filename = cvn.cvn_file.name.split('/')[-1].replace( u'.pdf', u'-' + str(cvn.uploaded_at.strftime('%Y-%m-%d-%Hh%Mm%Ss')) + u'.pdf') old_cvn_path = os.path.join( '/'.join(cvn.cvn_file.path.split('/')[:-1]), 'old', filename) CVN(user=user, pdf_path=get_cvn_path('CVN-Test')) self.assertTrue(os.path.isfile(old_cvn_path)) self.assertEqual( OldCvnPdf.objects.filter(user_profile=user.profile, uploaded_at=cvn.uploaded_at).count(), 1)
def test_cvnitem_learning_factory(self): user = UserFactory.create() parser = CvnXmlWriter(user) cvnitem_dict = {} # Insert Phd the researcher has received for i in range(0, 10): d = LearningPhdFactory.create() cvnitem_dict[d[u'des1_titulacion']] = d if u'des1_organismo' in d and d[u'des1_organismo'] is None: del d[u'des1_organismo'] parser.add_learning_phd(**d) # Insert bachelor, degree...data for i in range(0, 10): d = LearningFactory.create() cvnitem_dict[d[u'des1_titulacion']] = d if u'des1_organismo' in d and d[u'des1_organismo'] is None: del d[u'des1_organismo'] parser.add_learning(**d) cvn = CVN.create(user, parser.tostring()) cvn.xml_file.open() cvn_items = etree.parse(cvn.xml_file).findall('CvnItem') for item in cvn_items: cvnitem = parse_cvnitem(item) self.assertEqual( cmp(cvnitem, cvnitem_dict[cvnitem[u'des1_titulacion']]), 0) self.assertNotEqual(cvn, None)
def _get_one_cargo_ull(self): user = UserFactory.create() user.profile.rrhh_code = 'example_code' user.profile.documento = 'example_codeL' pdf = CVN.get_user_pdf_ull(user=user) cvn = CVN(user=user, pdf=pdf) cvn.xml_file.open() cvn_items = etree.parse(cvn.xml_file).findall('CvnItem') self.assertEqual(len(cvn_items), 1) item = parse_cvnitem(cvn_items[0]) ws_content = CachedWS.get(st.WS_ULL_CARGOS % 'example_code') self.assertEqual(len(ws_content), 1) w = ws_content[0] CVN._clean_data_profession(w) if not u'employer' in w: w[u'employer'] = u'Universidad de La Laguna' self.assertEqual(cmp(item, w), 0)
def test_insert_patentes(self): u = UserFactory.create() cvn = CVN(user=u, pdf_path=get_cvn_path('cvn-patentes')) cvn.insert_xml() patente = Patente.objects.get(num_solicitud=111111111111111) self.assertEqual(patente.titulo, "Patente uno") self.assertEqual(patente.fecha, datetime.date(2011, 01, 01)) self.assertEqual(patente.fecha_concesion, datetime.date(2011, 01, 02)) self.assertEqual(patente.lugar_prioritario, u'Canarias, Spain') self.assertEqual(patente.lugares, u'Israel; Andalucía, Spain') self.assertEqual(patente.autores, u'Judas Iscariote (JI); Juan Rodríguez González') self.assertEqual(patente.entidad_titular, u'BANCO POPULAR ESPAÑOL, S.A.') self.assertEqual(patente.empresas, u'Banco Pastor; CEMUSA CORPORACION EUROPEA DE ' 'MOBILIARIO URBANO SA')
def _get_one_learning_ull(self): user = UserFactory.create() user.profile.rrhh_code = 'example_code' user.profile.documento = 'example_codeL' pdf = CVN.get_user_pdf_ull(user=user) cvn = CVN(user=user, pdf=pdf) cvn.xml_file.open() cvn_items = etree.parse(cvn.xml_file).findall('CvnItem') self.assertEqual(len(cvn_items), 1) item = parse_cvnitem(cvn_items[0]) ws_content = CachedWS.get(st.WS_ULL_LEARNING % 'example_code') self.assertEqual(len(ws_content), 1) wi = ws_content[0] CVN._clean_data_learning(wi) if u'des1_grado_titulacion' in wi: wi[u'des1_grado_titulacion'] = wi[u'des1_grado_titulacion'].upper() if wi[u'des1_grado_titulacion'] == u'DOCTOR': del wi[u'des1_grado_titulacion'] if not u'des1_organismo' in wi: wi[u'des1_organismo'] = u'Universidad de La Laguna' self.assertEqual(cmp(item, wi), 0)
def test_number_of_articles(self): cvn = CVN(xml_file=self.xml_ull) cvn.xml_file.seek(0) u = UserFactory.create() items = etree.parse(cvn.xml_file).findall('CvnItem') count = 0 for item in items: cvn_key = item.find('CvnItemID/CVNPK/Item').text.strip() try: subtype = item.find('Subtype/SubType1/Item').text.strip() except AttributeError: subtype = '' if cvn_key == '060.010.010.000' and subtype == '035': count += 1 Articulo.objects.create(item, u.profile) self.assertEqual(count, 1214) self.assertEqual(Articulo.objects.all().count(), 1214)
def test_cvnitem_teaching_factory(self): user = UserFactory.create() parser = CvnXmlWriter(user) cvnitem_dict = {} # Insert teaching data for i in range(0, 10): d = TeachingFactory.create() cvnitem_dict[d[u'asignatura']] = d parser.add_teaching(**d) cvn = CVN.create(user, parser.tostring()) cvn.xml_file.open() cvn_items = etree.parse(cvn.xml_file).findall('CvnItem') for item in cvn_items: cvnitem = parse_cvnitem(item) self.assertEqual( cmp(cvnitem, cvnitem_dict[cvnitem[u'asignatura']]), 0) self.assertNotEqual(cvn, None)
def test_delete_producciones(self): user = UserFactory.create() cvn = CVN(user=user, pdf_path=get_cvn_path('CVN-Test')) cvn.insert_xml() cvn.remove_producciones() self.assertEqual(user.profile.articulo_set.count(), 0) self.assertEqual(user.profile.capitulo_set.count(), 0) self.assertEqual(user.profile.congreso_set.count(), 0) self.assertEqual(user.profile.convenio_set.count(), 0) self.assertEqual(user.profile.libro_set.count(), 0) self.assertEqual(user.profile.proyecto_set.count(), 0) self.assertEqual(user.profile.tesisdoctoral_set.count(), 0)
def test_check_read_data_publication(self): cvn = CVN(xml_file=self.xml_test) cvn.xml_file.seek(0) u = UserFactory.create() items = etree.parse(cvn.xml_file).findall('CvnItem') for item in items: tipo = _parse_produccion_type(item) subtipo = _parse_produccion_subtype(item) data = None if tipo == 'Publicacion': if subtipo == u'Articulo': data = Articulo.objects.create(item, u.profile) self.assertEqual(data.titulo, u'TÍTULO') self.assertEqual(data.nombre_publicacion, u'NOMBRE') self.assertEqual(data.autores, u'NOMBRE APELLIDO1 APELLIDO2 (STIC); ' 'NOMBRE2 APELLIDO12 APELLIDO22 (STIC2)') self.assertEqual(data.issn, u'0395-2037') if subtipo == u'Libro': data = Libro.objects.create(item, u.profile) self.assertEqual(data.titulo, u'Título de la publicación') self.assertEqual(data.nombre_publicacion, u'Nombre de la publicación') self.assertEqual(data.autores, u'Nombre Primer Apellido ' 'Segundo Apellido (STIC)') if subtipo == u'Capitulo': data = Capitulo.objects.create(item, u.profile) self.assertEqual(data.titulo, u'Título de la publicación') self.assertEqual(data.nombre_publicacion, u'Nombre de la publicación') self.assertEqual(data.autores, u'Nombre Primer Apellido ' 'Segundo Apellido (Firma)') self.assertEqual(data.issn, u'0395-2037') self.assertEqual(data.volumen, u'1') self.assertEqual(data.numero, u'1') self.assertEqual(data.pagina_inicial, u'1') self.assertEqual(data.pagina_final, u'100') self.assertEqual(data.fecha, datetime.date(2014, 04, 01))
def test_cvnitem_profession_factory(self): user = UserFactory.create() parser = CvnXmlWriter(user) cvnitem_dict = {} # Insert old and new professions in the CVN for i in range(0, 10): d = ProfessionFactory.create() for key in [u'des1_departamento', u'centro', u'des1_dedicacion']: if d[key] is None: del d[key] cvnitem_dict[d[u'des1_cargo']] = d parser.add_profession(**d) cvn = CVN.create(user, parser.tostring()) cvn.xml_file.open() cvn_items = etree.parse(cvn.xml_file).findall('CvnItem') for item in cvn_items: cvnitem = parse_cvnitem(item) self.assertEqual( cmp(cvnitem, cvnitem_dict[cvnitem[u'des1_cargo']]), 0) self.assertNotEqual(cvn, None)
def test_check_read_data_tesis(self): cvn = CVN(xml_file=self.xml_test) cvn.xml_file.seek(0) u = UserFactory.create() items = etree.parse(cvn.xml_file).findall('CvnItem') for item in items: tipo = _parse_produccion_type(item) if tipo == 'TesisDoctoral': data = TesisDoctoral.objects.create(item, u.profile) self.assertEqual(data.titulo, u'Título del trabajo') self.assertEqual(data.universidad_que_titula, u'Universidad que titula') self.assertEqual(data.autor, u'Nombre Primer Apellido ' 'Segundo Apellido (Firma)') self.assertEqual(data.codirector, u'Nombre Primer Apellido ' 'Segundo Apellido (Firma)') self.assertEqual(data.fecha, datetime.date(2014, 04, 01))
def test_check_read_data_project(self): cvn = CVN(xml_file=self.xml_test) cvn.xml_file.seek(0) u = UserFactory.create() items = etree.parse(cvn.xml_file).findall('CvnItem') for item in items: tipo = _parse_produccion_type(item) if tipo == 'Proyecto' or tipo == 'Convenio': data = {} if tipo == 'Proyecto': data = Proyecto.objects.create(item, u.profile) elif tipo == 'Convenio': data = Convenio.objects.create(item, u.profile) self.assertEqual(data.titulo, u'Denominación del proyecto') self.assertEqual(data.fecha_de_inicio, datetime.date(2014, 04, 01)) if tipo == 'Proyecto': self.assertEqual(data.fecha_de_fin, datetime.date(2015, 05, 02)) else: self.assertEqual(data.duracion, 396) if tipo == 'Proyecto': self.assertEqual(data.autores, u'Nombre Primer Apellido ' 'Segundo Apellido (Firma)') self.assertEqual(data.ambito, u'Internacional no UE') else: self.assertEqual(data.autores, u'Nombre Primer Apellido ' 'Segundo Apellido (STIC)') self.assertEqual(data.ambito, u'Autonómica') self.assertEqual(data.cod_segun_financiadora, u'Cód. según financiadora') self.assertEqual(data.cuantia_total, '1') self.assertEqual(data.cuantia_subproyecto, '1') self.assertEqual(data.porcentaje_en_subvencion, '1') self.assertEqual(data.porcentaje_en_credito, '1') self.assertEqual(data.porcentaje_mixto, '1')
def test_check_read_data_congress(self): cvn = CVN(xml_file=self.xml_test) cvn.xml_file.seek(0) u = UserFactory.create() items = etree.parse(cvn.xml_file).findall('CvnItem') for item in items: tipo = _parse_produccion_type(item) if tipo == 'Congreso': data = Congreso.objects.create(item, u.profile) self.assertEqual(data.titulo, u'Título') self.assertEqual(data.nombre_del_congreso, u'Nombre del congreso') self.assertEqual(data.fecha_de_inicio, datetime.date(2014, 04, 01)) self.assertEqual(data.fecha_de_fin, datetime.date(2014, 04, 05)) self.assertEqual(data.ciudad_de_realizacion, u'Ciudad de realización') self.assertEqual(data.autores, u'Nombre Primer Apellido ' 'Segundo Apellido (STIC)') self.assertEqual(data.ambito, u'Autonómica')
def test_update_from_pdf(self): us = UserFactory.create() cvn = CVN(user=us) pdf_file = file(get_cvn_path('CVN-Test')) cvn.update_from_pdf(pdf_file.read()) self.assertTrue(cvn.xml_file and cvn.cvn_file)
def test_contrato_dedicacion_ignore_case(self): ws_content = CachedWS.get(st.WS_ULL_CONTRATOS % 'example_code') w = ws_content[0] w[u'dedicacion'] = u'Tiempo completo' CVN._clean_data_profession(w) self.assertTrue(w[u'dedicacion'])
def test_dni_change(self): # LATEST CVN TEST user = UserFactory.create() cvn = CVN(user=user, pdf_path=get_cvn_path('CVN-Test')) cvn.save() user.profile.documento = '88888888O' user.profile.save() cvn.update_document_in_path() full_pdf_path = cvn.cvn_file.path full_xml_path = cvn.xml_file.path self.assertTrue(user.profile.documento in full_pdf_path) self.assertTrue(user.profile.documento in full_xml_path) self.assertTrue(os.path.isfile(full_pdf_path)) self.assertTrue(os.path.isfile(full_xml_path)) # OLD CVN TEST user_old = UserFactory.create() cvn2 = CVN(user=user_old, pdf_path=get_cvn_path('CVN-Test')) cvn2.save() CVN(user=user_old, pdf_path=get_cvn_path('CVN-Test')) user_old.profile.documento = '7777777D' user_old.save() cvn_old = user_old.profile.oldcvnpdf_set.all()[0] cvn_old.update_document_in_path() full_old_pdf_path = cvn_old.cvn_file.path self.assertTrue(user_old.profile.documento in full_old_pdf_path) self.assertTrue(os.path.isfile(full_old_pdf_path))
def test_productions_no_title(self): u = UserFactory.create() cvn = CVN(user=u, pdf_path=get_cvn_path('produccion_sin_titulo')) cvn.insert_xml() self.assertEqual(len(u.profile.proyecto_set.all()), 3) self.assertEqual(len(Articulo.objects.filter(user_profile__user=u)), 3)
def test_valid_identity_nif_without_letter(self): user = UserFactory.create() user.profile.documento = '11111111H' user.profile.save() cvn = CVN(user=user, pdf_path=get_cvn_path('CVN-NIF-sin_letra')) self.assertNotEqual(cvn.status, st_cvn.CVNStatus.INVALID_IDENTITY)