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)
Esempio n. 2
0
    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_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'], '*****@*****.**')
Esempio n. 4
0
    def test_every_man_is_an_island(self):
        for signup in randata.random_data(1000):
            signup_model.create_or_update_signup(**signup)

        groups = models.prepare_groups(1, max_group_size=1)

        for group in groups:
            self.assertEqual(len(group), 1)
Esempio n. 5
0
    def test_get_signups(self):
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'a1', 'q2':'a2', 'q3':'a3'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})

        self.assertEqual(len(signup_models.get_signups(1)), 4)
Esempio n. 6
0
    def test_handle_new_signups(self, *args):
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'a1', 'q2':'a2', 'q3':'a3'})
        self.assertEqual(len(signup_models.get_new_signups()), 1)

        with patch('signup.models.mailgun_api.send_mass_email') as send_email:
            signup_models.handle_new_signups()
            self.assertTrue(send_email.called)

        self.assertEqual(len(signup_models.get_new_signups()), 0)
Esempio n. 7
0
    def test_prepare_groups(self):
        for signup in randata.random_data(1000):
            signup_model.create_or_update_signup(**signup)

        groups = models.prepare_groups(1)

        grouped_users = filter(lambda x: x['questions']['groupRadios'], signup_model.get_signups(1))

        self.assertEquals(len(groups), math.ceil(len(grouped_users)/40.0))
Esempio n. 8
0
    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)
Esempio n. 9
0
    def test_group_creation(self):
        for signup in randata.random_data(1000):
            signup_model.create_or_update_signup(**signup)

        
        group_data = models.prepare_groups(1)
        models.create_groups(group_data, 1)
        groups = group_model.get_groups(1)

        self.assertEqual(len(group_data), len(groups))
Esempio n. 10
0
 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'])
Esempio n. 11
0
    def handle(self, *args, **options):
        import requests
        resp = requests.get(args[0])

        for signup in resp.json():
            email = signup['email']
            del signup['email']
            create_or_update_signup(email, signup)
            db.UserSignup.objects.filter(email=email).update(date_welcome_email_sent=datetime.datetime.utcnow())
            add_user_to_global_list(email)
Esempio n. 12
0
    def test_group_creation(self):
        for signup in randata.random_data(1000):
            signup_model.create_or_update_signup(**signup)

        group_data = models.prepare_groups(1)
        models.create_groups(group_data, 'g-')
        groups = group_model.get_groups()

        self.assertEqual(len(group_data), len(groups))
        for i, member in enumerate(groups[0]['members']):
            self.assertEqual(member, group_data[0]['members'][i]['email'])
Esempio n. 13
0
    def test_prepare_groups(self):
        for signup in randata.random_signup(1000):
            signup_model.create_or_update_signup(**signup)

        groups = models.prepare_groups()

        for i in range(100):
            random_group = random.choice(groups)
            random_user = random.choice(random_group['members'])

            self.assertEqual(random_group['timezone'], random_user['questions']['timezone'])
Esempio n. 14
0
    def test_group_creation(self):
        for signup in randata.random_signup(1000):
            signup_model.create_or_update_signup(**signup)

        group_data = models.prepare_groups()
        models.create_groups(group_data, 'g-')
        groups = group_model.get_groups()

        self.assertEqual(len(group_data), len(groups))
        for i, member in enumerate(groups[0]['members']):
            self.assertEqual(member, group_data[0]['members'][i]['email'])
Esempio n. 15
0
    def test_every_man_is_an_island(self):
        for signup in randata.random_data(1000):
            signup_model.create_or_update_signup(**signup)

        groups = models.prepare_groups(1, max_group_size=1)

        for i in range(100):
            random_group = random.choice(groups)
            random_user = random.choice(random_group['members'])
            self.assertEqual(random_group['timezone'], random_user['questions']['timezone'])
            self.assertEqual(len(random_group['members']), 1)
Esempio n. 16
0
    def test_handle_new_signups(self, add_list_member, delete_all_unsubscribes):
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'a1', 'q2':'a2', 'q3':'a3'})
        self.assertEqual(len(signup_models.get_new_signups()), 1)

        with patch('signup.models.mailgun_api.send_mass_email') as send_email:
            signup_models.handle_new_signups()
            self.assertTrue(send_email.called)
            self.assertTrue(add_list_member.called)
            self.assertTrue(delete_all_unsubscribes.called)

        self.assertEqual(len(signup_models.get_new_signups()), 0)
Esempio n. 17
0
    def handle(self, *args, **options):
        import requests
        resp = requests.get(args[0])

        for signup in resp.json():
            email = signup['email']
            del signup['email']
            create_or_update_signup(email, signup)
            db.UserSignup.objects.filter(email=email).update(
                date_welcome_email_sent=datetime.datetime.utcnow())
            add_user_to_global_list(email)
