def test_remove_signup_from_sequence(self): signup_models.create_or_update_signup('*****@*****.**', { 'q1': 'ar1', 'q2': 'ar2' }) signup = signup_models.get_signup('*****@*****.**') self.assertEquals(signup['sequence'], 1) with patch('signup.models.sequence_model.get_current_sequence_number', lambda: 2): signup_models.remove_signup_from_sequence('*****@*****.**') signup = signup_models.get_signup('*****@*****.**') self.assertEquals(signup['sequence'], 2) signup_models.create_or_update_signup('*****@*****.**', { 'q1': 'ar1', 'q2': 'ar2' }) signup = signup_models.get_signup('*****@*****.**') self.assertEquals(signup['sequence'], 1) with patch('signup.models.sequence_model.get_current_sequence_number', lambda: None): signup_models.remove_signup_from_sequence('*****@*****.**') signup = signup_models.get_signup('*****@*****.**') self.assertEquals(signup['sequence'], None)
def test_signup_added_to_current_sequence(self): signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'}) with patch('signup.models.sequence_model.get_current_sequence_number', lambda: 2): signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'}) signup = signup_models.get_signup('*****@*****.**', 1) self.assertEquals(signup['sequence'], 1) signup = signup_models.get_signup('*****@*****.**', 2) self.assertEquals(signup['sequence'], 2)
def test_signup_added_without_sequence(self): with patch('signup.models.sequence_model.get_current_sequence_number', lambda: None): signup_models.create_or_update_signup(*self.signup_data) signup = signup_models.get_signup(self.signup_data[0], None) self.assertNotEqual(signup, None) self.assertEqual(signup['sequence'], None)
def save_bio(request, sequence): """ receive AJAX post from class classphoto page """ url = reverse('classphoto_classphoto', kwargs={'sequence': sequence}) # check if user signed up for the mooc signed_up = False try: signup = signup_api.get_signup(request.POST['email']) signed_up = True except: pass if not signed_up or signup['sequence'] != int(sequence): messages.error(request, 'We couln\'t find your signup. Please check if you just gave us the email you signed up with?') #TODO: this error should not be possible return http.HttpResponseRedirect(url) if request.POST['email'] != request.session.get('user_email'): messages.error(request, 'Oops! We don\'t recognize that email. Maybe you signed up with a different one?') return http.HttpResponseRedirect(url) user_bio = classphoto_api.save_bio( request.POST['email'], sequence, request.POST['name'], request.POST['bio'], request.POST['avatar'], request.POST.get('twitter', None) ) request.session['user_bio'] = user_bio messages.success(request, 'Sweet! You\'re now in the Class Photo!') return http.HttpResponseRedirect(url)
def test_signup_added_to_current_sequence(self): signup_models.create_or_update_signup('*****@*****.**', { 'q1': 'ar1', 'q2': 'ar2' }) with patch('signup.models.sequence_model.get_current_sequence_number', lambda: 2): signup_models.create_or_update_signup('*****@*****.**', { 'q1': 'ar1', 'q2': 'ar2' }) signup = signup_models.get_signup('*****@*****.**', 1) self.assertEquals(signup['sequence'], 1) signup = signup_models.get_signup('*****@*****.**', 2) self.assertEquals(signup['sequence'], 2)
def test_case_insensitve_signup(self): signup_models.create_or_update_signup('*****@*****.**', { 'q1': 'a1', 'q2': 'a2', 'q3': 'a3' }) signup = signup_models.get_signup('*****@*****.**', 1) self.assertEquals(signup['email'], '*****@*****.**')
def test_update_signup(self): original = signup_models.create_or_update_signup('*****@*****.**', {'q1':'a1', 'q2':'a2', 'q3':'a3'}) signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'}) signup = signup_models.get_signup('*****@*****.**', 1) self.assertEqual(signup['email'], '*****@*****.**') self.assertEqual(signup['questions']['q1'], 'ar1') self.assertEqual(signup['questions']['q2'], 'ar2') self.assertEqual(signup['questions']['q3'], 'a3') self.assertEqual(original['date_created'], signup['date_created']) self.assertNotEqual(original['date_updated'], signup['date_updated'])
def test_remove_signup_from_sequence(self): signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'}) signup = signup_models.get_signup('*****@*****.**') self.assertEquals(signup['sequence'], 1) with patch('signup.models.sequence_model.get_current_sequence_number', lambda: 2): signup_models.remove_signup_from_sequence('*****@*****.**') signup = signup_models.get_signup('*****@*****.**') self.assertEquals(signup['sequence'], 2) signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'}) signup = signup_models.get_signup('*****@*****.**') self.assertEquals(signup['sequence'], 1) with patch('signup.models.sequence_model.get_current_sequence_number', lambda: None): signup_models.remove_signup_from_sequence('*****@*****.**') signup = signup_models.get_signup('*****@*****.**') self.assertEquals(signup['sequence'], None)
def request_link(request): signup = None try: signup = signup_api.get_signup(request.POST.get('email')) messages.success(request, 'Check your inbox -- a tasty new link will be there shortly.') send_user_link(signup['email'], signup['key']) except: messages.error(request, 'Not so fast, partner -- you need to sign up for the Mechanical MOOC first!') url = reverse('classphoto_sequence_redirect') if settings.DEBUG and signup: url += '?key={0}'.format(signup['key']) return http.HttpResponseRedirect(url)
def test_create_signup(self): """ Test creation of a signup """ signup_models.create_signup('*****@*****.**', {'q1':'a1', 'q2':'a2', 'q3':'a3'}) signup = signup_models.get_signup('*****@*****.**', 1) self.assertEqual(signup['email'], '*****@*****.**') self.assertEqual(signup['questions']['q1'], 'a1') self.assertEqual(signup['questions']['q2'], 'a2') self.assertEqual(signup['questions']['q3'], 'a3') self.assertIn('date_created', signup) self.assertIn('date_updated', signup)
def unsubscribe(request): context = {} if request.method == 'POST': email = request.POST.get('email') try: signup = signup_model.get_signup(email) send_unsubscribe_confirmation(signup) messages.info(request, u'You will shortly receive an email to confirm that you wish to unsubscribe') return http.HttpResponseRedirect(reverse('home')) except: context['error'] = 'Could not find signup.' return render_to_response('unsubscribe/unsubscribe.html', context, context_instance=RequestContext(request))
def test_create_signup(self): """ Test creation of a signup """ signup_models.create_signup('*****@*****.**', { 'q1': 'a1', 'q2': 'a2', 'q3': 'a3' }) signup = signup_models.get_signup('*****@*****.**') self.assertEqual(signup['email'], '*****@*****.**') self.assertEqual(signup['questions']['q1'], 'a1') self.assertEqual(signup['questions']['q2'], 'a2') self.assertEqual(signup['questions']['q3'], 'a3') self.assertIn('date_created', signup) self.assertIn('date_updated', signup)
def test_update_signup(self): original = signup_models.create_or_update_signup( '*****@*****.**', { 'q1': 'a1', 'q2': 'a2', 'q3': 'a3' }) signup_models.create_or_update_signup('*****@*****.**', { 'q1': 'ar1', 'q2': 'ar2' }) signup = signup_models.get_signup('*****@*****.**') self.assertEqual(signup['email'], '*****@*****.**') self.assertEqual(signup['questions']['q1'], 'ar1') self.assertEqual(signup['questions']['q2'], 'ar2') self.assertEqual(signup['questions']['q3'], 'a3') self.assertEqual(original['date_created'], signup['date_created']) self.assertNotEqual(original['date_updated'], signup['date_updated'])
def unsubscribe_user( address ): """ Unsubscribe user completely from the Mechanical Mooc """ # remove from sequence group try: user_signup = signup_model.get_signup(address) sequence_list = sequence_model.sequence_list_name(user_signup['sequence']) mailgun_api.remove_list_member(sequence_list, address) except: log.error(u"couldn't remove {0} from sequence list".format(address)) # remove from small groups groups = groups_model.get_member_groups(address) for group in groups: groups_model.remove_group_member(group['uri'], address) groups_model.sync_group_with_mailgun(group['uri']) # mark as unsubscribed in the signups signup_model.delete_signup(address)
def unsubscribe_from_sequence( address ): # remove from sequence group try: user_signup = signup_model.get_signup(address) sequence_list = sequence_model.sequence_list_name(user_signup['sequence']) mailgun_api.remove_list_member(sequence_list, address) except: log.error(u"couldn't remove {0} from sequence list".format(address)) # remove from small groups # TODO: Can a user be subscribed to more than one group or more than one # sequence at the same time? groups = groups_model.get_member_groups(address) for group in groups: groups_model.remove_group_member(group['uri'], address) groups_model.sync_group_with_mailgun(group['uri']) # add signup to next sequence. signup_model.remove_signup_from_sequence(address)
def save_bio(request, sequence): """ receive AJAX post from class classphoto page """ url = reverse('classphoto_classphoto', kwargs={'sequence': sequence}) # TODO validate data on the server side also! # check if user signed up for the mooc signed_up = False try: signup = signup_api.get_signup(request.POST['email'], sequence) signed_up = True except: pass if not signed_up or signup['sequence'] != int(sequence): messages.error( request, 'We couln\'t find your signup. Please check if you just gave us the email you signed up with?' ) #TODO: this error should not be possible return http.HttpResponseRedirect(url) if request.POST['email'] != request.session.get('user_email'): messages.error( request, 'Oops! We don\'t recognize that email. Maybe you signed up with a different one?' ) return http.HttpResponseRedirect(url) user_bio = classphoto_api.save_bio(request.POST['email'], sequence, request.POST['name'], request.POST['bio'], request.POST['avatar'], request.POST.get('twitter', None), request.POST.get('gplus', None)) request.session['user_bio'] = user_bio messages.success(request, 'Sweet! You\'re now in the Class Photo!') return http.HttpResponseRedirect(url)
def test_case_insensitve_signup(self): signup_models.create_or_update_signup('*****@*****.**', {'q1':'a1', 'q2':'a2', 'q3':'a3'}) signup = signup_models.get_signup('*****@*****.**', 1) self.assertEquals(signup['email'], '*****@*****.**')