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_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)