Пример #1
0
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)
Пример #2
0
    def test_get_sequence_bios(self):
        for i in range(10):
            data = self.BIO_DATA.copy()
            data['email'] = 'test-{0}@mail.com'.format(i)
            user_bio = classphoto_api.save_bio(**data)

        bios = classphoto_api.get_bios(1)
        self.assertEquals(len(bios), 10)
    def test_get_sequence_bios(self):
        for i in range(10):
            data = self.BIO_DATA.copy()
            data['email'] = 'test-{0}@mail.com'.format(i)
            user_bio = classphoto_api.save_bio(**data)

        bios = classphoto_api.get_bios(1)
        self.assertEquals(len(bios), 10)
    def test_get_sequence_bios_by_email(self):
        emails = ['test-{0}@mail.com'.format(i) for i in range(10)]
        for email in emails:
            data = self.BIO_DATA.copy()
            data['email'] = email
            user_bio = classphoto_api.save_bio(**data)

        bios = classphoto_api.get_bios_by_email(1, emails[:5])
        self.assertEquals(len(bios), 5)
Пример #5
0
 def test_get_sequence_bios_by_email(self):
     emails = ['test-{0}@mail.com'.format(i) for i in range(10)]
     for email in emails:
         data = self.BIO_DATA.copy()
         data['email'] = email
         user_bio = classphoto_api.save_bio(**data)
    
     bios = classphoto_api.get_bios_by_email(1, emails[:5])
     self.assertEquals(len(bios), 5)
Пример #6
0
    def test_send_user_link_to_whole_sequence( self ):
        signup_api.create_signup('*****@*****.**', {})
        signup_api.create_signup('*****@*****.**', {})
        signup_api.create_signup('*****@*****.**', {})
        signup_api.create_signup('*****@*****.**', {})
        signup_api.create_signup('*****@*****.**', {})
        bio = self.BIO_DATA.copy()
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)

        with patch('classphoto.emails.mailgun.api.send_mass_email') as sme:
            emails.send_user_link_to_whole_sequence(1)
            self.assertTrue(sme.called)
    def test_send_user_link_to_whole_sequence(self):
        signup_api.create_signup('*****@*****.**', {})
        signup_api.create_signup('*****@*****.**', {})
        signup_api.create_signup('*****@*****.**', {})
        signup_api.create_signup('*****@*****.**', {})
        signup_api.create_signup('*****@*****.**', {})
        bio = self.BIO_DATA.copy()
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)
        bio['email'] = '*****@*****.**'
        user_bio = classphoto_api.save_bio(**bio)

        with patch('classphoto.emails.mailgun.api.send_mass_email') as sme:
            emails.send_user_link_to_whole_sequence(1)
            self.assertTrue(sme.called)
Пример #8
0
    def test_update_bio(self):
        # create bio
        user_bio = classphoto_api.save_bio(**self.BIO_DATA)

        # bio should now be in primary list of bios
        bios = classphoto_api.get_bios(1)
        f = lambda x: x['email'] == user_bio['email']
        bios = filter(f, bios)
        self.assertEquals(len(bios), 1)
        self.assertEquals(bios[0], user_bio)

        # update bio
        update_data = self.BIO_DATA.copy()
        update_data['bio'] = 'This is the updated BIO'
        updated_bio = classphoto_api.save_bio(**update_data)
       
        # new bio should now be displayed
        bios = classphoto_api.get_bios(1)
        f = lambda x: x['email'] == user_bio['email']
        bios = filter(f, bios)
        self.assertEquals(len(bios), 1)
        self.assertEquals(bios[0], updated_bio)
    def test_update_bio(self):
        # create bio
        user_bio = classphoto_api.save_bio(**self.BIO_DATA)

        # bio should now be in primary list of bios
        bios = classphoto_api.get_bios(1)
        f = lambda x: x['email'] == user_bio['email']
        bios = filter(f, bios)
        self.assertEquals(len(bios), 1)
        self.assertEquals(bios[0], user_bio)

        # update bio
        update_data = self.BIO_DATA.copy()
        update_data['bio'] = 'This is the updated BIO'
        updated_bio = classphoto_api.save_bio(**update_data)

        # new bio should now be displayed
        bios = classphoto_api.get_bios(1)
        f = lambda x: x['email'] == user_bio['email']
        bios = filter(f, bios)
        self.assertEquals(len(bios), 1)
        self.assertEquals(bios[0], updated_bio)
Пример #10
0
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)
Пример #11
0
 def test_save_bio_with_twitter(self):
     bio_data = self.BIO_DATA.copy()
     bio_data['twitter'] = 'testhandle'
     user_bio = classphoto_api.save_bio(**bio_data)
     self.assertEqual(bio_data, user_bio)
Пример #12
0
 def test_save_bio(self):
     user_bio = classphoto_api.save_bio(**self.BIO_DATA)
     self.assertEqual(self.BIO_DATA, user_bio)
Пример #13
0
 def test_save_bio_with_twitter(self):
     bio_data = self.BIO_DATA.copy()
     bio_data['gplus'] = 'http://plus.google.com/user/1231231231/'
     user_bio = classphoto_api.save_bio(**bio_data)
     self.assertEqual(bio_data, user_bio)
Пример #14
0
 def test_save_bio_with_twitter(self):
     bio_data = self.BIO_DATA.copy()
     bio_data['twitter'] = 'testhandle'
     user_bio = classphoto_api.save_bio(**bio_data)
     self.assertEqual(bio_data, user_bio)
Пример #15
0
 def test_save_bio(self):
     user_bio = classphoto_api.save_bio(**self.BIO_DATA)
     self.assertEqual(self.BIO_DATA, user_bio)
Пример #16
0
 def test_save_bio_with_twitter(self):
     bio_data = self.BIO_DATA.copy()
     bio_data['gplus'] = 'http://plus.google.com/user/1231231231/'
     user_bio = classphoto_api.save_bio(**bio_data)
     self.assertEqual(bio_data, user_bio)