Esempio n. 18
0
    def test_every_man_is_an_island(self):
        for signup in randata.random_signup(1000):
            signup_model.create_or_update_signup(**signup)

        groups = models.prepare_groups(max_group_size=1)

        for i in range(100):
            random_group = random.choice(groups)
            random_user = random.choice(random_group['members'])
            self.assertEqual(random_group['timezone'],
                             random_user['questions']['timezone'])
            self.assertEqual(len(random_group['members']), 1)
Esempio n. 19
0
    def test_handle_new_signups(self, *args):
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'a1',
            'q2': 'a2',
            'q3': 'a3'
        })
        self.assertEqual(len(signup_models.get_new_signups()), 1)

        with patch('signup.models.emails.send_welcome_emails') as send_email:
            signup_models.handle_new_signups()
            self.assertTrue(send_email.called)

        self.assertEqual(len(signup_models.get_new_signups()), 0)
Esempio n. 20
0
def signup( request ):

    form = SignupForm(request.POST)
    if not form.is_valid():
        return render_to_response('signup/error.html', {'form': form}, context_instance=RequestContext(request))

    email = form.cleaned_data['email']
    scope = form.cleaned_data['scope']
    signup_questions = request.POST.dict()
    del signup_questions['email']
    del signup_questions['csrfmiddlewaretoken']
    del signup_questions['scope']
    signup_model.create_or_update_signup(email, scope, signup_questions )
    return http.HttpResponseRedirect(reverse('signup_success'))
Esempio n. 21
0
    def test_scale_signups(self, blah, send_email, add_list_member):
        for signup in randata.random_data(2000):
            signup_models.create_or_update_signup(**signup)

        signups = len(signup_models.get_new_signups())

        with patch('signup.models.sequence_model.sequence_list_name', lambda x: '*****@*****.**'):
            signup_models.handle_new_signups()
            self.assertTrue(send_email.called)
            self.assertEqual(send_email.call_count, math.ceil(signups/500.0))
            self.assertTrue(add_list_member.called)
            self.assertEqual(add_list_member.call_count, signups)

        self.assertEqual(len(signup_models.get_new_signups()), 0)
    def test_scale_signups(self, blah, send_email, add_list_member):
        for signup in randata.random_data(2000):
            signup_models.create_or_update_signup(**signup)

        signups = len(signup_models.get_new_signups())

        with patch('signup.models.sequence_model.sequence_list_name',
                   lambda x: '*****@*****.**'):
            signup_models.handle_new_signups()
            self.assertTrue(send_email.called)
            self.assertEqual(send_email.call_count, math.ceil(signups / 500.0))
            self.assertTrue(add_list_member.called)
            self.assertEqual(add_list_member.call_count, signups)

        self.assertEqual(len(signup_models.get_new_signups()), 0)
Esempio n. 23
0
def signup( request ):

    form = SignupForm(request.POST)

    if not form.is_valid():
        return render_to_response('signup/error.html', {'form': form}, context_instance=RequestContext(request))

    email = form.cleaned_data['email']
    timezone = form.cleaned_data['timezone']
    signup_questions = request.POST.dict()
    del signup_questions['email']
    del signup_questions['csrfmiddlewaretoken']

    signup_model.create_or_update_signup(email, signup_questions )

    return http.HttpResponseRedirect(reverse('signup_success'))
    def test_handle_new_signups(self, add_list_member,
                                delete_all_unsubscribes):
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'a1',
            'q2': 'a2',
            'q3': 'a3'
        })
        self.assertEqual(len(signup_models.get_new_signups()), 1)

        with patch('signup.models.mailgun_api.send_mass_email') as send_email:
            signup_models.handle_new_signups()
            self.assertTrue(send_email.called)
            self.assertTrue(add_list_member.called)
            self.assertTrue(delete_all_unsubscribes.called)

        self.assertEqual(len(signup_models.get_new_signups()), 0)
Esempio n. 25
0
def signup_ajax(request):
    form = SignupForm(request.POST)

    if not form.is_valid():
        return http.HttpResponse(400)

    email = form.cleaned_data['email']
    signup_questions = request.POST.dict()
    del signup_questions['email']

    signup_model.create_or_update_signup(email, signup_questions)
    response = http.HttpResponse(200)
    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
    response['Access-Control-Allow-Headers'] = '*'
    response['Access-Control-Max-Age'] = '1728000'
    return response
    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)
Esempio n. 27
0
def signup_ajax( request ):
    form = SignupForm(request.POST)

    if not form.is_valid():
        return http.HttpResponse(400)

    email = form.cleaned_data['email']
    signup_questions = request.POST.dict()
    del signup_questions['email']

    signup_model.create_or_update_signup(email, signup_questions )
    response = http.HttpResponse(200)
    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
    response['Access-Control-Allow-Headers'] =  '*'
    response['Access-Control-Max-Age'] = '1728000'
    return response
