示例#1
0
 def test_signed_up_not_signed_in_bio_save(self):
     signup_api.create_signup(**self.SIGNUP_DATA)
     c = Client()
     resp = c.post('/classphoto/1/save_bio/', self.BIO_DATA)
     self.assertRedirects(resp, '/classphoto/1/')
     bios = classphoto_api.get_bios(1)
     self.assertEquals(len(bios), 0)
示例#2
0
 def test_signed_up_not_signed_in_bio_save(self):
     signup_api.create_signup(**self.SIGNUP_DATA)
     c = Client()
     resp = c.post('/classphoto/1/save_bio/', self.BIO_DATA)
     self.assertRedirects(resp, '/classphoto/1/')
     bios = classphoto_api.get_bios(1)
     self.assertEquals(len(bios), 0)
示例#3
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)
示例#5
0
 def test_signed_up_signed_in_bio_save(self):
     signup = signup_api.create_signup(**self.SIGNUP_DATA)
     c = Client()
     resp = c.get('/classphoto/1/?key={0}'.format(signup['key']))
     resp = c.post('/classphoto/1/save_bio/', self.BIO_DATA)
     self.assertRedirects(resp, '/classphoto/1/')
     bios = classphoto_api.get_bios(0)
     self.assertEquals(len(bios), 0)
示例#6
0
 def test_signed_up_signed_in_bio_save(self):
     signup = signup_api.create_signup(**self.SIGNUP_DATA)
     c = Client()
     resp = c.get('/classphoto/1/?key={0}'.format(signup['key']))
     resp = c.post('/classphoto/1/save_bio/', self.BIO_DATA)
     self.assertRedirects(resp, '/classphoto/1/')
     bios = classphoto_api.get_bios(0)
     self.assertEquals(len(bios), 0)
示例#7
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)
示例#9
0
def classphoto(request, sequence):
    """ show classphoto for all signups for this sequence with profiles """
    s3_policy, signature = create_s3_policy_doc(settings.AWS_S3_BUCKET,
                                                'classphoto')

    prefix = hmac.new('THEANSWERIS42', request.session.session_key,
                      hashlib.sha1).hexdigest()

    bios = classphoto_api.get_bios(sequence, limit=0)
    bios += [{'email': ''} for i in range(len(bios), 36)]
    bios = random.sample(bios, 36)

    # if user is logged in and has a bio, display it!
    user_bio = request.session.get('user_bio', None)
    if user_bio:
        bio_in_list = [x for x in bios if x['email'] == user_bio['email']]
        if len(bio_in_list) == 1:
            # swap user bio with bio at position 12
            bio_index = bios.index(bio_in_list[0])
            bios[bio_index] = bios[11]
        bios[11] = user_bio
    else:
        # make a gap at position 12
        bios[11] = {'email': ''}

    context = {
        'bios': bios,
        'user_bio': user_bio,
        'user_email': request.session.get('user_email'),
        'sequence': sequence,
        's3_policy': s3_policy,
        's3_signature': signature,
        'AWS_ACCESS_KEY_ID': settings.AWS_ACCESS_KEY_ID,
        'AWS_S3_BUCKET': settings.AWS_S3_BUCKET,
        'key_prefix': 'classphoto/{0}'.format(prefix)
    }

    return render_to_response('classphoto/index.html',
                              context,
                              context_instance=RequestContext(request))
示例#10
0
def classphoto(request, sequence):
    """ show classphoto for all signups for this sequence with profiles """
    s3_policy, signature = create_s3_policy_doc(settings.AWS_S3_BUCKET, 'classphoto')

    prefix = hmac.new(
        'THEANSWERIS42', request.session.session_key, hashlib.sha1
    ).hexdigest()

    bios = classphoto_api.get_bios(sequence, limit=0)
    bios += [{'email': ''} for i in range(len(bios), 36)]
    bios = random.sample(bios, 36)

    # if user is logged in and has a bio, display it!
    user_bio = request.session.get('user_bio', None)
    if user_bio:
        bio_in_list = [ x for x in bios if x['email'] == user_bio['email'] ]
        if len(bio_in_list) == 1:
            # swap user bio with bio at position 12
            bio_index = bios.index(bio_in_list[0])
            bios[bio_index] = bios[11]
        bios[11] = user_bio
    else:
        # make a gap at position 12
        bios[11] = {'email': ''}

    context = {
        'bios': bios,
        'user_bio': user_bio,
        'user_email': request.session.get('user_email'),
        'sequence': sequence,
        's3_policy': s3_policy,
        's3_signature': signature,
        'AWS_ACCESS_KEY_ID': settings.AWS_ACCESS_KEY_ID,
        'AWS_S3_BUCKET': settings.AWS_S3_BUCKET,
        'key_prefix': 'classphoto/{0}'.format(prefix)
    }
    
    return render_to_response('classphoto/index.html', context, context_instance=RequestContext(request))
示例#11
0
 def test_un_signedup_bio(self):
     c = Client()
     resp = c.post('/classphoto/1/save_bio/', self.BIO_DATA)
     self.assertRedirects(resp, '/classphoto/1/')
     bios = classphoto_api.get_bios(1)
     self.assertEquals(len(bios), 0)
示例#12
0
 def test_un_signedup_bio(self):
     c = Client()
     resp = c.post('/classphoto/1/save_bio/', self.BIO_DATA)
     self.assertRedirects(resp, '/classphoto/1/')
     bios = classphoto_api.get_bios(1)
     self.assertEquals(len(bios), 0)