class NotificationTests(TestCase): def setUp(self): settings.NOTIFICATION_OPTIONS = dict( TEST_NOTIFICATION=dict( caller='notification', template='notification_test_template.html', subject='Notification test template' ) ) self.package = dict( caller='notifications', notification_type='TEST_NOTIFICATION', recipients=['dummy_mail@dummy_host.com', ], context=dict( dummy_data='dummy_data' ) ) # noinspection PyUnresolvedReferences def tearDown(self): del settings.NOTIFICATION_OPTIONS # noinspection PyUnresolvedReferences def test_notification_options(self): self.notification = Notification(**self.package) self.notification.send() self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, 'Notification test template') self.assertTrue('dummy_data' in mail.outbox[0].body)
def post(self, request, token=None): user = check_token(token) password = request.data.get('new_password', '') if not password: return Response( dict(status="error", error_code="new_password_required", message="You haven't provided a new password.")) # if we have a valid user if user: # check if the submitted password complies with the password_enforce_format pass_check = password_enforce_format(password) if pass_check: user.set_password(password) user.save() return Response( dict(status="error", error_code="invalid_password_format", message=pass_check)) else: package = dict( caller='jwt_auth', notification_type='RESET_PASSWORD_CONFIRMATION', recipients=[user.email, ], context=dict( username=user.username, password=password ) ) notify = Notification(**package) notify.send() return Response(dict(status="success", message="Password has been successfully reset")) else: return Response( dict(status="error", error_code="invalid_token", message="The token you provided is invalid or has expired."))
def post(self, request): user = User.objects.filter(email=request.data['email']).first() if user: package = dict( caller='jwt_auth', notification_type='FORGOT_PASSWORD', recipients=[user.email, ], context=dict( token=new_token(user), user=user.get_full_name() ) ) notify = Notification(**package) notify.send() return Response( dict(status="success", message="An email containing the password reset instruction to: \"%s\"" % ( user.email))) else: return Response({ "status": "no_registered_user" })