Example #1
0
 def setUp(self):
     '''set up the group client and set the group name'''
     self.client = Group('gtest.pdx.edu')
     self.group_name = 'new_test_group'
Example #2
0
class group_test:
    '''test class for groups'''
    def __init__(self):
        '''init client and group_name to none'''
        self.client = None
        self.group_name = None

    def setUp(self):
        '''set up the group client and set the group name'''
        self.client = Group('gtest.pdx.edu')
        self.group_name = 'new_test_group'

    def tearDown(self):
        '''delete the newly created test group and the client object'''
        try:
            self.client.delete(group_name='new_test_group')
        except:
            print "error deleting group: 'new_test_group'"
        del self.client

    def test_group_validate_existing(self):
        '''this function tests running group_validate on a known existing 
        group'''
        group_already_exists, success = \
            group_validate('abc_group', '', self.client)
        assert (group_already_exists == True)
        assert (success == False)

    def test_group_validate_new(self):
        '''this function tests running calendar_validate on a new calendar'''
        group_already_exists, success = \
            group_validate(self.group_name, '',  self.client)
        assert (group_already_exists == False)
        assert (success == True)

    def test_group_already_owner_true(self):
        '''this function tests running group_already_owner on a group where we
        know that the given user is already an owner'''
        owner_already = group_already_owner('magarvey', 'abc_group', self.client)
        assert owner_already

    def test_group_already_owner_false(self):
        '''this function tests running group_already_owner on a group where we
        know that the given user is not already an owner'''
        owner_already = group_already_owner('phony_phony_phony', 'abc_group', self.client)
        assert (owner_already == False)

    def test_process_group_existing(self):
        '''this function tests running the process_group method on a known
        existing group'''
        response = process_group('group_name', '', True, False)
	meaningful_response = response.split('\n')[0]
	print meaningful_response
        assert (meaningful_response == 'group name: group_name (existing group)')

    def test_process_group_new(self):
        '''this function tests running the process_group method on a new
        group'''
        response = process_group('group_name', '', False, True)
	meaningful_response = response.split('\n')[0]
	print meaningful_response
        assert (meaningful_response ==  'group name: group_name (new group)')

    def test_process_group_error(self):
        '''this function tests running the process_group method on invalid
        input; indicating failure to create group'''
        response = process_group('group_name', '', False, False)
	meaningful_response = response.split('\n')[0]
	print meaningful_response
        assert (meaningful_response == 'could not make group: group_name')

    def test_group_process_reqiuestor_existing(self):
        '''this function tests the group_process_requestor method on a requestor
        that is already the owner of the calendar'''
        response = group_process_requestor('magarvey',
            'abc_group',
            True,
            self.client)
        assert (response == '\n<br/>magarvey (already owner)')

    def test_group_process_requestor_new(self):
        '''this function tests the calendar_process_requestor method on a requestor
        that is not already the owner of the calendar'''
        self.client.create(self.group_name)
        response = group_process_requestor('magarvey', self.group_name, False, self.client)
        print response
        assert (response == '\n<br/>magarvey (new owner)')

    def test_group_process_requestor_invalid(self):
        '''this function tests the group_process_requestor method on a requestor with
        some invalid chars in the requestor's name (... to trigger the exception)'''
        response = group_process_requestor('', 'abc_group', False, self.client)
        assert (response.startswith('\n<br/> is invalid user'))

    def test_group_add_owner_existing(self):
        '''this function tests the group_add_owner method on a group that the user
        is already owner of'''
        group_already_exists, success = \
            group_validate('abc_calendar', '', self.client)
        group_already_owner_start = group_already_owner('magarvey', 'abc_group', self.client)
        try:
            group_add_owner('magarvey', 'abc_group', self.client)
            group_add_owner_success = True
        except:
            group_add_owner_success = False
        group_already_owner_end = group_already_owner('magarvey','abc_group',self.client)
        assert group_already_exists
        assert group_already_owner_start
        assert group_already_owner_end
        assert (success == False)
        assert (group_add_owner_success == True)

    def test_group_add_owner_invalid(self):
        '''this function tests the group_add_owner method on a user that is not in the
        gtest.pdx.edu system'''
        group_already_exists, success = \
            group_validate('abc_group', '', self.client)
        try:
            group_already_owner_start = group_already_owner('?//%/$/#@', 'abc_group', self.client)
        except:
            group_already_owner_start = False
        try:
            subscribed, owner = group_add_owner('?//%/$/#@', 'abc_group', self.client)
            group_add_owner_success = True
        except:
            group_add_owner_success = False
        assert group_already_exists
        assert (group_already_owner_start == False)
        assert (success == False)
        assert (group_add_owner_success == True)
        assert (subscribed == False)
        assert (owner == False)

    def test_group_add_owner_new(self):
        '''this function tests the group_add_owner method for a valid user not already
        owner of the group'''
        self.client.create(self.group_name)
        group_already_exists, success = \
            group_validate(self.group_name, '', self.client)
        group_already_owner_start = group_already_owner('magarvey', self.group_name, self.client)
        try:
            subscribed, owner = group_add_owner('magarvey', self.group_name, self.client)
            group_add_owner_success = True
        except:
            group_add_owner_success = False
        group_already_exists, success = \
            group_validate(self.group_name, '', self.client)

        sleep(5)
        group_already_owner_end = group_already_owner('magarvey', self.group_name, self.client)

        '''DEBUGGIN'''
        print str(self.client.status(self.group_name))
        print str(group_already_owner('magarvey',self.group_name,self.client))

        assert group_already_exists
        assert (group_already_owner_start == False)
        assert (success == False)
        assert group_add_owner_success
        assert subscribed
        assert owner
        assert group_already_owner_end