Ejemplo n.º 1
0
 def test_process_reqiuestor_existing(self):
     '''this function tests the calendar_process_requestor method on a requestor
     that is already the owner of the calendar'''
     response = calendar_process_requestor('magarvey',
         'abc_calendar',
         True,
         self.client)
     assert (response == '\n<br/>magarvey (already owner)')
Ejemplo n.º 2
0
 def test_calendar_process_requestor_new(self):
     '''this function tests the calendar_process_requestor method on a requestor
     that is already the owner of the calendar'''
     __a__ = md5()
     __a__.update(str(randint(0, 5000000)))
     user = '******'+str(__a__.hexdigest())
     response = calendar_process_requestor(user, 'abc_calendar', False, self.client)
     assert (response == '\n<br/>' + user + ' (new owner)')
Ejemplo n.º 3
0
def index(request):
    '''this is the index method, it serves and handles the calendar creation
    owner addition functionality'''
    #check for correct permission
    if not request.user.has_perm('mysite.psu_gcal'):
        return render_to_response('invalid.html')
    else:
        #check if form submitted
        if not request.method == 'POST':
            #if the user wants the calendar form
            if request.path == '/calendar_form/':
                calendar_form = CalendarForm()
                template = loader.get_template("calendar_form.html")
                context = Context()
                return render_to_response('calendar_form.html', {'calendar_form': calendar_form}, context_instance=RequestContext(request))
            #if the user wants the group form
            elif request.path == '/group_form/':
                group_form = GroupForm()
                template = loader.get_template("group_form.html")
                context = Context()
                return render_to_response('group_form.html', {'group_form': group_form}, context_instance=RequestContext(request))
            #no more alias form... handled with the other alias create scripts
            #alias_form = AliasForm()

            #the generic case
            else:
                template = loader.get_template( 'index.html' )
                context = Context()
                return render_to_response( 'index.html', {},
                    context_instance=RequestContext(request)  )

        #if it's the calendar form that they submitted
        elif (u'calendar_name' in request.POST.keys()):
            form = CalendarForm( request.POST )
            #check if form valid
            if not form.is_valid():
                return HttpResponse("form not valid...")
            #handle form submission
            else:
                calendar_name, calendar_requestor_1, calendar_requestor_2 = \
                    calendar_process_form(form)
                print 'calendar_name: {0}'.format(calendar_name)#debug
                print 'calendar_requestor_1: {0}'.format(calendar_requestor_1)#debug
                print 'calendar_requestor_2: {0}'.format(calendar_requestor_2)#debug
                try:
                    #client = CalendarResource( google.keys()[0] )
                    client = CalendarResource(domain=calendar.keys()[0],adminuser=calendar[calendar.keys()[0]]['adminuser'],password=calendar[calendar.keys()[0]]['password'])
                    print 'client: {0}'.format(client)#debug
                    #print str(client) #debug
                    try:
                        calendar_already_exists, success, acl = \
                            calendar_validate( calendar_name, client )
                        __logger__.info('calendar_already_exists: '+str(calendar_already_exists)+'\nsuccess: '+str(success)+'\nclient: '+str(client)) #debug
                    except Exception, err:
                        __logger__.info('err: '+str(err)) #debug

                    #create success message
                    response = process_calendar( 
                            calendar_name, calendar_already_exists, success )
                    __logger__.info('response: '+response) #debug
                    if calendar_requestor_1:
                        if requestor_validate( calendar_requestor_1, client ):
                            requestor_1_already_owner = calendar_already_owner(
                                calendar_requestor_1, 
                                acl, 
                                client )

                            response += calendar_process_requestor(
                                calendar_requestor_1, 
                                calendar_name, 
                                requestor_1_already_owner, 
                                client )
                        else:
                            response += '\n<br/>' + calendar_requestor_1 + \
                                ' is not a valid user'

                    if calendar_requestor_2:
                        if requestor_validate( calendar_requestor_2, client ):
                            requestor_2_already_owner = calendar_already_owner(
                                calendar_requestor_2,
                                acl,
                                client )

                            response += calendar_process_requestor(
                                calendar_requestor_2, 
                                calendar_name, 
                                requestor_2_already_owner, 
                                client )
                        else:
                            response += '\n<br/>' + calendar_requestor_2 + \
                                ' is not a valid user'

                    __logger__.info('user: '******' has made the following request:\n' + str(response) + \
                        '\n')
                    #return HttpResponse( response )

                    template = loader.get_template("success.html")
                    context = Context()
                    return render_to_response('success.html', {'success_msg': response}, context_instance=RequestContext(request))

                except Exception, err:
                    response = str(err)
                    response += '\n<br/>calendar name: ' + str(calendar_name)
                    response += '\n<br/>requestor_1: ' + str(calendar_requestor_1)
                    response += '\n<br/>requestor_2: ' + str(calendar_requestor_2)
                    template = loader.get_template("success.html")
                    context = Context()
                    return render_to_response('success.html', {'success_msg': response}, context_instance=RequestContext(request))
Ejemplo n.º 4
0
 def test_calendar_process_requestor_invalid(self):
     '''this function tests the calendar_process_requestor method on a requestor with
     some invalid chars in the requestor's name (... to trigger the exception)'''
     response = calendar_process_requestor('', 'abc_calendar', False, self.client)
     assert (response.startswith('\n<br/> is invalid user'))