Exemplo n.º 1
0
 def test_calendar_add_owner_new(self):
     '''this function tests the calendar_add_owner method for a valid user not already
     owner of the calendar'''
     self.client.create(self.cal_name)
     calendar_already_exists, success, acl = \
         calendar_validate(self.cal_name, self.client)
     calendar_already_owner_start = calendar_already_owner('magarvey', acl, self.client)
     try:
         calendar_add_owner('magarvey', self.cal_name, self.client)
         calendar_add_owner_success = True
     except Exception, err:
         print err
         calendar_add_owner_success = False
Exemplo n.º 2
0
 def test_calendar_add_owner_invalid(self):
     '''this function tests the calendar_add_owner method on a user that is not in the
     gtest.pdx.edu system'''
     calendar_already_exists, success, acl = \
         calendar_validate('abc_calendar', self.client)
     calendar_already_owner_start = calendar_already_owner('?//%/$/#@', acl, self.client)
     try:
         calendar_add_owner('?//%/$/#@', 'abc_calendar', self.client)
         calendar_add_owner_success = True
     except:
         calendar_add_owner_success = False
     assert calendar_already_exists
     assert (calendar_already_owner_start == False)
     assert (success == False)
     assert (calendar_add_owner_success == False)
Exemplo n.º 3
0
 def test_calendar_add_owner_existing(self):
     '''this function tests the calendar_add_owner method on a calendar that the user
     is already owner of'''
     calendar_already_exists, success, acl = \
         calendar_validate('abc_calendar', self.client)
     calendar_already_owner_start = calendar_already_owner('magarvey', acl, self.client)
     try:
         calendar_add_owner('magarvey', 'abc_calendar', self.client)
         calendar_add_owner_success = True
     except:
         calendar_add_owner_success = False
     assert calendar_already_exists
     assert calendar_already_owner_start
     assert (success == False)
     assert (calendar_add_owner_success == False)
Exemplo n.º 4
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))
Exemplo n.º 5
0
 def test_calendar_already_owner_false(self):
     '''this function tests running calendar_already_owner on a calendar where we
     know that the given user is not already an owner'''
     _, _, acl = calendar_validate('abc_calendar', self.client)
     owner_already = calendar_already_owner('phony_phony_phony', acl, self.client)
     assert (owner_already == False)
Exemplo n.º 6
0
 def test_calendar_already_owner_true(self):
     '''this function tests running calendar_already_owner on a calendar where we
     know that the given user is already an owner'''
     _, _, acl = calendar_validate('abc_calendar', self.client)
     owner_already = calendar_already_owner('magarvey', acl, self.client)
     assert owner_already