def test_is_authenticated(self): """ Test our custom User.is_authenticated property. """ # create past and future dates past = timezone.now() - timezone.timedelta(days=1) future = timezone.now() + timezone.timedelta(days=1) # create some users user_with_tokens = UserFactory.create( username='******', email='*****@*****.**', access_token='1', refresh_token='2', token_expiry=future) user_with_expired_tokens = UserFactory.create( username='******', email='*****@*****.**', access_token='1', refresh_token='2', token_expiry=past) user_without_tokens = UserFactory.create( username='******', email='*****@*****.**', access_token='', refresh_token='2', token_expiry=future) user_without_refresh_token = UserFactory.create( username='******', email='*****@*****.**', access_token='1', refresh_token='', token_expiry=future) # check authenticated status for each user self.assertTrue(user_with_tokens.is_authenticated) self.assertFalse(user_with_expired_tokens.is_authenticated) self.assertFalse(user_without_tokens.is_authenticated) self.assertFalse(user_without_refresh_token.is_authenticated)
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_conflicting_user_with_same_email_is_not_reused(self): """ If there's an existing User with the right email address but a different oauth_user_id, then the existing user should have its email field wiped (because it's unqiue) and a new user should be created and returned. """ user = UserFactory.create(oauth_user_id='9999', email='*****@*****.**') user_info = dict(id='12345', email='*****@*****.**', given_name='Rob', family_name='Charlwood', name='Rob Charlwood') backend = OauthenticationBackend() with mock.patch('accounts.backends.get_user_info', return_value=user_info): result = backend.authenticate(oauth_credentials=MockCredentials()) # It should have created a new user self.assertNotEqual(result, user) self.assertEqual(get_user_model().objects.count(), 2) # The existing user should now have a blank 'email' field user.refresh_from_db() self.assertEqual(user.email, '') # We should get a new user object with correct email & oauth_user_id self._check_user_info_values_match_user_fields(user_info, result) # And because it created a new user via oauth, it shouldn't have a # usable password self._check_has_unusable_password(result)
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_existing_user_is_returned_and_updated(self): """ If there's an existing User with the same User ID as that of the fetched user profile, then the existing User should be returned but updated with latest profile info. """ user = UserFactory.create(oauth_user_id='12345') user_info = dict(id='12345', email='*****@*****.**', given_name='Rob', family_name='Charlwood', name='Rob Charlwood') backend = OauthenticationBackend() with mock.patch('accounts.backends.get_user_info', return_value=user_info): result = backend.authenticate(oauth_credentials=MockCredentials()) self.assertEqual(result, user) # Now check that # (1) the returned user has been updated with the latest profile info # (2) User object in the DB has been updated with latest profile info user.refresh_from_db() for user_obj in result, user: self._check_user_info_values_match_user_fields(user_info, result) self._check_user_info_values_match_user_fields(user_info, user)
def test_pre_created_user_is_matched_by_email(self): """ If there's an existing User with the right email address but a username of None, then this is a pre-created User, which should be updated with the User ID and returned. """ user = UserFactory.create(oauth_user_id=None, email='*****@*****.**') user_info = dict(id='12345', email='*****@*****.**', given_name='Rob', family_name='Charlwood', name='Rob Charlwood') backend = OauthenticationBackend() with mock.patch('accounts.backends.get_user_info', return_value=user_info): result = backend.authenticate(oauth_credentials=MockCredentials()) # It should have used the existing user but updated it with the new # profile values self.assertEqual(result, user) # Now check that # (1) the returned user has been updated with the latest profile info # (2) User object in the DB has been updated with latest profile info user.refresh_from_db() for user_obj in result, user: self._check_user_info_values_match_user_fields(user_info, result) self._check_user_info_values_match_user_fields(user_info, user)
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 test_step_two_log_in_fails(self): factory = RequestFactory() request = factory.get('/') request.session = {} user = UserFactory.create() with mock.patch('accounts.views.messages.error') as messages_error: with mock.patch(mock_step_two, return_value=MockCredentials()): with mock.patch( 'accounts.views.auth.authenticate', return_value=user ) as authenticate: with mock.patch('accounts.views.auth.login') as login_mock: authenticate.return_value = None response = OauthStepTwo.as_view()(request) self.assertTrue(authenticate.called) self.assertTrue(messages_error.called) self.assertFalse(login_mock.called) self.assertEqual( messages_error.call_args[0][1], 'Try connecting your account again.' ) # And we expect it to redirect us on to the login view self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], settings.LOGIN_URL)
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_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_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_reset_tokens(self): user_with_tokens = UserFactory.create( username='******', email='*****@*****.**', access_token='1', refresh_token='2', token_expiry=timezone.now()) user_with_tokens.reset_tokens() user_with_tokens.refresh_from_db() self.assertEquals('', user_with_tokens.access_token) self.assertEquals('', user_with_tokens.refresh_token)
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_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 fill_db(self, range): for i in range: u = UserFactory.create() u.profile.rrhh_code = i u.profile.save() a = Articulo(titulo="ArtName" + str(i), fecha=datetime.date(randint(2012, 2014), 1, 1)) a.save() a.user_profile.add(u.profile) a = Capitulo(titulo="CapName" + str(i), fecha=datetime.date(randint(2012, 2014), 1, 1)) a.save() a.user_profile.add(u.profile) a = Libro(titulo="LibName" + str(i), fecha=datetime.date(randint(2012, 2014), 1, 1)) a.save() a.user_profile.add(u.profile) a = Congreso(titulo="ConName" + str(i), fecha_de_inicio=datetime.date(randint(2012, 2014), 1, 1)) a.save() a.user_profile.add(u.profile) a = Convenio(titulo="ConvName" + str(i), fecha_de_inicio=datetime.date(randint(2012, 2014), 1, 1)) a.save() a.user_profile.add(u.profile) a = Patente(titulo="PatName" + str(i), fecha=datetime.date(randint(2012, 2014), 1, 1)) a.save() a.user_profile.add(u.profile) a = Proyecto(titulo="ProName" + str(i), fecha_de_inicio=datetime.date(randint(2012, 2014), 1, 1)) a.save() a.user_profile.add(u.profile) a = TesisDoctoral(titulo="TesisName" + str(i), fecha=datetime.date(randint(2012, 2014), 1, 1)) a.save() a.user_profile.add(u.profile)
def test_is_authenticated_refresh_required(self): """ Test our custom User.is_authenticated property. """ # create past past = timezone.now() - timezone.timedelta(days=1) # create a user who token has expired user_with_tokens = UserFactory.create( username='******', email='*****@*****.**', access_token='1', refresh_token='2', token_expiry=past) # adding this because of random No route to host errors with mock.patch( 'accounts.models.OAuth2Credentials') as mock_oauth: mock_oauth.return_value = MockCredentials(access_token='foo') self.assertTrue(user_with_tokens.is_authenticated)
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 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 _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_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_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_step_two_logs_user_in(self): factory = RequestFactory() request = factory.get('/') request.session = {} user = UserFactory.create() with mock.patch(mock_step_two, return_value=MockCredentials()): with mock.patch( 'accounts.views.auth.authenticate', return_value=user ) as authenticate: with mock.patch('accounts.views.auth.login') as login_mock: response = OauthStepTwo.as_view()(request) self.assertTrue(authenticate.called) self.assertTrue(login_mock.called) # And we expect it to redirect us on to the dashboard view self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], settings.LOGIN_REDIRECT_URL)
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 _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_existing_token_missing_tz(self): user = UserFactory.create(oauth_user_id='12345') user_info = dict(id='12345', email='*****@*****.**', given_name='Rob', family_name='Charlwood', name='Rob Charlwood') backend = OauthenticationBackend() with mock.patch('accounts.backends.get_user_info', return_value=user_info): result = backend.authenticate(oauth_credentials=MockCredentials( token_expiry=datetime.datetime.now())) self.assertEqual(result, user) # Now check that # (1) the returned user has been updated with the latest profile info # (2) User object in the DB has been updated with latest profile info user.refresh_from_db() for user_obj in result, user: self._check_user_info_values_match_user_fields(user_info, result) self._check_user_info_values_match_user_fields(user_info, user)
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_unicode(self): user = UserFactory.create( full_name="John Smith", email="*****@*****.**") self.assertEquals(unicode(user), "*****@*****.**")