bugfix in test, better error handling in mail sending
This commit is contained in:
parent
5e8c99354e
commit
db74d3db5e
2
TODO
2
TODO
|
@ -1,5 +1,3 @@
|
|||
* remove dot before "Nextcloud" at login page.
|
||||
|
||||
* better error handling with mail sending.
|
||||
|
||||
* test for complete run with all forms
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.test import TestCase
|
||||
from django.test import Client
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
|
||||
from .forms import ITForm
|
||||
|
||||
|
@ -16,6 +17,7 @@ class LoginTestCase(TestCase):
|
|||
|
||||
def testDebugWarning(self):
|
||||
with self.settings(DEBUG=True):
|
||||
self.response = self.client.get('/')
|
||||
self.assertContains(self.response, "WARNUNG! Test-MODUS aktiviert. Es werden keine Mails verschickt!", status_code=200)
|
||||
|
||||
|
||||
|
|
|
@ -83,10 +83,10 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView):
|
|||
|
||||
#print('GETCONTEXT')
|
||||
context = super().get_context_data(form=form, **kwargs)
|
||||
#testmode = settings.DEBUG or settings.MAILTEST
|
||||
testmode = settings.DEBUG or settings.MAILTEST
|
||||
context.update({'choice': self.choice,
|
||||
'choice_string': TYPE_CHOICES[self.choice],
|
||||
'TESTMODE': settings.DEBUG or settings.MAILTEST})
|
||||
'TESTMODE': testmode})
|
||||
|
||||
# deliver context for forms if we are in the last step
|
||||
if (self.steps.step1 == 5 or (self.choice != 'IN' and self.steps.step1 == 3)):
|
||||
|
@ -95,7 +95,7 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView):
|
|||
return context
|
||||
|
||||
def get_form_instance(self,step):
|
||||
''' this method makes shure, that we use the same model instance for all steps'''
|
||||
''' this method assures, that we use the same model instance for all steps'''
|
||||
|
||||
if self.instance == None:
|
||||
self.instance = Employee()
|
||||
|
@ -114,12 +114,15 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView):
|
|||
|
||||
# send data to departments
|
||||
for dep in MAILS:
|
||||
self.send_mail_to_department(dep)
|
||||
response = self.send_mail_to_department(dep)
|
||||
|
||||
if not settings.DEBUG:
|
||||
self.instance.delete()
|
||||
|
||||
return HttpResponseRedirect('success')
|
||||
if response:
|
||||
return response
|
||||
else:
|
||||
return HttpResponseRedirect('success')
|
||||
|
||||
|
||||
def send_mail_to_department(self, department):
|
||||
|
@ -152,12 +155,19 @@ class EvaFormView(LoginRequiredMixin, CookieWizardView):
|
|||
EVA_MAIL,
|
||||
[MAILS[department]['MAIL'], contact],
|
||||
fail_silently=False)
|
||||
except BadHeaderError:
|
||||
except BadHeaderError as error:
|
||||
print(error)
|
||||
self.instance.delete()
|
||||
return HttpResponse('Invalid header found. Data not saved!')
|
||||
except SMTPException:
|
||||
return HttpResponse(f'{error}<p>Invalid header found. Data not saved!')
|
||||
except SMTPException as error:
|
||||
print(error)
|
||||
self.instance.delete()
|
||||
return HttpResponse('Error in sending mails (propably wrong adress?). Data not saved!')
|
||||
return HttpResponse(f'{error}<p>Error in sending mails (propably wrong adress?). Data not saved!')
|
||||
except Exception as error:
|
||||
print(error)
|
||||
# self.instance.delete()
|
||||
return HttpResponse(f'{error}<p>Error in sending mails. Data not saved! Please contact ' + EVA_MAIL)
|
||||
return False
|
||||
|
||||
def beautify_data(self, data):
|
||||
''' # use long form for contextdata instead of short form if available
|
||||
|
|
Loading…
Reference in New Issue