Exemplo n.º 1
0
 def setUp(self):
     '''set the client obj to a new client, and set the cal name to the name we\'re using'''
     self.client = CalendarResource('gtest.pdx.edu')
     self.cal_name = 'new_cal_name'
Exemplo n.º 2
0
class calendar_test:
    '''test class for calendar operations'''
    def __init__(self):
        '''init the client obj and the new cal's name to null'''
        self.client = None
        self.cal_name = ''

    def setUp(self):
        '''set the client obj to a new client, and set the cal name to the name we\'re using'''
        self.client = CalendarResource('gtest.pdx.edu')
        self.cal_name = 'new_cal_name'

    def tearDown(self):
        '''delete the newly created calendar object as well as the client we were using'''
        try:
            self.client.g_res_client.delete_resource(md5('new_cal_name').hexdigest())
        except:
            print 'error deleting the cal with name "new_cal_name"'
        del self.client

    def test_calendar_validate_existing(self):
        '''this function tests running calendar_validate on a known existing 
        calendar'''
        calendar_already_exists, success, acl = \
            calendar_validate('abc_calendar', self.client)
        assert (calendar_already_exists == True)
        assert (success == False)
        assert (len(acl)>0)

    def test_calendar_validate_new(self):
        '''this function tests running calendar_validate on a new calendar'''
        calendar_already_exists, success, acl = \
            calendar_validate(self.cal_name, self.client)
        assert (calendar_already_exists == False)
        assert (success == True)
        assert ((len(acl)==2) or (len(acl)==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

    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)

    def test_process_calendar_existing(self):
        '''this function tests running the process_calendar method on a known
        existing calendar'''
        response = process_calendar('calendar_name', True, False)
        assert (response == 'calendar_name (existing calendar)')

    def test_process_calendar_new(self):
        '''this function tests running the process_calendar method on a new
        calendar'''
        response = process_calendar('calendar_name', False, True)
        assert (response == 'calendar_name (new calendar)')

    def test_process_calendar_error(self):
        '''this function tests running the process_calendar method on invalid
        input; indicating failure to create calendar'''
        response = process_calendar('calendar_name', False, False)
        assert (response == 'could not make calendar: calendar_name')

    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)')

    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)')

    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'))

    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)

    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)

    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
        calendar_already_exists, success, acl = \
            calendar_validate(self.cal_name, self.client)
        calendar_already_owner_end = calendar_already_owner('magarvey', acl, self.client)
        assert calendar_already_exists
        assert (calendar_already_owner_start == False)
        assert (success == False)
        assert calendar_add_owner_success
        assert calendar_already_owner_end