diff --git a/tests/tests.py b/tests/tests.py index ee6fc8d..0db7d1f 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -126,5 +126,51 @@ We're still logged in so go to the page where the settings can be changed (this page also requires admin authority). - >>> response = c.get('/settings/new_list%40example.com/',) + >>> response = c.get('/settings/new_list%40mail.example.com/',) + + + +Mass Subscribe Users +==================== + +Now we want to mass subscribe a few users to the list. Therefore, +go to the mass subscription page. + + >>> url = '/settings/new_list%40mail.example.com/mass_subscribe/' + + >>> response = c.get(url) + +Check that everything went well by making sure the status code +was correct. + + >>> response.status_code + 200 + +Try mass subscribing the users 'liza@example.com' and +'george@example.com'. Each address should be provided on a separate +line so add '\\n' between the names to indicate that this was done +(we're on a Linux machine which is why the letter 'n' was used and +the double '\\' instead of a single one is to escape the string +parsing of Python). + + >>> url = '/settings/new_list%40mail.example.com/mass_subscribe/' + + >>> response = c.post(url, + ... {"emails": "liza@example.com\\ngeorge@example.com"}) + +If everything was successful, we shall get a positive response from +the page. We'll check that this was the case. + + >>> print ("The mass subscription was successful." in response.content) or ("HTTP Error 409: Member already subscribed" in response.content) #TODO - doubled data after multiple tests + True + +Done with the admin stuff. Now let's log out. + + >>> response = c.get('/lists/logout/',) + +If the request was successful we should end up on the list info page. +Now make sure that we got redirected there. + + >>> print "All mailing lists" in response.content + True """ diff --git a/views.py b/views.py index 6019024..f5c70bf 100644 --- a/views.py +++ b/views.py @@ -331,12 +331,16 @@ # The emails to subscribe should each be provided on a # separate line so get each of them. emails = request.POST["emails"].splitlines() - message = "The mass subscription was successful." for email in emails: # very simple test if email address is valid parts = email.split('@') - if len(parts) == 2 and '.' in parts[1]: - the_list.subscribe(address=email, real_name="") + if len(parts) == 2 and '.' in parts[1]: #TODO - move check to clean method of the form - see example in django docs + try: + the_list.subscribe(address=email, real_name="") + message = "The mass subscription was successful." + except Exception, e: + form._errors["NON_FIELD_ERRORS"]=forms.util.ErrorList() + form._errors["NON_FIELD_ERRORS"].append(e) else: # At least one email address wasn't valid so # overwrite the success message and ask them to