Esempio n. 28
0
 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'])
Esempio n. 29
0
    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)
Esempio n. 30
0
def signup_ajax( request ):
    form = SignupForm(request.POST)

    if not form.is_valid():
        return http.HttpResponse(status=400)
    email = form.cleaned_data['email']
    scope = form.cleaned_data['scope']
    signup_questions = request.POST.dict()
    del signup_questions['email']
    del signup_questions['scope']
    #TODO: make exception specific - only legit exception should be wrong scope
    try: 
        signup_model.create_or_update_signup(email, scope, signup_questions )
    except Exception as ex:
        logger.debug(unicode(ex))
        return http.HttpResponse(status=400)

    response = http.HttpResponse(status=200)
    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
    response['Access-Control-Allow-Headers'] =  '*'
    response['Access-Control-Max-Age'] = '1728000'
    return response
Esempio n. 31
0
    def test_get_signups(self):
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'a1',
            'q2': 'a2',
            'q3': 'a3'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })

        self.assertEqual(len(signup_models.get_signups()), 4)
Esempio n. 32
0
 def test_here_comes_everyone(self):
     for signup in randata.random_data(1000):
         signup_model.create_or_update_signup(**signup)
     groups = models.prepare_groups(1, max_group_size=1001)
     self.assertEqual(len(groups), 1)
Esempio n. 33
0
    def test_delete_signup(self):
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'a1',
            'q2': 'a2',
            'q3': 'a3'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })

        self.assertEqual(len(signup_models.get_signups()), 4)
        new_signups = signup_models.get_new_signups()
        self.assertIn('*****@*****.**', [s['email'] for s in new_signups])

        signup_models.delete_signup('*****@*****.**')

        signups = signup_models.get_signups()
        self.assertEqual(len(signups), 3)
        self.assertNotIn('*****@*****.**', [s['email'] for s in signups])
        new_signups = signup_models.get_new_signups()
        self.assertNotIn('*****@*****.**', [s['email'] for s in new_signups])

        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })
        self.assertEqual(len(signup_models.get_signups()), 4)
        new_signups = signup_models.get_new_signups()
        self.assertIn('*****@*****.**', [s['email'] for s in new_signups])
Esempio n. 34
0
    def test_get_signups_for_sequence(self):
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'a1',
            'q2': 'a2',
            'q3': 'a3'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })
        signup_models.create_or_update_signup('*****@*****.**', {
            'q1': 'ar1',
            'q2': 'ar2'
        })
        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'})
            signup_models.create_or_update_signup('*****@*****.**',
                                                  {'q1': 'ar1'})
            signup_models.create_or_update_signup('*****@*****.**',
                                                  {'q1': 'ar1'})
            signup_models.create_or_update_signup('*****@*****.**',
                                                  {'q1': 'ar1'})

        self.assertEqual(len(signup_models.get_signups(1)), 2)
        self.assertEqual(len(signup_models.get_signups(2)), 4)
Esempio n. 35
0
 def test_here_comes_everyone(self):
     for signup in randata.random_data(1000):
         signup_model.create_or_update_signup(**signup)
     groups = models.prepare_groups(1, max_group_size=1001)
     self.assertEqual(len(groups), 0)
Esempio n. 36
0
    def test_delete_signup(self):
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'a1', 'q2':'a2', 'q3':'a3'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})

        self.assertEqual(len(signup_models.get_signups(1)), 4)
        new_signups = signup_models.get_new_signups()
        self.assertIn('*****@*****.**', [s['email'] for s in new_signups])

        signup_models.delete_signup('*****@*****.**', 1)

        signups = signup_models.get_signups(1)
        self.assertEqual(len(signups), 3)
        self.assertNotIn('*****@*****.**', [s['email'] for s in signups])
        new_signups = signup_models.get_new_signups()
        self.assertNotIn('*****@*****.**', [s['email'] for s in new_signups])

        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})
        self.assertEqual(len(signup_models.get_signups(1)), 4)
        new_signups = signup_models.get_new_signups()
        self.assertIn('*****@*****.**', [s['email'] for s in new_signups])
Esempio n. 37
0
 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'], '*****@*****.**')
Esempio n. 38
0
    def test_get_signups_for_sequence(self):
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'a1', 'q2':'a2', 'q3':'a3'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})
        signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1', 'q2':'ar2'})
        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'})
            signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1'})
            signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1'})
            signup_models.create_or_update_signup('*****@*****.**', {'q1':'ar1'})

        self.assertEqual(len(signup_models.get_signups(1)), 3)
        self.assertEqual(len(signup_models.get_signups(2)), 4)
Esempio n. 39
0
 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)