def test_anonymous_watch_with_email(self): form = WatchQuestionForm(AnonymousUser(), data={ 'email': '*****@*****.**', 'event_type': 'reply' }) assert form.is_valid() eq_('*****@*****.**', form.cleaned_data['email'])
def test_registered_watch_with_email(self): form = WatchQuestionForm(UserFactory(), data={ "email": "*****@*****.**", "event_type": "reply" }) assert form.is_valid() assert not form.cleaned_data["email"]
def test_anonymous_watch_with_email(self): form = WatchQuestionForm(AnonymousUser(), data={ "email": "*****@*****.**", "event_type": "reply" }) assert form.is_valid() eq_("*****@*****.**", form.cleaned_data["email"])
def test_registered_watch_with_email(self): form = WatchQuestionForm(user(), data={ 'email': '*****@*****.**', 'event_type': 'reply' }) assert form.is_valid() assert not form.cleaned_data['email']
def watch_question(request, question_id): """Start watching a question for replies or solution.""" question = get_object_or_404(Question, pk=question_id, is_spam=False) form = WatchQuestionForm(request.user, request.POST) # Process the form msg = None if form.is_valid(): user_or_email = (request.user if request.user.is_authenticated else form.cleaned_data["email"]) try: if form.cleaned_data["event_type"] == "reply": QuestionReplyEvent.notify(user_or_email, question) else: QuestionSolvedEvent.notify(user_or_email, question) except ActivationRequestFailed: msg = _("Could not send a message to that email address.") # Respond to ajax request if request.is_ajax(): if form.is_valid(): msg = msg or (_("You will be notified of updates by email.") if request.user.is_authenticated else _( "You should receive an email shortly " "to confirm your subscription.")) return HttpResponse(json.dumps({"message": msg})) if request.POST.get("from_vote"): tmpl = "questions/includes/question_vote_thanks.html" else: tmpl = "questions/includes/email_subscribe.html" html = render_to_string(tmpl, context={ "question": question, "watch_form": form }, request=request) return HttpResponse(json.dumps({"html": html})) if msg: messages.add_message(request, messages.ERROR, msg) return HttpResponseRedirect(question.get_absolute_url())
def test_registered_watch_without_email(self): form = WatchQuestionForm(UserFactory(), data={"event_type": "reply"}) assert form.is_valid()
def test_anonymous_watch_without_email(self): form = WatchQuestionForm(AnonymousUser(), data={"event_type": "reply"}) assert not form.is_valid() eq_("Please provide an email.", form.errors["email"][0])
def test_registered_watch_without_email(self): form = WatchQuestionForm(user(), data={'event_type': 'reply'}) assert form.is_valid()
def test_anonymous_watch_without_email(self): form = WatchQuestionForm(AnonymousUser(), data={'event_type': 'reply'}) assert not form.is_valid() eq_('Please provide an email.', form.errors['email'][0])
def _init_watch_form(request, event_type="solution"): initial = {"event_type": event_type} return WatchQuestionForm(request.user, initial=initial)
def test_registered_watch_with_email(self): form = WatchQuestionForm(user(), data={'email': '*****@*****.**', 'event_type': 'reply'}) assert form.is_valid() assert not form.cleaned_data['email']
def test_anonymous_watch_with_email(self): form = WatchQuestionForm(AnonymousUser(), data={'email': '*****@*****.**', 'event_type': 'reply'}) assert form.is_valid() eq_('*****@*****.**', form.cleaned_data['email'])